summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
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