2018-10-08 04:52:23 +08:00
|
|
|
# Copyright 2013-2018 Lawrence Livermore National Security, LLC and other
|
|
|
|
# Spack Project Developers. See the top-level COPYRIGHT file for details.
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
|
|
|
|
2014-08-17 05:58:15 +08:00
|
|
|
########################################################################
|
|
|
|
# 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.
|
|
|
|
########################################################################
|
2014-08-17 16:41:32 +08:00
|
|
|
# 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
|
|
|
|
|
2014-08-17 05:58:15 +08:00
|
|
|
# Set up args -- we want a subcommand and a spec.
|
2014-08-17 16:41:32 +08:00
|
|
|
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-])
|
2014-08-17 05:58:15 +08:00
|
|
|
|
|
|
|
# Figure out what type of module we're running here.
|
2014-08-17 16:41:32 +08:00
|
|
|
set _sp_modtype = ""
|
2014-08-17 05:58:15 +08:00
|
|
|
switch ($_sp_subcommand)
|
2014-08-23 02:00:19 +08:00
|
|
|
case cd:
|
2014-09-30 13:39:36 +08:00
|
|
|
shift _sp_args # get rid of 'cd'
|
|
|
|
|
|
|
|
set _sp_arg=""
|
|
|
|
[ $#_sp_args -gt 0 ] && set _sp_arg = ($_sp_args[1])
|
2014-08-22 13:59:39 +08:00
|
|
|
shift _sp_args
|
2014-09-30 13:39:36 +08:00
|
|
|
|
|
|
|
if ( "$_sp_arg" == "-h" ) then
|
|
|
|
\spack cd -h
|
|
|
|
else
|
|
|
|
cd `\spack location $_sp_arg $_sp_args`
|
|
|
|
endif
|
2014-08-22 13:59:39 +08:00
|
|
|
breaksw
|
2014-08-17 05:58:15 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
# 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.
|
2014-08-23 02:00:19 +08:00
|
|
|
switch ($_sp_subcommand)
|
|
|
|
case "use":
|
2018-08-14 15:28:43 +08:00
|
|
|
set _sp_full_spec = ( "`\spack $_sp_flags module dotkit find $_sp_spec`" )
|
2014-08-23 02:00:19 +08:00
|
|
|
if ( $? == 0 ) then
|
|
|
|
use $_sp_module_args $_sp_full_spec
|
|
|
|
endif
|
|
|
|
breaksw
|
|
|
|
case "unuse":
|
2018-08-14 15:28:43 +08:00
|
|
|
set _sp_full_spec = ( "`\spack $_sp_flags module dotkit find $_sp_spec`" )
|
2014-08-23 02:00:19 +08:00
|
|
|
if ( $? == 0 ) then
|
|
|
|
unuse $_sp_module_args $_sp_full_spec
|
|
|
|
endif
|
|
|
|
breaksw
|
|
|
|
case "load":
|
2018-08-14 15:28:43 +08:00
|
|
|
set _sp_full_spec = ( "`\spack $_sp_flags module tcl find $_sp_spec`" )
|
2014-08-23 02:00:19 +08:00
|
|
|
if ( $? == 0 ) then
|
|
|
|
module load $_sp_module_args $_sp_full_spec
|
|
|
|
endif
|
|
|
|
breaksw
|
|
|
|
case "unload":
|
2018-08-14 15:28:43 +08:00
|
|
|
set _sp_full_spec = ( "`\spack $_sp_flags module tcl find $_sp_spec`" )
|
2014-08-23 02:00:19 +08:00
|
|
|
if ( $? == 0 ) then
|
|
|
|
module unload $_sp_module_args $_sp_full_spec
|
|
|
|
endif
|
|
|
|
breaksw
|
|
|
|
endsw
|
2014-08-17 16:41:32 +08:00
|
|
|
breaksw
|
|
|
|
|
2014-08-17 05:58:15 +08:00
|
|
|
default:
|
2015-11-07 02:53:22 +08:00
|
|
|
\spack $_sp_flags $_sp_args
|
2014-08-17 16:41:32 +08:00
|
|
|
breaksw
|
2014-08-17 05:58:15 +08:00
|
|
|
endsw
|
|
|
|
|
2014-08-17 16:41:32 +08:00
|
|
|
_sp_end:
|
|
|
|
unset _sp_args _sp_full_spec _sp_modtype _sp_module_args
|
|
|
|
unset _sp_sh_cmd _sp_spec _sp_subcommand _sp_flags
|