Commit | Line | Data |
---|---|---|
644e0364 MJ |
1 | #!/bin/bash |
2 | # | |
0235b0db MJ |
3 | # SPDX-License-Identifier: GPL-2.0-only |
4 | # | |
b566b220 | 5 | # Copyright (C) 2017-2023 Philippe Proulx <pproulx@efficios.com> |
644e0364 | 6 | # Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com> |
644e0364 | 7 | |
a234ff43 | 8 | if [[ -n ${BT_TESTS_SRCDIR:-} ]]; then |
c46ef177 | 9 | utils_sh=$BT_TESTS_SRCDIR/utils/utils.sh |
644e0364 | 10 | else |
c46ef177 | 11 | utils_sh=$(dirname "$0")/../utils/utils.sh |
644e0364 MJ |
12 | fi |
13 | ||
14 | # shellcheck source=../utils/utils.sh | |
c46ef177 | 15 | source "$utils_sh" |
644e0364 MJ |
16 | |
17 | usage() { | |
b566b220 | 18 | echo "Usage: run-in-py-utils-bt2-env.sh COMMAND [ARGS]..." |
644e0364 | 19 | echo "" |
b566b220 PP |
20 | echo "Runs the command \`COMMAND\` with the arguments \`ARGS\` within an environment" |
21 | echo "which can import the testing Python modules (in \`tests/utils/python\`) and the" | |
22 | echo "built \`bt2\` Python package." | |
644e0364 | 23 | echo "" |
b566b220 PP |
24 | echo "NOTE: If you build out of tree, export and set the \`BT_TESTS_BUILDDIR\`" |
25 | echo "environment variable to the built \`tests\` directory." | |
644e0364 MJ |
26 | } |
27 | ||
f68c8a71 | 28 | if (($# == 0)); then |
644e0364 | 29 | usage |
b841eced | 30 | exit 1 |
644e0364 | 31 | fi |
b841eced | 32 | |
9e400c5c | 33 | # Make sure the value of `BT_TESTS_BUILDDIR` makes sense |
a234ff43 | 34 | if [[ ! -f $BT_TESTS_BUILDDIR/Makefile ]]; then |
7dec5799 PP |
35 | { |
36 | echo "ERROR: Invalid \`BT_TESTS_BUILDDIR\` variable (\`\$BT_TESTS_BUILDDIR/Makefile\`" | |
37 | echo "doesn't exist)." | |
38 | echo "" | |
39 | echo "If you build out of tree, export and set the \`BT_TESTS_BUILDDIR\` environment" | |
40 | echo "variable to the built \`tests\` directory." | |
41 | } >&2 | |
b841eced | 42 | |
b841eced SM |
43 | exit 1 |
44 | fi | |
45 | ||
4c8e6861 | 46 | bt_run_in_py_env "$@" |