summaryrefslogtreecommitdiff
path: root/share/spack/csh/spack.csh
diff options
context:
space:
mode:
authorGeorge Todd Gamblin <gamblin2@llnl.gov>2014-08-18 23:11:02 -0700
committerGeorge Todd Gamblin <gamblin2@llnl.gov>2014-08-18 23:11:02 -0700
commit42e27d04c17b8f011a1882bb45f899187c8ffa59 (patch)
tree39c23e96c4782a252962a004e9946dec3e493327 /share/spack/csh/spack.csh
parent884a4fecd18eb983ae02ead366d638a735e5170b (diff)
parentb601fd08caf21b5fc11e6998a5ebd20a04ac57ad (diff)
downloadspack-42e27d04c17b8f011a1882bb45f899187c8ffa59.tar.gz
spack-42e27d04c17b8f011a1882bb45f899187c8ffa59.tar.bz2
spack-42e27d04c17b8f011a1882bb45f899187c8ffa59.tar.xz
spack-42e27d04c17b8f011a1882bb45f899187c8ffa59.zip
Merge pull request #19 in SCALE/spack from features/modules to develop
# By Todd Gamblin (4) and David Beckingsale (2) # Via Todd Gamblin * commit 'b601fd08caf21b5fc11e6998a5ebd20a04ac57ad': Bugfixes for csh environment modules. Bugfixes, more consolidation of modules code. Add csh/tcsh support for modules Consolidate most module code into spack.modules and spack.cmd.module Fixed up module support Added inital module support
Diffstat (limited to 'share/spack/csh/spack.csh')
-rw-r--r--share/spack/csh/spack.csh91
1 files changed, 91 insertions, 0 deletions
diff --git a/share/spack/csh/spack.csh b/share/spack/csh/spack.csh
new file mode 100644
index 0000000000..169e9878bf
--- /dev/null
+++ b/share/spack/csh/spack.csh
@@ -0,0 +1,91 @@
+########################################################################
+# This is a wrapper around the spack command that forwards calls to
+# 'spack use' and 'spack unuse' to shell functions. This in turn
+# allows them to be used to invoke dotkit functions.
+#
+# 'spack use' is smarter than just 'use' because it converts its
+# arguments into a unique spack spec that is then passed to dotkit
+# commands. This allows the user to use packages without knowing all
+# their installation details.
+#
+# e.g., rather than requring a full spec for libelf, the user can type:
+#
+# spack use libelf
+#
+# This will first find the available libelf dotkits and use a
+# matching one. If there are two versions of libelf, the user would
+# need to be more specific, e.g.:
+#
+# spack use libelf@0.8.13
+#
+# This is very similar to how regular spack commands work and it
+# avoids the need to come up with a user-friendly naming scheme for
+# spack dotfiles.
+########################################################################
+# accumulate initial flags for main spack command
+set _sp_flags = ""
+while ( $#_sp_args > 0 )
+ if ( "$_sp_args[1]" !~ "-*" ) break
+ set _sp_flags = "$_sp_flags $_sp_args[1]"
+ shift _sp_args
+end
+
+# h and V flags don't require further output parsing.
+if ( "$_sp_flags" =~ *h* || "$_sp_flags" =~ *V* ) then
+ \spack $_sp_flags $_sp_args
+ goto _sp_end
+endif
+
+# Set up args -- we want a subcommand and a spec.
+set _sp_subcommand=""
+set _sp_spec=""
+[ $#_sp_args -gt 0 ] && set _sp_subcommand = ($_sp_args[1])
+[ $#_sp_args -gt 1 ] && set _sp_spec = ($_sp_args[2-])
+
+# Figure out what type of module we're running here.
+set _sp_modtype = ""
+switch ($_sp_subcommand)
+case use:
+case unuse:
+case load:
+case unload:
+ set _sp_module_args=""""
+ if ( "$_sp_spec" =~ "-*" ) then
+ set _sp_module_args = $_sp_spec[1]
+ 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
+ breaksw
+
+default:
+ \spack $_sp_args
+ breaksw
+endsw
+
+_sp_end:
+unset _sp_args _sp_full_spec _sp_modtype _sp_module_args
+unset _sp_sh_cmd _sp_spec _sp_subcommand _sp_flags