Spack on Windows: fix shell scripts when root contains a space (#39875)

Enclose variable tracking root in quotes.
This commit is contained in:
John W. Parent 2023-09-08 13:49:16 -04:00 committed by GitHub
parent 87f99de3fb
commit 14f248652c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 18 deletions

View file

@ -14,7 +14,7 @@
:: ::
@echo off @echo off
set spack=%SPACK_ROOT%\bin\spack set spack="%SPACK_ROOT%"\bin\spack
::####################################################################### ::#######################################################################
:: This is a wrapper around the spack command that forwards calls to :: This is a wrapper around the spack command that forwards calls to

View file

@ -55,10 +55,10 @@ function Set-SpackEnv {
function Invoke-SpackCD { function Invoke-SpackCD {
if (Compare-CommonArgs $SpackSubCommandArgs) { if (Compare-CommonArgs $SpackSubCommandArgs) {
python $Env:SPACK_ROOT/bin/spack cd -h python "$Env:SPACK_ROOT/bin/spack" cd -h
} }
else { else {
$LOC = $(python $Env:SPACK_ROOT/bin/spack location $SpackSubCommandArgs) $LOC = $(python "$Env:SPACK_ROOT/bin/spack" location $SpackSubCommandArgs)
if (($NULL -ne $LOC)){ if (($NULL -ne $LOC)){
if ( Test-Path -Path $LOC){ if ( Test-Path -Path $LOC){
Set-Location $LOC Set-Location $LOC
@ -75,7 +75,7 @@ function Invoke-SpackCD {
function Invoke-SpackEnv { function Invoke-SpackEnv {
if (Compare-CommonArgs $SpackSubCommandArgs[0]) { if (Compare-CommonArgs $SpackSubCommandArgs[0]) {
python $Env:SPACK_ROOT/bin/spack env -h python "$Env:SPACK_ROOT/bin/spack" env -h
} }
else { else {
$SubCommandSubCommand = $SpackSubCommandArgs[0] $SubCommandSubCommand = $SpackSubCommandArgs[0]
@ -83,46 +83,45 @@ function Invoke-SpackEnv {
switch ($SubCommandSubCommand) { switch ($SubCommandSubCommand) {
"activate" { "activate" {
if (Compare-CommonArgs $SubCommandSubCommandArgs) { if (Compare-CommonArgs $SubCommandSubCommandArgs) {
python $Env:SPACK_ROOT/bin/spack env activate $SubCommandSubCommandArgs python "$Env:SPACK_ROOT/bin/spack" env activate $SubCommandSubCommandArgs
} }
elseif ([bool]($SubCommandSubCommandArgs.Where({$_ -eq "--pwsh"}))) { elseif ([bool]($SubCommandSubCommandArgs.Where({$_ -eq "--pwsh"}))) {
python $Env:SPACK_ROOT/bin/spack env activate $SubCommandSubCommandArgs python "$Env:SPACK_ROOT/bin/spack" env activate $SubCommandSubCommandArgs
} }
elseif (!$SubCommandSubCommandArgs) { elseif (!$SubCommandSubCommandArgs) {
python $Env:SPACK_ROOT/bin/spack env activate $SubCommandSubCommandArgs python "$Env:SPACK_ROOT/bin/spack" env activate $SubCommandSubCommandArgs
} }
else { else {
$SpackEnv = $(python $Env:SPACK_ROOT/bin/spack $SpackCMD_params env activate "--pwsh" $SubCommandSubCommandArgs) $SpackEnv = $(python "$Env:SPACK_ROOT/bin/spack" $SpackCMD_params env activate "--pwsh" $SubCommandSubCommandArgs)
Set-SpackEnv $SpackEnv Set-SpackEnv $SpackEnv
} }
} }
"deactivate" { "deactivate" {
if ([bool]($SubCommandSubCommandArgs.Where({$_ -eq "--pwsh"}))) { if ([bool]($SubCommandSubCommandArgs.Where({$_ -eq "--pwsh"}))) {
python $Env:SPACK_ROOT/bin/spack env deactivate $SubCommandSubCommandArgs python"$Env:SPACK_ROOT/bin/spack" env deactivate $SubCommandSubCommandArgs
} }
elseif($SubCommandSubCommandArgs) { elseif($SubCommandSubCommandArgs) {
python $Env:SPACK_ROOT/bin/spack env deactivate -h python "$Env:SPACK_ROOT/bin/spack" env deactivate -h
} }
else { else {
$SpackEnv = $(python $Env:SPACK_ROOT/bin/spack $SpackCMD_params env deactivate "--pwsh") $SpackEnv = $(python "$Env:SPACK_ROOT/bin/spack" $SpackCMD_params env deactivate "--pwsh")
Set-SpackEnv $SpackEnv Set-SpackEnv $SpackEnv
} }
} }
default {python $Env:SPACK_ROOT/bin/spack $SpackCMD_params $SpackSubCommand $SpackSubCommandArgs} default {python "$Env:SPACK_ROOT/bin/spack" $SpackCMD_params $SpackSubCommand $SpackSubCommandArgs}
} }
} }
} }
function Invoke-SpackLoad { function Invoke-SpackLoad {
if (Compare-CommonArgs $SpackSubCommandArgs) { if (Compare-CommonArgs $SpackSubCommandArgs) {
python $Env:SPACK_ROOT/bin/spack $SpackCMD_params $SpackSubCommand $SpackSubCommandArgs python "$Env:SPACK_ROOT/bin/spack" $SpackCMD_params $SpackSubCommand $SpackSubCommandArgs
} }
elseif ([bool]($SpackSubCommandArgs.Where({($_ -eq "--pwsh") -or ($_ -eq "--list")}))) { elseif ([bool]($SpackSubCommandArgs.Where({($_ -eq "--pwsh") -or ($_ -eq "--list")}))) {
python $Env:SPACK_ROOT/bin/spack $SpackCMD_params $SpackSubCommand $SpackSubCommandArgs python "$Env:SPACK_ROOT/bin/spack" $SpackCMD_params $SpackSubCommand $SpackSubCommandArgs
} }
else { else {
# python $Env:SPACK_ROOT/bin/spack $SpackCMD_params $SpackSubCommand "--pwsh" $SpackSubCommandArgs $SpackEnv = $(python "$Env:SPACK_ROOT/bin/spack" $SpackCMD_params $SpackSubCommand "--pwsh" $SpackSubCommandArgs)
$SpackEnv = $(python $Env:SPACK_ROOT/bin/spack $SpackCMD_params $SpackSubCommand "--pwsh" $SpackSubCommandArgs)
Set-SpackEnv $SpackEnv Set-SpackEnv $SpackEnv
} }
} }
@ -131,7 +130,7 @@ function Invoke-SpackLoad {
$SpackCMD_params, $SpackSubCommand, $SpackSubCommandArgs = Read-SpackArgs $args $SpackCMD_params, $SpackSubCommand, $SpackSubCommandArgs = Read-SpackArgs $args
if (Compare-CommonArgs $SpackCMD_params) { if (Compare-CommonArgs $SpackCMD_params) {
python $Env:SPACK_ROOT/bin/spack $SpackCMD_params $SpackSubCommand $SpackSubCommandArgs python "$Env:SPACK_ROOT/bin/spack" $SpackCMD_params $SpackSubCommand $SpackSubCommandArgs
exit $LASTEXITCODE exit $LASTEXITCODE
} }
@ -143,5 +142,5 @@ switch($SpackSubCommand)
"env" {Invoke-SpackEnv} "env" {Invoke-SpackEnv}
"load" {Invoke-SpackLoad} "load" {Invoke-SpackLoad}
"unload" {Invoke-SpackLoad} "unload" {Invoke-SpackLoad}
default {python $Env:SPACK_ROOT/bin/spack $SpackCMD_params $SpackSubCommand $SpackSubCommandArgs} default {python "$Env:SPACK_ROOT/bin/spack" $SpackCMD_params $SpackSubCommand $SpackSubCommandArgs}
} }