Fix setup-env when going back and forth between instances (#40924)

* setup-env: Fix back and forth between two instances

* setup-env.csh: Fix SPACK_ROOT when switch to a different instance

i.e. Always look for the current SPACK_ROOT

* setup-env: Update comments
This commit is contained in:
Jordan Galby 2024-01-05 18:31:32 +01:00 committed by Massimiliano Culpo
parent 64d046100a
commit 2489b137d9
4 changed files with 33 additions and 34 deletions

View file

@ -25,8 +25,8 @@ if ($_pa_set == 1) then
eval set _pa_old_value='$'$_pa_varname
endif
# Do the actual prepending here, if it is a dir and not already in the path
if ( -d $_pa_new_path && \:$_pa_old_value\: !~ *\:$_pa_new_path\:* ) then
# Do the actual prepending here, if it is a dir and not first in the path
if ( -d $_pa_new_path && $_pa_old_value\: !~ $_pa_new_path\:* ) then
if ("x$_pa_old_value" == "x") then
setenv $_pa_varname $_pa_new_path
else

View file

@ -17,11 +17,11 @@ if ($?_sp_initializing) then
endif
setenv _sp_initializing true
# If SPACK_ROOT is not set, we'll try to find it ourselves.
# find SPACK_ROOT.
# csh/tcsh don't have a built-in way to do this, but both keep files
# they are sourcing open. We use /proc on linux and lsof on macs to
# find this script's full path in the current process's open files.
if (! $?SPACK_ROOT) then
# figure out a command to list open files
if (-d /proc/$$/fd) then
set _sp_lsof = "ls -l /proc/$$/fd"
@ -49,7 +49,6 @@ if (! $?SPACK_ROOT) then
echo " Set SPACK_ROOT to the root of your spack installation and try again."
exit 1
endif
endif
# Command aliases point at separate source files
set _spack_source_file = $SPACK_ROOT/share/spack/setup-env.csh

View file

@ -648,10 +648,10 @@ function spack_pathadd -d "Add path to specified variable (defaults to PATH)"
# passed to regular expression matching (`string match -r`)
set -l _a "$pa_oldvalue"
# skip path if it is already contained in the variable
# skip path if it is already the first in the variable
# note spaces in regular expression: we're matching to a space delimited
# list of paths
if not echo $_a | string match -q -r " *$pa_new_path *"
if not echo $_a | string match -q -r "^$pa_new_path *"
if test -n "$pa_oldvalue"
set $pa_varname $pa_new_path $pa_oldvalue
else

View file

@ -214,9 +214,9 @@ _spack_pathadd() {
# Do the actual prepending here.
eval "_pa_oldvalue=\${${_pa_varname}:-}"
_pa_canonical=":$_pa_oldvalue:"
_pa_canonical="$_pa_oldvalue:"
if [ -d "$_pa_new_path" ] && \
[ "${_pa_canonical#*:${_pa_new_path}:}" = "${_pa_canonical}" ];
[ "${_pa_canonical#$_pa_new_path:}" = "$_pa_canonical" ];
then
if [ -n "$_pa_oldvalue" ]; then
eval "export $_pa_varname=\"$_pa_new_path:$_pa_oldvalue\""