X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=tests%2Futils%2Fenv.sh.in;h=77e0c443ec9f00b8e96f3d27e48eba5091efc226;hp=af34046b822ca250d0564e8e27109bcea5b725c9;hb=HEAD;hpb=e46cbefe0605ab6e66e5c1d1487c823682d3ac10 diff --git a/tests/utils/env.sh.in b/tests/utils/env.sh.in index af34046b..77e0c443 100644 --- a/tests/utils/env.sh.in +++ b/tests/utils/env.sh.in @@ -1,42 +1,50 @@ -#!/bin/bash -# +# SPDX-FileCopyrightText: 2021-2022 EfficiOS, Inc. # SPDX-License-Identifier: GPL-2.0-only -# - -### Base paths to test suite ### -if [ "x${BT_TESTS_SRCDIR:-}" = "x" ]; then - BT_TESTS_SRCDIR="@abs_top_srcdir@/tests" -fi -export BT_TESTS_SRCDIR - -if [ "x${BT_TESTS_BUILDDIR:-}" = "x" ]; then - BT_TESTS_BUILDDIR="@abs_top_builddir@/tests" -fi -export BT_TESTS_BUILDDIR - - -### External Tools ### -if [ "x${BT_TESTS_AWK_BIN:-}" = "x" ]; then - BT_TESTS_AWK_BIN="@AWK@" -fi -export BT_TESTS_AWK_BIN - -if [ "x${BT_TESTS_GREP_BIN:-}" = "x" ]; then - BT_TESTS_GREP_BIN="@GREP@" -fi -export BT_TESTS_GREP_BIN - -if [ "x${BT_TESTS_PYTHON_BIN:-}" = "x" ]; then - BT_TESTS_PYTHON_BIN="@PYTHON@" -fi -export BT_TESTS_PYTHON_BIN - -if [ "x${BT_TESTS_PYTHON_CONFIG_BIN:-}" = "x" ]; then - BT_TESTS_PYTHON_CONFIG_BIN="@PYTHON_CONFIG@" -fi -export BT_TESTS_PYTHON_CONFIG_BIN - -if [ "x${BT_TESTS_SED_BIN:-}" = "x" ]; then - BT_TESTS_SED_BIN="@SED@" -fi -export BT_TESTS_SED_BIN + +# shellcheck shell=bash + +# Sets the variable named `$1` to `$2` if it's not set (or empty), and +# exports it. +_set_var_def() { + local -r varname=$1 + local -r val=$2 + + if [[ -z $(eval echo "\${$varname:-}") ]]; then + eval "$varname='$val'" + fi + + export "${varname?}" +} + +# Base source directory of tests, if not set +_set_var_def BT_TESTS_SRCDIR '@abs_top_srcdir@/tests' + +# Base build directory of tests, if not set +_set_var_def BT_TESTS_BUILDDIR '@abs_top_builddir@/tests' + +# Name of the `awk` command to use when testing, if not set +_set_var_def BT_TESTS_AWK_BIN '@AWK@' + +# Name of the `grep` command to use when testing, if not set +_set_var_def BT_TESTS_GREP_BIN '@GREP@' + +# Name of the `python3` command to use when testing, if not set +_set_var_def BT_TESTS_PYTHON_BIN '@PYTHON@' + +# Name of the `python3-config` command to use when testing, if not set +_set_var_def BT_TESTS_PYTHON_CONFIG_BIN '@PYTHON_CONFIG@' + +# Name of the `sed` command to use when testing, if not set +_set_var_def BT_TESTS_SED_BIN '@SED@' + +# Name of the `cc` command to use when testing, if not set +_set_var_def BT_TESTS_CC_BIN '@CC@' + +# `1` if AddressSanitizer is used, if not set +_set_var_def BT_TESTS_ENABLE_ASAN '@ENABLE_ASAN@' + +# `1` to run tests which depend on Python plugin support, if not set +_set_var_def BT_TESTS_ENABLE_PYTHON_PLUGINS '@ENABLE_PYTHON_PLUGINS@' + +# No more +unset -f _set_var_def