tamer: configure.ac: conf.sh: New configuration file

The intent is to source this in shell scripts, like tests.

This exposes feature flags to shell scripts, but it doesn't do so in quite
the same way that Rust does---it doesn't apply the dependencies.  While this
isn't needed now, it does make me a little uncomfortable, and so I may take
a different approach in the future.

DEV-13708
main
Mike Gerwitz 2023-02-22 21:55:51 -05:00
parent 716247483f
commit 9200d415f9
3 changed files with 68 additions and 1 deletions

1
tamer/.gitignore vendored
View File

@ -8,6 +8,7 @@ aclocal.m4
*.cache/
configure
/config.*
conf.sh
# Rust/Cargo-generated
/target/

63
tamer/conf.sh.in 100644
View File

@ -0,0 +1,63 @@
# This configuration file is populated by `configure` and is intended to be
# sourced by shell scripts.
declare -r TAMER_PATH_ROOT="@abs_top_srcdir@"
declare -r TAMER_CARGO_BUILD_FLAGS="@CARGO_BUILD_FLAGS@"
declare -r TAMER_CARGO_FEATURES=",@FEATURES_RAW@,"
# List supported flags from Cargo.toml.
tamer-supported-flags() {
awk '
/^\[features\]$/ { parse=1; next }
parse && /^\[/ { parse=0; next }
parse && /^[a-z-]+ =/ { print $1 }
' "$TAMER_PATH_ROOT/Cargo.toml"
}
# Determine whether the provided feature flag is enabled.
#
# The flag must exist in `Cargo.toml`, otherwise the program will exit with
# exit code 16. This ensures that (a) flags are cleaned up and (b) that
# systems don't silently behave incorrectly because a removed flag is
# perceived as disabled.
#
# NB: Unlike Rust, this _does not_ see dependent flags as enabled. We can
# add this feature if it's actually needed.
tamer-flag() {
local -r flag="${1?Missing flag name}"
tamer-supported-flags | grep -qo "^$flag\$" || {
echo "error: feature flag \`$flag\` not found in Cargo.toml!" >&2
echo "error: supported flags:" >&2
tamer-supported-flags | sed 's/^/error: - /' >&2
exit 16
}
[[ "$TAMER_CARGO_FEATURES" =~ ",$flag," ]]
}
# Exit successfully with a note on stderr if the provided flag is not
# enabled.
tamer-flag-or-exit-ok() {
local -r flag="${1?Missing flag name}"
tamer-flag "$@" || {
echo "note: feature flag \`$flag\` is disabled; skipping"
exit 0
}
}
declare -r TAMER_PATH_TARGET="$TAMER_PATH_ROOT/target"
# The path to TAMER's executables depends on whether we are configured for a
# release build.
if [[ "$TAMER_CARGO_BUILD_FLAGS" =~ \<--release\> ]]; then
declare -r TAMER_PATH_BIN="$TAMER_PATH_TARGET/release"
else
declare -r TAMER_PATH_BIN="$TAMER_PATH_TARGET/debug"
fi
declare -r TAMER_PATH_TAMEC="$TAMER_PATH_BIN/tamec"
declare -r TAMER_PATH_TAMELD="$TAMER_PATH_BIN/tameld"

View File

@ -115,11 +115,14 @@ AS_IF([cargo "+$RUST_TC" clippy --help &>/dev/null],
AC_ARG_VAR([FEATURES],
[Cargo features flags for TAMER, comma-delimited])
AC_SUBST([FEATURES_RAW], [])
test -z "$FEATURES" || {
AC_MSG_RESULT([requested features: $FEATURES])
FEATURES_RAW="$FEATURES"
FEATURES="--features $FEATURES"
}
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([Makefile conf.sh])
AC_OUTPUT