From 6630fae77db61ffb3c18bfa245d2d7bbc7a5be8b Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Fri, 15 May 2026 12:07:56 +0200 Subject: [PATCH 1/3] 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 4156eed..cc8b62a 100755 --- a/cc.sh +++ b/cc.sh @@ -32,17 +32,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 @@ -212,12 +201,13 @@ if eval "[ \"\${*#*${lsep}}\" != \"\$*\" ]"; then die "Compiler command line contains our separator ('${lsep}'). Cannot parse." fi -# 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 9095e8c525b711b281ea116f03d69939ae523dc9 Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Fri, 15 May 2026 12:15:17 +0200 Subject: [PATCH 2/3] 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 a59b0a9..f626e1f 100644 --- a/test/run.sh +++ b/test/run.sh @@ -358,8 +358,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 ea60e01c739a719dfb9475a0278f847bc0a706f0 Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Fri, 15 May 2026 12:16:54 +0200 Subject: [PATCH 3/3] 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 cc8b62a..059ab87 100755 --- a/cc.sh +++ b/cc.sh @@ -201,13 +201,13 @@ if eval "[ \"\${*#*${lsep}}\" != \"\$*\" ]"; then die "Compiler command line contains our separator ('${lsep}'). Cannot parse." fi -# 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 f626e1f..af58b3e 100644 --- a/test/run.sh +++ b/test/run.sh @@ -358,8 +358,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 }