diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2024-10-31 12:33:00 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2024-10-31 12:52:52 (GMT) |
commit | c1ddff67f2f4fb7ec08c1481135b442a03762e5e (patch) | |
tree | 1e634615ce225768c93cdbfef3d2f5ffec3f6abe | |
parent | 641976a36b42a1a1a708f338d5218a3faf2e91d4 (diff) | |
download | CMake-c1ddff67f2f4fb7ec08c1481135b442a03762e5e.zip CMake-c1ddff67f2f4fb7ec08c1481135b442a03762e5e.tar.gz CMake-c1ddff67f2f4fb7ec08c1481135b442a03762e5e.tar.bz2 |
ci: use JSON to transfer environment variables
The `set` command in `cmd` has terrible properties in that there's no
real structure to it. Sensitive sequences in values or variable names
that are escaping sequences can be interpreted at the wrong time or
things like newlines in values are not escaped at all and cause
ambiguities in parsing. Avoid all of that and use PowerShell to use JSON
as a communication mechanism.
-rw-r--r-- | .gitlab/ci/vcvarsall.ps1 | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/.gitlab/ci/vcvarsall.ps1 b/.gitlab/ci/vcvarsall.ps1 index f91b100..f8c4150 100644 --- a/.gitlab/ci/vcvarsall.ps1 +++ b/.gitlab/ci/vcvarsall.ps1 @@ -1,9 +1,7 @@ $erroractionpreference = "stop" -cmd /c "`"$env:VCVARSALL`" $env:VCVARSPLATFORM -vcvars_ver=$env:VCVARSVERSION & set" | -foreach { - if ($_ -match "=") { - $v = $_.split("=") - [Environment]::SetEnvironmentVariable($v[0], $v[1]) - } +$all_env = cmd /c "`"$env:VCVARSALL`" $env:VCVARSPLATFORM -vcvars_ver=$env:VCVARSVERSION >NUL & powershell -Command `"Get-ChildItem env: | Select-Object -Property Key,Value | ConvertTo-Json`"" | ConvertFrom-Json + +foreach ($envvar in $all_env) { + [Environment]::SetEnvironmentVariable($envvar.Key, $envvar.Value) } |