X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Futils%2Futils.sh;h=ada568b8dd5d0d31dfbdc5e2cacda548a45a1512;hb=7030f9fe4fef4bc2a1f1ea3e6cd66ac38b4fcf61;hp=a068ccb5c6ecc340a22c29d7af6588e3a10d0fb5;hpb=07ff3b19ad76e1c2c7e18c244fd9adb84b09a82f;p=babeltrace.git diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index a068ccb5..ada568b8 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -25,15 +25,6 @@ # An unbound variable is an error set -u -# If `readlink -f` is available, then get a resolved absolute path to -# the tests source directory. Otherwise, make do with a relative path. -scriptdir="$(dirname "${BASH_SOURCE[0]}")" -if readlink -f "." >/dev/null 2>&1; then - testsdir=$(readlink -f "$scriptdir/..") -else - testsdir="$scriptdir/.." -fi - # Name of the OS on which we're running, if not set. # # One of: @@ -71,18 +62,38 @@ if [ -z "${BT_TESTS_OS_TYPE:-}" ]; then fi export BT_TESTS_OS_TYPE -# Base source directory of tests -if [ -z "${BT_TESTS_SRCDIR:-}" ]; then - BT_TESTS_SRCDIR="$testsdir" -fi -export BT_TESTS_SRCDIR +# Sets and exports, if not set: +# +# • `BT_TESTS_SRCDIR` to the base source directory of tests. +# • `BT_TESTS_BUILDDIR` to the base build directory of tests. +_set_vars_srcdir_builddir() { + # If `readlink -f` is available, then get a resolved absolute path + # to the tests source directory. Otherwise, make do with a relative + # path. + local -r scriptdir="$(dirname "${BASH_SOURCE[0]}")" + local testsdir -# Base build directory of tests -if [ -z "${BT_TESTS_BUILDDIR:-}" ]; then - BT_TESTS_BUILDDIR="$testsdir" -fi -export BT_TESTS_BUILDDIR + if readlink -f "." >/dev/null 2>&1; then + testsdir=$(readlink -f "$scriptdir/..") + else + testsdir="$scriptdir/.." + fi + + # Base source directory of tests + if [ -z "${BT_TESTS_SRCDIR:-}" ]; then + BT_TESTS_SRCDIR="$testsdir" + fi + export BT_TESTS_SRCDIR + + # Base build directory of tests + if [ -z "${BT_TESTS_BUILDDIR:-}" ]; then + BT_TESTS_BUILDDIR="$testsdir" + fi + export BT_TESTS_BUILDDIR +} +_set_vars_srcdir_builddir +unset -f _set_vars_srcdir_builddir # Source the generated environment file if it's present if [ -f "${BT_TESTS_BUILDDIR}/utils/env.sh" ]; then