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.
This commit is contained in:

committed by
scheibelp

parent
4f57c9651a
commit
51828dd982
@@ -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
|
||||
|
Reference in New Issue
Block a user