From ca872f9c34f6b360d9d67a91294fa66452867e78 Mon Sep 17 00:00:00 2001 From: "John W. Parent" <45471568+johnwparent@users.noreply.github.com> Date: Fri, 1 Sep 2023 14:36:27 -0400 Subject: Windows: fix pwsh env activate/deactivate; load/unload (#39118) These commands are currently broken on powershell (Windows) due to improper use of the InvokeCommand commandlet and a lack of direct support for the `--pwsh` argument in `spack load`, `spack unload`, and `spack env deactivate`. --- bin/spack.ps1 | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'bin') diff --git a/bin/spack.ps1 b/bin/spack.ps1 index 39fe0167ca..d3f48dfc59 100644 --- a/bin/spack.ps1 +++ b/bin/spack.ps1 @@ -39,6 +39,20 @@ function Read-SpackArgs { return $SpackCMD_params, $SpackSubCommand, $SpackSubCommandArgs } +function Set-SpackEnv { + # This method is responsible + # for processing the return from $(spack ) + # which are returned as System.Object[]'s containing + # a list of env commands + # Invoke-Expression can only handle one command at a time + # so we iterate over the list to invoke the env modification + # expressions one at a time + foreach($envop in $args[0]){ + Invoke-Expression $envop + } +} + + function Invoke-SpackCD { if (Compare-CommonArgs $SpackSubCommandArgs) { python $Env:SPACK_ROOT/bin/spack cd -h @@ -79,7 +93,7 @@ function Invoke-SpackEnv { } else { $SpackEnv = $(python $Env:SPACK_ROOT/bin/spack $SpackCMD_params env activate "--pwsh" $SubCommandSubCommandArgs) - $ExecutionContext.InvokeCommand($SpackEnv) + Set-SpackEnv $SpackEnv } } "deactivate" { @@ -90,8 +104,8 @@ function Invoke-SpackEnv { python $Env:SPACK_ROOT/bin/spack env deactivate -h } else { - $SpackEnv = $(python $Env:SPACK_ROOT/bin/spack $SpackCMD_params env deactivate --pwsh) - $ExecutionContext.InvokeCommand($SpackEnv) + $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} @@ -107,8 +121,9 @@ function Invoke-SpackLoad { 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) - $ExecutionContext.InvokeCommand($SpackEnv) + Set-SpackEnv $SpackEnv } } -- cgit v1.2.3-60-g2f50