| 1 | #!/bin/bash |
| 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | # |
| 5 | # Copyright (C) 2017 Philippe Proulx <pproulx@efficios.com> |
| 6 | # Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com> |
| 7 | # |
| 8 | |
| 9 | # Execute a shell command in the appropriate environment to have access to the |
| 10 | # bt2 Python bindings. For example, one could use it to run a specific Python |
| 11 | # binding test case with: |
| 12 | # |
| 13 | # $ tests/utils/run_python_bt2 python3 ./tests/utils/python/testrunner.py \ |
| 14 | # -t test_value.MapValueTestCase.test_deepcopy \ |
| 15 | # ./tests/bindings/python/bt2 |
| 16 | |
| 17 | if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then |
| 18 | UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh" |
| 19 | else |
| 20 | UTILSSH="$(dirname "$0")/../utils/utils.sh" |
| 21 | fi |
| 22 | |
| 23 | # shellcheck source=../utils/utils.sh |
| 24 | source "$UTILSSH" |
| 25 | |
| 26 | usage() { |
| 27 | echo "Usage: run_python_bt2 [PYTHON_BIN] ..." |
| 28 | echo "" |
| 29 | echo "Run a binary with the python environment set to use the 'bt2' module" |
| 30 | echo "from the build system prior to installation." |
| 31 | echo "" |
| 32 | echo "When building out of tree export the BT_TESTS_BUILDDIR variable with" |
| 33 | echo "the path to the built 'tests' directory." |
| 34 | } |
| 35 | |
| 36 | if [ "x$*" = "x" ]; then |
| 37 | usage |
| 38 | exit 1 |
| 39 | fi |
| 40 | |
| 41 | # Sanity check that the BT_TESTS_BUILDDIR value makes sense. |
| 42 | if [ ! -f "$BT_TESTS_BUILDDIR/Makefile" ]; then |
| 43 | fold -w 80 -s <<- END |
| 44 | $0: BT_TESTS_BUILDDIR does not point to a valid directory (\`$BT_TESTS_BUILDDIR/Makefile\` does not exist). |
| 45 | |
| 46 | If building out-of-tree, set BT_TESTS_BUILDDIR to point to the \`tests\` directory in the build tree. |
| 47 | END |
| 48 | exit 1 |
| 49 | fi |
| 50 | |
| 51 | run_python_bt2 "${@}" |