summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorMatthew Scott Krafczyk <krafczyk.matthew@gmail.com>2017-09-08 12:15:06 -0500
committerscheibelp <scheibel1@llnl.gov>2017-09-08 10:15:06 -0700
commit51828dd982f2642b3f52512aea4fb2c02395d378 (patch)
tree31311f4a5a33c19f0a07f8ea974b09b560b42558 /share
parent4f57c9651a5f4605d4e3668298bd20307181bfb5 (diff)
downloadspack-51828dd982f2642b3f52512aea4fb2c02395d378.tar.gz
spack-51828dd982f2642b3f52512aea4fb2c02395d378.tar.bz2
spack-51828dd982f2642b3f52512aea4fb2c02395d378.tar.xz
spack-51828dd982f2642b3f52512aea4fb2c02395d378.zip
Bootstrap environment-modules
Renames the existing bootstrap command to 'clone'. Repurposes 'spack bootstrap' to install packages that are useful to the operation of Spack (for now this is just environment-modules). For bash and ksh users running setup-env.sh, if a Spack-installed instance of environment-modules is detected and environment modules and dotkit are not externally available, Spack will define the 'module' command in the user's shell to use the environment-modules built by Spack.
Diffstat (limited to 'share')
-rwxr-xr-xshare/spack/setup-env.sh57
1 files changed, 54 insertions, 3 deletions
diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh
index c9a3858621..958689cab4 100755
--- a/share/spack/setup-env.sh
+++ b/share/spack/setup-env.sh
@@ -27,7 +27,9 @@
#
# This file is part of Spack and sets up the spack environment for
# bash and zsh. This includes dotkit support, module support, and
-# it also puts spack in your path. Source it like this:
+# it also puts spack in your path. The script also checks that
+# at least module support exists, and provides suggestions if it
+# doesn't. Source it like this:
#
# . /path/to/spack/share/spack/setup-env.sh
#
@@ -189,19 +191,68 @@ if [ -z "$_sp_source_file" ]; then
fi
#
-# Set up modules and dotkit search paths in the user environment
+# Find root directory and add bin to path.
#
_sp_share_dir=$(cd "$(dirname $_sp_source_file)" && pwd)
_sp_prefix=$(cd "$(dirname $(dirname $_sp_share_dir))" && pwd)
_spack_pathadd PATH "${_sp_prefix%/}/bin"
+export SPACK_ROOT=${_sp_prefix}
+
+#
+# Determine which shell is being used
+#
+function _spack_determine_shell() {
+ ps -p $$ | tail -n 1 | awk '{print $4}' | xargs basename
+}
+export SPACK_SHELL=$(_spack_determine_shell)
+
+#
+# Check whether a shell function of the given name is defined
+#
+function _spack_fn_exists() {
+ type $1 2>&1 | grep -q 'shell function'
+}
+need_module="no"
+if [ ! $(_spack_fn_exists use) ] && [ ! $(_spack_fn_exists module) ]; then
+ need_module="yes"
+fi;
+
+#
+# build and make available environment-modules
+#
+if [ "${need_module}" = "yes" ]; then
+ #check if environment-modules~X 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
+ #activate it!
+ export MODULE_PREFIX=${module_prefix}
+ _spack_pathadd PATH "${MODULE_PREFIX}/Modules/bin"
+ module() { eval `${MODULE_PREFIX}/Modules/bin/modulecmd ${SPACK_SHELL} $*`; }
+ echo "INFO: Using spack managed module system."
+ else
+ echo "WARNING: A method for managing modules does not currently exist."
+ echo ""
+ echo "To resolve this you may either:"
+ echo "1. Allow spack to handle this by running 'spack boostrap'"
+ echo " and sourcing this script again."
+ echo "2. Install and activate a supported module managment engine manually"
+ echo " Supported engines include: environment-modules and lmod"
+ fi;
+else
+ echo "INFO: Using system available module system."
+fi;
+
+#
+# Set up modules and dotkit search paths in the user environment
+#
_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"
-#
# Add programmable tab completion for Bash
#
if [ -n "${BASH_VERSION:-}" ]; then