From b841eced73b140d37c264befa35279e8b357c0d3 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Sat, 29 Jun 2019 10:06:58 -0400 Subject: [PATCH] tests: run_python_bt2: error out if BT_TESTS_BUILDDIR does not point to a build directory 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 "", line 1, in 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 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1583 Tested-by: jenkins Reviewed-by: Philippe Proulx --- tests/utils/run_python_bt2 | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/utils/run_python_bt2 b/tests/utils/run_python_bt2 index 7147da4a..c016624f 100755 --- a/tests/utils/run_python_bt2 +++ b/tests/utils/run_python_bt2 @@ -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 "${@}" -- 2.34.1