diff --git a/share/spack/setup-env.csh b/share/spack/setup-env.csh index 67357c94e49..c4a2f6a4731 100755 --- a/share/spack/setup-env.csh +++ b/share/spack/setup-env.csh @@ -12,6 +12,13 @@ # setenv SPACK_ROOT /path/to/spack # source $SPACK_ROOT/share/spack/setup-env.csh # + +# prevent infinite recursion when spack shells out (e.g., on cray for modules) +if ($?_sp_initializing) then + exit 0 +endif +setenv _sp_initializing true + if ($?SPACK_ROOT) then set _spack_source_file = $SPACK_ROOT/share/spack/setup-env.csh set _spack_share_dir = $SPACK_ROOT/share/spack @@ -37,3 +44,6 @@ else echo "ERROR: Sourcing spack setup-env.csh requires setting SPACK_ROOT to " echo " the root of your spack installation." endif + +# done: unset sentinel variable as we're no longer initializing +unsetenv _sp_initializing diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh index 5968c4c0160..703079988df 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 @@ -358,3 +364,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