Skip to content

Commit b33be25

Browse files
authored
Merge pull request swiftlang#80441 from brianmichel/brian/always-restore-env-variables
Always restore old env variables
2 parents b3f592a + 07dac7b commit b33be25

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

utils/build.ps1

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -801,16 +801,17 @@ function Invoke-IsolatingEnvVars([scriptblock]$Block) {
801801
foreach ($Var in (Get-ChildItem env:*).GetEnumerator()) {
802802
$OldVars.Add($Var.Key, $Var.Value)
803803
}
804+
try {
805+
& $Block
806+
} finally {
807+
Remove-Item env:*
808+
foreach ($Var in $OldVars.GetEnumerator()) {
809+
New-Item -Path "env:\$($Var.Key)" -Value $Var.Value -ErrorAction Ignore | Out-Null
810+
}
804811

805-
& $Block
806-
807-
Remove-Item env:*
808-
foreach ($Var in $OldVars.GetEnumerator()) {
809-
New-Item -Path "env:\$($Var.Key)" -Value $Var.Value -ErrorAction Ignore | Out-Null
810-
}
811-
812-
if ($ToBatch) {
813-
Write-Output "endlocal"
812+
if ($ToBatch) {
813+
Write-Output "endlocal"
814+
}
814815
}
815816
}
816817

0 commit comments

Comments
 (0)