X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=tests%2Futils%2Frun-in-py-env.sh;fp=tests%2Futils%2Frun-in-py-env.sh;h=2168f87b6e9591562934d81d762f6b3b45514f07;hp=0000000000000000000000000000000000000000;hb=31d2049bc9259ef24ef21d2a5352096057a09877;hpb=2fb231c047e483af94e4664c1316d7943aaa4c0e diff --git a/tests/utils/run-in-py-env.sh b/tests/utils/run-in-py-env.sh new file mode 100755 index 00000000..2168f87b --- /dev/null +++ b/tests/utils/run-in-py-env.sh @@ -0,0 +1,51 @@ +#!/bin/bash +# +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2017 Philippe Proulx +# Copyright (C) 2019 Simon Marchi +# + +# Execute a shell command in the appropriate environment to have access to the +# bt2 Python bindings. For example, one could use it to run a specific Python +# binding test case with: +# +# $ tests/utils/run-in-py-utils-bt2-env.sh python3 ./tests/utils/python/testrunner.py \ +# -t test_value.MapValueTestCase.test_deepcopy \ +# ./tests/bindings/python/bt2 + +if [ -n "${BT_TESTS_SRCDIR:-}" ]; then + UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh" +else + UTILSSH="$(dirname "$0")/../utils/utils.sh" +fi + +# shellcheck source=../utils/utils.sh +source "$UTILSSH" + +usage() { + echo "Usage: run-in-py-utils-bt2-env.sh [PYTHON_BIN] ..." + echo "" + echo "Run a binary with the python environment set to use the 'bt2' module" + echo "from the build system prior to installation." + echo "" + echo "When building out of tree export the BT_TESTS_BUILDDIR variable with" + echo "the path to the built 'tests' directory." +} + +if [ -z "$*" ]; then + usage + 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 + +bt_run_in_py_env "${@}"