Skip to content

Commit 6630fae

Browse files
committed
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 <me@harmenstoppels.nl>
1 parent e9fb6c4 commit 6630fae

1 file changed

Lines changed: 7 additions & 17 deletions

File tree

cc.sh

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,6 @@ unset IFS
3232
# NOTE: Depending on your editor this may look empty, but it is not.
3333
readonly lsep=''
3434

35-
# This is an array of environment variables that need to be set before
36-
# the script runs. They are set by routines in spack.build_environment
37-
# as part of the package installation process.
38-
readonly params="\
39-
SPACK_COMPILER_WRAPPER_PATH
40-
SPACK_DEBUG_LOG_DIR
41-
SPACK_DEBUG_LOG_ID
42-
SPACK_SHORT_SPEC
43-
SPACK_SYSTEM_DIRS
44-
SPACK_MANAGED_DIRS"
45-
4635
# Optional parameters that aren't required to be set
4736

4837
# Boolean (true/false/custom) if we want to add debug flags
@@ -212,12 +201,13 @@ if eval "[ \"\${*#*${lsep}}\" != \"\$*\" ]"; then
212201
die "Compiler command line contains our separator ('${lsep}'). Cannot parse."
213202
fi
214203

215-
# ensure required variables are set
216-
for param in $params; do
217-
if eval "test -z \"\${${param}:-}\""; then
218-
die "Spack compiler must be run from Spack! Input '$param' is missing."
219-
fi
220-
done
204+
# ensure required variables are set (POSIX 2.6.2 ${parameter:?word})
205+
: "${SPACK_COMPILER_WRAPPER_PATH:?Error: compiler wrapper must be invoked by Spack}"
206+
: "${SPACK_DEBUG_LOG_DIR:?Error: compiler wrapper must be invoked by Spack}"
207+
: "${SPACK_DEBUG_LOG_ID:?Error: compiler wrapper must be invoked by Spack}"
208+
: "${SPACK_SHORT_SPEC:?Error: compiler wrapper must be invoked by Spack}"
209+
: "${SPACK_SYSTEM_DIRS:?Error: compiler wrapper must be invoked by Spack}"
210+
: "${SPACK_MANAGED_DIRS:?Error: compiler wrapper must be invoked by Spack}"
221211

222212
# eval this because SPACK_MANAGED_DIRS and SPACK_SYSTEM_DIRS are inputs we don't wanna loop over.
223213
# moving the eval inside the function would eval it every call.

0 commit comments

Comments
 (0)