From 14f248652c077e291112f456efb8026bc880d27d Mon Sep 17 00:00:00 2001 From: "John W. Parent" <45471568+johnwparent@users.noreply.github.com> Date: Fri, 8 Sep 2023 13:49:16 -0400 Subject: Spack on Windows: fix shell scripts when root contains a space (#39875) Enclose variable tracking root in quotes. --- bin/spack.bat | 2 +- bin/spack.ps1 | 33 ++++++++++++++++----------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/bin/spack.bat b/bin/spack.bat index c9afffb51a..b067256cf9 100644 --- a/bin/spack.bat +++ b/bin/spack.bat @@ -14,7 +14,7 @@ :: @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 diff --git a/bin/spack.ps1 b/bin/spack.ps1 index d3f48dfc59..e08f1fc53d 100644 --- a/bin/spack.ps1 +++ b/bin/spack.ps1 @@ -55,10 +55,10 @@ function Set-SpackEnv { function Invoke-SpackCD { if (Compare-CommonArgs $SpackSubCommandArgs) { - python $Env:SPACK_ROOT/bin/spack cd -h + python "$Env:SPACK_ROOT/bin/spack" cd -h } else { - $LOC = $(python $Env:SPACK_ROOT/bin/spack location $SpackSubCommandArgs) + $LOC = $(python "$Env:SPACK_ROOT/bin/spack" location $SpackSubCommandArgs) if (($NULL -ne $LOC)){ if ( Test-Path -Path $LOC){ Set-Location $LOC @@ -75,7 +75,7 @@ function Invoke-SpackCD { function Invoke-SpackEnv { if (Compare-CommonArgs $SpackSubCommandArgs[0]) { - python $Env:SPACK_ROOT/bin/spack env -h + python "$Env:SPACK_ROOT/bin/spack" env -h } else { $SubCommandSubCommand = $SpackSubCommandArgs[0] @@ -83,46 +83,45 @@ function Invoke-SpackEnv { switch ($SubCommandSubCommand) { "activate" { 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"}))) { - python $Env:SPACK_ROOT/bin/spack env activate $SubCommandSubCommandArgs + python "$Env:SPACK_ROOT/bin/spack" env activate $SubCommandSubCommandArgs } elseif (!$SubCommandSubCommandArgs) { - python $Env:SPACK_ROOT/bin/spack env activate $SubCommandSubCommandArgs + python "$Env:SPACK_ROOT/bin/spack" env activate $SubCommandSubCommandArgs } 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 } } "deactivate" { 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) { - python $Env:SPACK_ROOT/bin/spack env deactivate -h + python "$Env:SPACK_ROOT/bin/spack" env deactivate -h } 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 } } - 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 { 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")}))) { - python $Env:SPACK_ROOT/bin/spack $SpackCMD_params $SpackSubCommand $SpackSubCommandArgs + python "$Env:SPACK_ROOT/bin/spack" $SpackCMD_params $SpackSubCommand $SpackSubCommandArgs } 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 } } @@ -131,7 +130,7 @@ function Invoke-SpackLoad { $SpackCMD_params, $SpackSubCommand, $SpackSubCommandArgs = Read-SpackArgs $args 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 } @@ -143,5 +142,5 @@ switch($SpackSubCommand) "env" {Invoke-SpackEnv} "load" {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} } -- cgit v1.2.3-70-g09d2