tests: run_python_bt2: error out if BT_TESTS_BUILDDIR does not point to a build directory
authorSimon Marchi <simon.marchi@efficios.com>
Sat, 29 Jun 2019 14:06:58 +0000 (10:06 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 18 Jul 2019 05:27:04 +0000 (01:27 -0400)
This patch improves the user experience when building out of tree, using
run_python_bt2, but forgetting to set BT_TESTS_BUILDDIR.

Currently, the script doesn't complain when you do this, but sets
variables (e.g. PYTHONPATH) to point to files/directories that don't
exist:

  $ /home/simark/src/babeltrace/tests/utils/run_python_bt2 python3
  >>> import bt2
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  ModuleNotFoundError: No module named 'bt2'

With this patch, the user gets notified that they did something wrong:

  /home/simark/src/babeltrace/tests/utils/run_python_bt2: BT_TESTS_BUILDDIR does
  not point to a valid directory
  (/home/simark/src/babeltrace/tests/utils/../utils/../Makefile does not exist).

  If building out-of-tree, set BT_TESTS_BUILDDIR to point to the tests directory
  in the build tree.

Change-Id: Ibbc6e11b6cbfce560ad97081d709ed4794c406b1
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1583
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
tests/utils/run_python_bt2

index 7147da4ae0b675bbb4d9d4ab0a82cbc24858eb0f..c016624fb99d6579273eada54d6b0b92b6ccebaf 100755 (executable)
@@ -47,6 +47,17 @@ usage() {
 
 if [ "x$*" = "x" ]; then
        usage
-else
-       run_python_bt2 "${@}"
+       exit 1
 fi
+
+# Sanity check that the BT_TESTS_BUILDDIR value makes sense.
+if [ ! -f "$BT_TESTS_BUILDDIR/Makefile" ]; then
+       fold -w 80 -s <<- END
+       $0: BT_TESTS_BUILDDIR does not point to a valid directory (\`$BT_TESTS_BUILDDIR/Makefile\` does not exist).
+
+       If building out-of-tree, set BT_TESTS_BUILDDIR to point to the \`tests\` directory in the build tree.
+       END
+       exit 1
+fi
+
+run_python_bt2 "${@}"
This page took 0.024704 seconds and 4 git commands to generate.