summaryrefslogtreecommitdiff
path: root/share/spack/setup-env.sh
diff options
context:
space:
mode:
Diffstat (limited to 'share/spack/setup-env.sh')
-rwxr-xr-xshare/spack/setup-env.sh118
1 files changed, 76 insertions, 42 deletions
diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh
index 21a7e00345..79688455bf 100755
--- a/share/spack/setup-env.sh
+++ b/share/spack/setup-env.sh
@@ -1,27 +1,8 @@
-##############################################################################
-# Copyright (c) 2013-2017, Lawrence Livermore National Security, LLC.
-# Produced at the Lawrence Livermore National Laboratory.
+# Copyright 2013-2018 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
-# This file is part of Spack.
-# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
-# LLNL-CODE-647188
-#
-# For details, see https://github.com/spack/spack
-# Please also see the NOTICE and LICENSE files for our notice and the LGPL.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU Lesser General Public License (as
-# published by the Free Software Foundation) version 2.1, February 1999.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
-# conditions of the GNU Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-##############################################################################
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
########################################################################
#
@@ -80,14 +61,22 @@ function spack {
return
fi
- _sp_subcommand=$1; shift
- _sp_spec="$@"
+ _sp_subcommand=""
+ if [ -n "$1" ]; then
+ _sp_subcommand="$1"
+ shift
+ fi
+ _sp_spec=("$@")
# Filter out use and unuse. For any other commands, just run the
# command.
case $_sp_subcommand in
"cd")
- _sp_arg="$1"; shift
+ _sp_arg=""
+ if [ -n "$1" ]; then
+ _sp_arg="$1"
+ shift
+ fi
if [ "$_sp_arg" = "-h" ]; then
command spack cd -h
else
@@ -100,6 +89,43 @@ function spack {
fi
return
;;
+ "env")
+ _sp_arg=""
+ if [ -n "$1" ]; then
+ _sp_arg="$1"
+ shift
+ fi
+
+ if [ "$_sp_arg" = "-h" ]; then
+ command spack env -h
+ else
+ case $_sp_arg in
+ activate)
+ _a="$@"
+ if [ -z "$1" -o "${_a#*--sh}" != "$_a" -o "${_a#*--csh}" != "$_a" -o "${_a#*-h}" != "$_a" ]; then
+ # no args or args contain -h/--help, --sh, or --csh: just execute
+ command spack "${args[@]}"
+ else
+ # actual call to activate: source the output
+ eval $(command spack $_sp_flags env activate --sh "$@")
+ fi
+ ;;
+ deactivate)
+ if [ -n "$1" ]; then
+ # with args: execute the command
+ command spack "${args[@]}"
+ else
+ # no args: source the output.
+ eval $(command spack $_sp_flags env deactivate --sh)
+ fi
+ ;;
+ *)
+ command spack "${args[@]}"
+ ;;
+ esac
+ fi
+ return
+ ;;
"use"|"unuse"|"load"|"unload")
# Shift any other args for use off before parsing spec.
_sp_subcommand_args=""
@@ -113,7 +139,7 @@ function spack {
shift
done
- _sp_spec="$@"
+ _sp_spec=("$@")
# Here the user has run use or unuse with a spec. Find a matching
# spec using 'spack module find', then use the appropriate module
@@ -121,20 +147,28 @@ function spack {
# If spack module command comes back with an error, do nothing.
case $_sp_subcommand in
"use")
- if _sp_full_spec=$(command spack $_sp_flags module loads --input-only $_sp_subcommand_args --module-type dotkit $_sp_spec); then
+ if _sp_full_spec=$(command spack $_sp_flags module dotkit find $_sp_subcommand_args "${_sp_spec[@]}"); then
use $_sp_module_args $_sp_full_spec
+ else
+ $(exit 1)
fi ;;
"unuse")
- if _sp_full_spec=$(command spack $_sp_flags module loads --input-only $_sp_subcommand_args --module-type dotkit $_sp_spec); then
+ if _sp_full_spec=$(command spack $_sp_flags module dotkit find $_sp_subcommand_args "${_sp_spec[@]}"); then
unuse $_sp_module_args $_sp_full_spec
+ else
+ $(exit 1)
fi ;;
"load")
- if _sp_full_spec=$(command spack $_sp_flags module loads --input-only $_sp_subcommand_args --module-type tcl $_sp_spec); then
+ if _sp_full_spec=$(command spack $_sp_flags module tcl find $_sp_subcommand_args "${_sp_spec[@]}"); then
module load $_sp_module_args $_sp_full_spec
+ else
+ $(exit 1)
fi ;;
"unload")
- if _sp_full_spec=$(command spack $_sp_flags module loads --input-only $_sp_subcommand_args --module-type tcl $_sp_spec); then
+ if _sp_full_spec=$(command spack $_sp_flags module tcl find $_sp_subcommand_args "${_sp_spec[@]}"); then
module unload $_sp_module_args $_sp_full_spec
+ else
+ $(exit 1)
fi ;;
esac
;;
@@ -202,7 +236,7 @@ export SPACK_ROOT=${_sp_prefix}
# Determine which shell is being used
#
function _spack_determine_shell() {
- ps -p $$ | tail -n 1 | awk '{print $4}' | sed 's/^-//' | xargs basename
+ PS_FORMAT= ps -p $$ | tail -n 1 | awk '{print $4}' | sed 's/^-//' | xargs basename
}
export SPACK_SHELL=$(_spack_determine_shell)
@@ -218,27 +252,27 @@ if ! _spack_fn_exists use && ! _spack_fn_exists module; then
need_module="yes"
fi;
+
#
-# build and make available environment-modules
+# make available environment-modules
#
if [ "${need_module}" = "yes" ]; then
- #check if environment-modules is installed
- module_prefix="$(spack location -i "environment-modules" 2>&1 || echo "not_installed")"
- module_prefix=$(echo "${module_prefix}" | tail -n 1)
- if [ "${module_prefix}" != "not_installed" ]; then
+ eval `spack --print-shell-vars sh,modules`
+
+ # _sp_module_prefix is set by spack --print-sh-vars
+ if [ "${_sp_module_prefix}" != "not_installed" ]; then
#activate it!
- export MODULE_PREFIX=${module_prefix}
+ export MODULE_PREFIX=${_sp_module_prefix}
_spack_pathadd PATH "${MODULE_PREFIX}/Modules/bin"
module() { eval `${MODULE_PREFIX}/Modules/bin/modulecmd ${SPACK_SHELL} $*`; }
fi;
+else
+ eval `spack --print-shell-vars sh`
fi;
#
-# Set up modules and dotkit search paths in the user environment
+# set module system roots
#
-_sp_sys_type=$(spack-python -c 'print(spack.architecture.sys_type())')
-_sp_dotkit_root=$(spack-python -c "print(spack.util.path.canonicalize_path(spack.config.get_config('config').get('module_roots', {}).get('dotkit')))")
-_sp_tcl_root=$(spack-python -c "print(spack.util.path.canonicalize_path(spack.config.get_config('config').get('module_roots', {}).get('tcl')))")
_spack_pathadd DK_NODE "${_sp_dotkit_root%/}/$_sp_sys_type"
_spack_pathadd MODULEPATH "${_sp_tcl_root%/}/$_sp_sys_type"