summaryrefslogtreecommitdiff
path: root/share/spack/setup-env.sh
diff options
context:
space:
mode:
authorGreg Becker <becker33@llnl.gov>2020-01-22 22:36:02 -0800
committerTodd Gamblin <tgamblin@llnl.gov>2020-01-22 22:36:02 -0800
commitc9e01ff9d76f5e1e645b01f5021c469f436b260c (patch)
treede1eacc3b689efc0ef8cdbd8634ecc0436f3b080 /share/spack/setup-env.sh
parent5053dfa2599a90a8b5bf69c9391fa3b8e38a7bbb (diff)
downloadspack-c9e01ff9d76f5e1e645b01f5021c469f436b260c.tar.gz
spack-c9e01ff9d76f5e1e645b01f5021c469f436b260c.tar.bz2
spack-c9e01ff9d76f5e1e645b01f5021c469f436b260c.tar.xz
spack-c9e01ff9d76f5e1e645b01f5021c469f436b260c.zip
shell support: `spack load` no longer needs modules (#14062)
Previously the `spack load` command was a wrapper around `module load`. This required some bootstrapping of modules to make `spack load` work properly. With this PR, the `spack` shell function handles the environment modifications necessary to add packages to your user environment. This removes the dependence on environment modules or lmod and removes the requirement to bootstrap spack (beyond using the setup-env scripts). Included in this PR is support for MacOS when using Apple's System Integrity Protection (SIP), which is enabled by default in modern MacOS versions. SIP clears the `LD_LIBRARY_PATH` and `DYLD_LIBRARY_PATH` variables on process startup for executables that live in `/usr` (but not '/usr/local', `/System`, `/bin`, and `/sbin` among other system locations. Spack cannot know the `LD_LIBRARY_PATH` of the calling process when executed using `/bin/sh` and `/usr/bin/python`. The `spack` shell function now manually forwards these two variables, if they are present, as `SPACK_<VAR>` and recovers those values on startup. - [x] spack load/unload no longer delegate to modules - [x] refactor user_environment modification calculations - [x] update documentation for spack load/unload Co-authored-by: Todd Gamblin <tgamblin@llnl.gov>
Diffstat (limited to 'share/spack/setup-env.sh')
-rwxr-xr-xshare/spack/setup-env.sh61
1 files changed, 26 insertions, 35 deletions
diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh
index 23a29ce6a2..207e9c4a80 100755
--- a/share/spack/setup-env.sh
+++ b/share/spack/setup-env.sh
@@ -40,6 +40,16 @@
########################################################################
spack() {
+ # Store LD_LIBRARY_PATH variables from spack shell function
+ # This is necessary because MacOS System Integrity Protection clears
+ # (DY?)LD_LIBRARY_PATH variables on process start.
+ if [ -n "${LD_LIBRARY_PATH-}" ]; then
+ export SPACK_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
+ fi
+ if [ -n "${DYLD_LIBRARY_PATH-}" ]; then
+ export SPACK_DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
+ fi
+
# Zsh does not do word splitting by default, this enables it for this
# function only
if [ -n "${ZSH_VERSION:-}" ]; then
@@ -141,41 +151,22 @@ spack() {
return
;;
"load"|"unload")
- # Shift any other args for use off before parsing spec.
- _sp_subcommand_args=""
- _sp_module_args=""
- while [ "${1#-}" != "${1}" ]; do
- if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
- command spack $_sp_flags $_sp_subcommand $_sp_subcommand_args "$@"
- return
- elif [ "$1" = "-r" ] || [ "$1" = "--dependencies" ]; then
- _sp_subcommand_args="$_sp_subcommand_args $1"
- else
- _sp_module_args="$_sp_module_args $1"
- fi
- shift
- done
-
- # Here the user has run use or unuse with a spec. Find a matching
- # spec using 'spack module find', then use the appropriate module
- # tool's commands to add/remove the result from the environment.
- # If spack module command comes back with an error, do nothing.
- case $_sp_subcommand in
- "load")
- if _sp_full_spec=$(command spack $_sp_flags module tcl find $_sp_subcommand_args "$@"); then
- module load $_sp_module_args $_sp_full_spec
- else
- $(exit 1)
- fi
- ;;
- "unload")
- if _sp_full_spec=$(command spack $_sp_flags module tcl find $_sp_subcommand_args "$@"); then
- module unload $_sp_module_args $_sp_full_spec
- else
- $(exit 1)
- fi
- ;;
- esac
+ # get --sh, --csh, --help, or -h arguments
+ # space is important for -h case to differentiate between `-h`
+ # argument and specs with "-h" in package name or variant settings
+ _a=" $@"
+ if [ "${_a#* --sh}" != "$_a" ] || \
+ [ "${_a#* --csh}" != "$_a" ] || \
+ [ "${_a#* -h}" != "$_a" ] || \
+ [ "${_a#* --help}" != "$_a" ];
+ then
+ # just execute the command if --sh or --csh are provided
+ # or if the -h or --help arguments are provided
+ command spack $_sp_flags $_sp_subcommand "$@"
+ else
+ eval $(command spack $_sp_flags $_sp_subcommand --sh "$@" || \
+ echo "return 1") # return 1 if spack command fails
+ fi
;;
*)
command spack $_sp_flags $_sp_subcommand "$@"