From d87a6525823e0d75b9f6b71fb265ebffb9c060a4 Mon Sep 17 00:00:00 2001 From: Todd Gamblin <tgamblin@llnl.gov> Date: Fri, 22 Aug 2014 11:00:19 -0700 Subject: Add spack cd and spack location commands. - Better shell support for cd'ing into directories - Fix some csh weirdness with nested aliases. --- share/spack/csh/pathadd.csh | 23 ++++++++++++++++++ share/spack/csh/spack.csh | 50 ++++++++++++++++++++++----------------- share/spack/csh/spack_pathadd.csh | 23 ------------------ share/spack/setup-env.csh | 2 +- share/spack/setup-env.sh | 38 ++++++++++++++--------------- 5 files changed, 71 insertions(+), 65 deletions(-) create mode 100644 share/spack/csh/pathadd.csh delete mode 100644 share/spack/csh/spack_pathadd.csh (limited to 'share') diff --git a/share/spack/csh/pathadd.csh b/share/spack/csh/pathadd.csh new file mode 100644 index 0000000000..1e0800c5f3 --- /dev/null +++ b/share/spack/csh/pathadd.csh @@ -0,0 +1,23 @@ +######################################################################## +# Prepends directories to path, if they exist. +# pathadd /path/to/dir # add to PATH +# or pathadd OTHERPATH /path/to/dir # add to OTHERPATH +######################################################################## +# If no variable name is supplied, just append to PATH +# otherwise append to that variable. +set _pa_varname = PATH; +set _pa_new_path = $_pa_args[1]; +[ $#_pa_args -gt 1 ] && set _pa_varname = $_pa_args[1] && set _pa_new_path = $_pa_args[2]; + +# Check whether the variable is set yet. +set _pa_old_value = "" +eval set _pa_set = '$?'$_pa_varname +[ $_pa_set -eq 1 ] && eval set _pa_old_value='$'$_pa_varname; + +# Do the actual prepending here, if it is a dir and not already in the path +if ( -d $_pa_new_path && \:$_pa_old_value\: !~ *\:$_pa_new_path\:* ) then + [ -n "$_pa_old_value" ] && setenv $_pa_varname $_pa_new_path\:$_pa_old_value + [ -z "$_pa_old_value" ] && setenv $_pa_varname $_pa_new_path +endif + +unset _pa_args _pa_new_path _pa_old_value _pa_set _pa_varname diff --git a/share/spack/csh/spack.csh b/share/spack/csh/spack.csh index 6073673333..30c4ec1361 100644 --- a/share/spack/csh/spack.csh +++ b/share/spack/csh/spack.csh @@ -45,9 +45,9 @@ set _sp_spec="" # Figure out what type of module we're running here. set _sp_modtype = "" switch ($_sp_subcommand) -case "cd": +case cd: shift _sp_args - cd `spack stage --print-build-dir $_sp_args` + cd `spack location $_sp_args` breaksw case use: case unuse: @@ -59,30 +59,36 @@ case unload: shift _sp_spec set _sp_spec = ($_sp_spec) endif - # Translate the parameter into pieces of a command. - # _sp_modtype is an arg to spack module find, and - # _sp_sh_cmd is the equivalent shell command. - switch ($_sp_subcommand) - case use: - case unuse: - set _sp_modtype = dotkit - set _sp_sh_cmd = ( "`alias $_sp_subcommand'" ) - breaksw - case load: - case unload: - set _sp_modtype = tcl - set _sp_sh_cmd = ( "`alias module`" $_sp_subcommand ) - breaksw - endsw # Here the user has run use or unuse with a spec. Find a matching # spec using 'spack module find', then use the appropriate module # tool's commands to add/remove the result from the environment. - # If spack module command comes back with an error, do nothing. - set _sp_full_spec = "" - if { set _sp_full_spec = `\spack module find $_sp_modtype $_sp_spec` } then - $_sp_sh_cmd $_sp_module_args $_sp_full_spec - endif + switch ($_sp_subcommand) + case "use": + set _sp_full_spec = ( "`\spack $_sp_flags module find dotkit $_sp_spec`" ) + if ( $? == 0 ) then + use $_sp_module_args $_sp_full_spec + endif + breaksw + case "unuse": + set _sp_full_spec = ( "`\spack $_sp_flags module find dotkit $_sp_spec`" ) + if ( $? == 0 ) then + unuse $_sp_module_args $_sp_full_spec + endif + breaksw + case "load": + set _sp_full_spec = ( "`\spack $_sp_flags module find tcl $_sp_spec`" ) + if ( $? == 0 ) then + module load $_sp_module_args $_sp_full_spec + endif + breaksw + case "unload": + set _sp_full_spec = ( "`\spack $_sp_flags module find tcl $_sp_spec`" ) + if ( $? == 0 ) then + module unload $_sp_module_args $_sp_full_spec + endif + breaksw + endsw breaksw default: diff --git a/share/spack/csh/spack_pathadd.csh b/share/spack/csh/spack_pathadd.csh deleted file mode 100644 index 1e0800c5f3..0000000000 --- a/share/spack/csh/spack_pathadd.csh +++ /dev/null @@ -1,23 +0,0 @@ -######################################################################## -# Prepends directories to path, if they exist. -# pathadd /path/to/dir # add to PATH -# or pathadd OTHERPATH /path/to/dir # add to OTHERPATH -######################################################################## -# If no variable name is supplied, just append to PATH -# otherwise append to that variable. -set _pa_varname = PATH; -set _pa_new_path = $_pa_args[1]; -[ $#_pa_args -gt 1 ] && set _pa_varname = $_pa_args[1] && set _pa_new_path = $_pa_args[2]; - -# Check whether the variable is set yet. -set _pa_old_value = "" -eval set _pa_set = '$?'$_pa_varname -[ $_pa_set -eq 1 ] && eval set _pa_old_value='$'$_pa_varname; - -# Do the actual prepending here, if it is a dir and not already in the path -if ( -d $_pa_new_path && \:$_pa_old_value\: !~ *\:$_pa_new_path\:* ) then - [ -n "$_pa_old_value" ] && setenv $_pa_varname $_pa_new_path\:$_pa_old_value - [ -z "$_pa_old_value" ] && setenv $_pa_varname $_pa_new_path -endif - -unset _pa_args _pa_new_path _pa_old_value _pa_set _pa_varname diff --git a/share/spack/setup-env.csh b/share/spack/setup-env.csh index cc12eae82f..5f91670a60 100755 --- a/share/spack/setup-env.csh +++ b/share/spack/setup-env.csh @@ -37,7 +37,7 @@ if ($?SPACK_ROOT) then # Command aliases point at separate source files alias spack 'set _sp_args = (\!*); source $_spack_share_dir/csh/spack.csh' - alias _spack_pathadd 'set _pa_args = (\!*) && source $_spack_share_dir/csh/spack_pathadd.csh' + alias _spack_pathadd 'set _pa_args = (\!*) && source $_spack_share_dir/csh/pathadd.csh' # Set up modules and dotkit search paths in the user environment # TODO: fix SYS_TYPE to something non-LLNL-specific diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh index 9a6090a93b..6f56d4739b 100755 --- a/share/spack/setup-env.sh +++ b/share/spack/setup-env.sh @@ -76,7 +76,7 @@ function spack { # command. case $_sp_subcommand in "cd") - cd $(spack stage --print-build-dir "$@") + cd $(spack location "$@") return ;; "use"|"unuse"|"load"|"unload") @@ -87,28 +87,28 @@ function spack { _sp_spec="$@" fi - # Translate the parameter into pieces of a command. - # _sp_modtype is an arg to spack module find, and - # _sp_sh_cmd is the equivalent shell command. - case $_sp_subcommand in - "use"|"unuse") - _sp_modtype=dotkit - _sp_sh_cmd=$_sp_subcommand - ;; - "load"|"unload") - _sp_modtype=tcl - _sp_sh_cmd="module $_sp_subcommand" - ;; - esac - # Here the user has run use or unuse with a spec. Find a matching # spec using 'spack module find', then use the appropriate module # tool's commands to add/remove the result from the environment. # If spack module command comes back with an error, do nothing. - if _sp_full_spec=$(command spack $_sp_flags module find $_sp_modtype $_sp_spec); then - $_sp_sh_cmd $_sp_module_args $_sp_full_spec - fi - return + case $_sp_subcommand in + "use") + if _sp_full_spec=$(command spack $_sp_flags module find dotkit $_sp_spec); then + use $_sp_module_args $_sp_full_spec + fi ;; + "unuse") + if _sp_full_spec=$(command spack $_sp_flags module find dotkit $_sp_spec); then + unuse $_sp_module_args $_sp_full_spec + fi ;; + "load") + if _sp_full_spec=$(command spack $_sp_flags module find dotkit $_sp_spec); then + module load $_sp_module_args $_sp_full_spec + fi ;; + "unload") + if _sp_full_spec=$(command spack $_sp_flags module find dotkit $_sp_spec); then + module unload $_sp_module_args $_sp_full_spec + fi ;; + esac ;; *) command spack $_sp_flags $_sp_subcommand $_sp_spec -- cgit v1.2.3-70-g09d2