summaryrefslogtreecommitdiff
path: root/share/spack/setup-env.sh
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2020-07-05 22:35:01 -0700
committerPeter Scheibel <scheibel1@llnl.gov>2020-07-10 13:05:49 -0700
commit054e0d1d1132145f7e7c00ad9408c5c9b164d4ef (patch)
tree4eb508c24039aae8a80936756f72194f79f80e8d /share/spack/setup-env.sh
parentc8a83661c2c761c9de5ff30ae82aa79a635e5d64 (diff)
downloadspack-054e0d1d1132145f7e7c00ad9408c5c9b164d4ef.tar.gz
spack-054e0d1d1132145f7e7c00ad9408c5c9b164d4ef.tar.bz2
spack-054e0d1d1132145f7e7c00ad9408c5c9b164d4ef.tar.xz
spack-054e0d1d1132145f7e7c00ad9408c5c9b164d4ef.zip
bugfix: no infinite recursion in setup-env.sh on Cray
On Cray platforms, we rely heavily on the module system to figure out what targets, compilers, etc. are available. This unfortunately means that we shell out to the `module` command as part of platform initialization. Because we run subcommands in a shell, we can get infinite recursion if `setup-env.sh` and friends are in some init script like `.bashrc`. This fixes the infinite loop by adding guards around `setup-env.sh`, `setup-env.csh`, and `setup-env.fish`, to prevent recursive initializations of Spack. This is safe because Spack never shells out to itself, so we do not need it to be initialized in subshells. - [x] add recursion guard around `setup-env.sh` - [x] add recursion guard around `setup-env.csh` - [x] add recursion guard around `setup-env.fish`
Diffstat (limited to 'share/spack/setup-env.sh')
-rwxr-xr-xshare/spack/setup-env.sh10
1 files changed, 10 insertions, 0 deletions
diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh
index 032247cd8f..9d984ae199 100755
--- a/share/spack/setup-env.sh
+++ b/share/spack/setup-env.sh
@@ -39,6 +39,12 @@
# spack module files.
########################################################################
+# prevent infinite recursion when spack shells out (e.g., on cray for modules)
+if [ -n "${_sp_initializing:-}" ]; then
+ exit 0
+fi
+export _sp_initializing=true
+
spack() {
# Store LD_LIBRARY_PATH variables from spack shell function
# This is necessary because MacOS System Integrity Protection clears
@@ -357,3 +363,7 @@ _sp_multi_pathadd MODULEPATH "$_sp_tcl_roots"
if [ "$_sp_shell" = bash ]; then
source $_sp_share_dir/spack-completion.bash
fi
+
+# done: unset sentinel variable as we're no longer initializing
+unset _sp_initializing
+export _sp_initializing