From 311830021b4162d176942dfa7edeafda4de69290 Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Fri, 15 May 2026 12:07:56 +0200 Subject: [PATCH 1/4] Use native variable validation * Use null utility `: ...` to avoid execution * Use `${parameter:?[word]}` to do ensure the variable is set * Drop `eval` loop The error message on Ubuntu reads: > cc.sh: 205: SPACK_COMPILER_WRAPPER_PATH: Error: compiler wrapper must be invoked by Spack Previously it was: > [spack cc]: Error: Spack compiler must be run from Spack! Input 'SPACK_COMPILER_WRAPPER_PATH' is missing. Signed-off-by: Harmen Stoppels --- cc.sh | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/cc.sh b/cc.sh index b888427..fc236e2 100755 --- a/cc.sh +++ b/cc.sh @@ -34,17 +34,6 @@ unset IFS # NOTE: Depending on your editor this may look empty, but it is not. readonly lsep='' -# This is an array of environment variables that need to be set before -# the script runs. They are set by routines in spack.build_environment -# as part of the package installation process. -readonly params="\ -SPACK_COMPILER_WRAPPER_PATH -SPACK_DEBUG_LOG_DIR -SPACK_DEBUG_LOG_ID -SPACK_SHORT_SPEC -SPACK_SYSTEM_DIRS -SPACK_MANAGED_DIRS" - # Optional parameters that aren't required to be set # Boolean (true/false/custom) if we want to add debug flags @@ -232,12 +221,13 @@ case "$*" in ;; esac -# ensure required variables are set -for param in $params; do - if eval "test -z \"\${${param}:-}\""; then - die "Spack compiler must be run from Spack! Input '$param' is missing." - fi -done +# ensure required variables are set (POSIX 2.6.2 ${parameter:?word}) +: "${SPACK_COMPILER_WRAPPER_PATH:?Error: compiler wrapper must be invoked by Spack}" +: "${SPACK_DEBUG_LOG_DIR:?Error: compiler wrapper must be invoked by Spack}" +: "${SPACK_DEBUG_LOG_ID:?Error: compiler wrapper must be invoked by Spack}" +: "${SPACK_SHORT_SPEC:?Error: compiler wrapper must be invoked by Spack}" +: "${SPACK_SYSTEM_DIRS:?Error: compiler wrapper must be invoked by Spack}" +: "${SPACK_MANAGED_DIRS:?Error: compiler wrapper must be invoked by Spack}" # eval this because SPACK_MANAGED_DIRS and SPACK_SYSTEM_DIRS are inputs we don't wanna loop over. # moving the eval inside the function would eval it every call. From 285240a7564f99d08cfacd5f664148a653c2783d Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Fri, 15 May 2026 12:15:17 +0200 Subject: [PATCH 2/4] update test Signed-off-by: Harmen Stoppels --- test/run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/run.sh b/test/run.sh index 8127170..3c765e4 100755 --- a/test/run.sh +++ b/test/run.sh @@ -396,8 +396,8 @@ test_no_wrapper_environment() { fail "cc with no env unexpectedly exited 0" fi case "$_out" in - *"Spack compiler must be run from Spack"*) ;; - *) fail "expected 'Spack compiler must be run from Spack' in: $_out" ;; + *"compiler wrapper must be invoked by Spack"*) ;; + *) fail "expected 'compiler wrapper must be invoked by Spack' in: $_out" ;; esac } From bdb5b93e6c15c75bd262b61b525a4f9fabf0e61e Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Fri, 15 May 2026 12:16:54 +0200 Subject: [PATCH 3/4] by->from, the Signed-off-by: Harmen Stoppels --- cc.sh | 14 +++++++------- test/run.sh | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cc.sh b/cc.sh index fc236e2..013dda2 100755 --- a/cc.sh +++ b/cc.sh @@ -221,13 +221,13 @@ case "$*" in ;; esac -# ensure required variables are set (POSIX 2.6.2 ${parameter:?word}) -: "${SPACK_COMPILER_WRAPPER_PATH:?Error: compiler wrapper must be invoked by Spack}" -: "${SPACK_DEBUG_LOG_DIR:?Error: compiler wrapper must be invoked by Spack}" -: "${SPACK_DEBUG_LOG_ID:?Error: compiler wrapper must be invoked by Spack}" -: "${SPACK_SHORT_SPEC:?Error: compiler wrapper must be invoked by Spack}" -: "${SPACK_SYSTEM_DIRS:?Error: compiler wrapper must be invoked by Spack}" -: "${SPACK_MANAGED_DIRS:?Error: compiler wrapper must be invoked by Spack}" +# Ensure required variables are set +: "${SPACK_COMPILER_WRAPPER_PATH:?Error: the compiler wrapper must be invoked from Spack}" +: "${SPACK_DEBUG_LOG_DIR:?Error: the compiler wrapper must be invoked from Spack}" +: "${SPACK_DEBUG_LOG_ID:?Error: the compiler wrapper must be invoked from Spack}" +: "${SPACK_SHORT_SPEC:?Error: the compiler wrapper must be invoked from Spack}" +: "${SPACK_SYSTEM_DIRS:?Error: the compiler wrapper must be invoked from Spack}" +: "${SPACK_MANAGED_DIRS:?Error: the compiler wrapper must be invoked from Spack}" # eval this because SPACK_MANAGED_DIRS and SPACK_SYSTEM_DIRS are inputs we don't wanna loop over. # moving the eval inside the function would eval it every call. diff --git a/test/run.sh b/test/run.sh index 3c765e4..7bf2e12 100755 --- a/test/run.sh +++ b/test/run.sh @@ -396,8 +396,8 @@ test_no_wrapper_environment() { fail "cc with no env unexpectedly exited 0" fi case "$_out" in - *"compiler wrapper must be invoked by Spack"*) ;; - *) fail "expected 'compiler wrapper must be invoked by Spack' in: $_out" ;; + *"compiler wrapper must be invoked from Spack"*) ;; + *) fail "expected 'compiler wrapper must be invoked from Spack' in: $_out" ;; esac } From 631c209ff269cf11d9eb051e3a4cd997fcc4765c Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Wed, 20 May 2026 10:23:42 +0200 Subject: [PATCH 4/4] Factor the repeated error message into a local var Signed-off-by: Harmen Stoppels --- cc.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cc.sh b/cc.sh index 013dda2..5aa71f1 100755 --- a/cc.sh +++ b/cc.sh @@ -222,12 +222,14 @@ case "$*" in esac # Ensure required variables are set -: "${SPACK_COMPILER_WRAPPER_PATH:?Error: the compiler wrapper must be invoked from Spack}" -: "${SPACK_DEBUG_LOG_DIR:?Error: the compiler wrapper must be invoked from Spack}" -: "${SPACK_DEBUG_LOG_ID:?Error: the compiler wrapper must be invoked from Spack}" -: "${SPACK_SHORT_SPEC:?Error: the compiler wrapper must be invoked from Spack}" -: "${SPACK_SYSTEM_DIRS:?Error: the compiler wrapper must be invoked from Spack}" -: "${SPACK_MANAGED_DIRS:?Error: the compiler wrapper must be invoked from Spack}" +_msg="Error: the compiler wrapper must be invoked from Spack" +: "${SPACK_COMPILER_WRAPPER_PATH:?$_msg}" +: "${SPACK_DEBUG_LOG_DIR:?$_msg}" +: "${SPACK_DEBUG_LOG_ID:?$_msg}" +: "${SPACK_SHORT_SPEC:?$_msg}" +: "${SPACK_SYSTEM_DIRS:?$_msg}" +: "${SPACK_MANAGED_DIRS:?$_msg}" +unset _msg # eval this because SPACK_MANAGED_DIRS and SPACK_SYSTEM_DIRS are inputs we don't wanna loop over. # moving the eval inside the function would eval it every call.