summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorJohn W. Parent <45471568+johnwparent@users.noreply.github.com>2023-09-01 14:36:27 -0400
committerGitHub <noreply@github.com>2023-09-01 11:36:27 -0700
commitca872f9c34f6b360d9d67a91294fa66452867e78 (patch)
tree8121defd75132c55beccbca38bd89349c0f49453 /bin
parentb72a268bc565d370bd64589e86929acfd73c08a1 (diff)
downloadspack-ca872f9c34f6b360d9d67a91294fa66452867e78.tar.gz
spack-ca872f9c34f6b360d9d67a91294fa66452867e78.tar.bz2
spack-ca872f9c34f6b360d9d67a91294fa66452867e78.tar.xz
spack-ca872f9c34f6b360d9d67a91294fa66452867e78.zip
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`.
Diffstat (limited to 'bin')
-rw-r--r--bin/spack.ps123
1 files changed, 19 insertions, 4 deletions
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 <command>)
+ # 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
}
}