add spack --print-shell-vars to speed up setup-env.[c]sh (#8101)
				
					
				
			- The setup-env.sh script currently makes two calls to spack, but it should only need to make one. - Add a fast-path shell setup routine in `main.py` to allow the shell setup to happen in a single, fast call that doesn't load more than it needs to. - This simplifies setup code, as it has to eval what Spack prints - TODO: consider eventually making the whole setup script the output of a spack command
This commit is contained in:
		| @@ -39,10 +39,8 @@ if ($?SPACK_ROOT) then | ||||
|     alias spack          'set _sp_args = (\!*); source $_spack_share_dir/csh/spack.csh' | ||||
|     alias _spack_pathadd 'set _pa_args = (\!*) && source $_spack_share_dir/csh/pathadd.csh' | ||||
|  | ||||
|     # Shamelessly stolen from setup-env.sh | ||||
|     set _sp_sys_type    = `$SPACK_ROOT/bin/spack python -c 'print(spack.architecture.sys_type())'` | ||||
|     set _sp_dotkit_root = `$SPACK_ROOT/bin/spack python -c "print(spack.util.path.canonicalize_path(spack.config.get('config:module_roots', {}).get('dotkit')))"` | ||||
|     set _sp_tcl_root    = `$SPACK_ROOT/bin/spack python -c "print(spack.util.path.canonicalize_path(spack.config.get('config:module_roots', {}).get('tcl')))"` | ||||
|     # Set variables needed by this script | ||||
|     eval `spack --print-shell-vars csh` | ||||
|  | ||||
|     # Set up modules and dotkit search paths in the user environment | ||||
|     _spack_pathadd DK_NODE    "$_sp_dotkit_root/$_sp_sys_type" | ||||
|   | ||||
| @@ -218,34 +218,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 | ||||
| # | ||||
|  | ||||
| _python_command=$(printf  "%s\\\n%s\\\n%s" \ | ||||
| "print(\'_sp_sys_type={0}\'.format(spack.architecture.sys_type()))" \ | ||||
| "print(\'_sp_dotkit_root={0}\'.format(spack.util.path.canonicalize_path(spack.config.get(\'config:module_roots\', {}).get(\'dotkit\'))))" \ | ||||
| "print(\'_sp_tcl_root={0}\'.format(spack.util.path.canonicalize_path(spack.config.get(\'config:module_roots\', {}).get(\'tcl\'))))" | ||||
| ) | ||||
|  | ||||
| _assignment_command=$(spack-python -c "exec('${_python_command}')") | ||||
| eval ${_assignment_command} | ||||
|  | ||||
| _spack_pathadd DK_NODE    "${_sp_dotkit_root%/}/$_sp_sys_type" | ||||
| _spack_pathadd MODULEPATH "${_sp_tcl_root%/}/$_sp_sys_type" | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Todd Gamblin
					Todd Gamblin