From e65d3d14b4a7a9a9667b006bea1f9f2eafc69472 Mon Sep 17 00:00:00 2001 From: "John W. Parent" <45471568+johnwparent@users.noreply.github.com> Date: Wed, 7 Jul 2021 08:32:47 -0400 Subject: Relocate spack_cmd and scripts from installer to root bin (#24651) Relocate spack_cmd and scripts from installer to root bin Refactor documentation, installer, and launcher to facilitate that change --- bin/spack.bat | 223 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+) create mode 100644 bin/spack.bat (limited to 'bin/spack.bat') diff --git a/bin/spack.bat b/bin/spack.bat new file mode 100644 index 0000000000..3b6b7905a4 --- /dev/null +++ b/bin/spack.bat @@ -0,0 +1,223 @@ +:: Copyright 2013-2021 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) +::####################################################################### +:: +:: This file is part of Spack and sets up the spack environment for batch, +:: This includes environment modules and lmod support, +:: and 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/install/spack_cmd.bat +:: +@echo off + +set spack=%SPACK_ROOT%\bin\spack + +::####################################################################### +:: This is a wrapper around the spack command that forwards calls to +:: 'spack load' and 'spack unload' to shell functions. This in turn +:: allows them to be used to invoke environment modules functions. +:: +:: 'spack load' is smarter than just 'load' because it converts its +:: arguments into a unique Spack spec that is then passed to module +:: commands. This allows the user to use packages without knowing all +:: their installation details. +:: +:: e.g., rather than requiring a full spec for libelf, the user can type: +:: +:: spack load libelf +:: +:: This will first find the available libelf module file and use a +:: matching one. If there are two versions of libelf, the user would +:: need to be more specific, e.g.: +:: +:: spack load 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 module files. +::####################################################################### + +:_sp_shell_wrapper +set "_sp_flags=" +set "_sp_args=" +set "_sp_subcommand=" +setlocal enabledelayedexpansion +:: commands have the form '[flags] [subcommand] [args]' +:: flags will always start with '-', e.g. --help or -V +:: subcommands will never start with '-' +:: everything after the subcommand is an arg +for %%x in (%*) do ( + set t="%%~x" + if "!t:~0,1!" == "-" ( + if defined _sp_subcommand ( + :: We already have a subcommand, processing args now + set "_sp_args=!_sp_args! !t!" + ) else ( + set "_sp_flags=!_sp_flags! !t!" + shift + ) + ) else if not defined _sp_subcommand ( + set "_sp_subcommand=!t!" + shift + ) else ( + set "_sp_args=!_sp_args! !t!" + shift + ) +) + +:: --help, -h and -V flags don't require further output parsing. +:: If we encounter, execute and exit +if defined _sp_flags ( + if NOT "%_sp_flags%"=="%_sp_flags:-h=%" ( + python "%spack%" %_sp_flags% + exit /B 0 + ) else if NOT "%_sp_flags%"=="%_sp_flags:--help=%" ( + python "%spack%" %_sp_flags% + exit /B 0 + ) else if NOT "%_sp_flags%"=="%_sp_flags:-V=%" ( + python "%spack%" %_sp_flags% + exit /B 0 + ) +) +:: pass parsed variables outside of local scope. Need to do +:: this because delayedexpansion can only be set by setlocal +echo %_sp_flags%>flags +echo %_sp_args%>args +echo %_sp_subcommand%>subcmd +endlocal +set /p _sp_subcommand=