From 30a92ce1f2c50aae5e37a2c9e6e815d88d378b0a Mon Sep 17 00:00:00 2001 From: Elias Toivola Date: Mon, 14 Apr 2025 12:25:03 +0300 Subject: [PATCH] Set-EnvironmentVariable helper: apply envvar to current PS session When you use the helper to set an envvar in provisioning, you can not reference the machine scoped variable in a later .ps1 script in the same provisoning run using the direct/static reference '$env:NAME', instead you have to use a more verbose method with e.g. 'Get-Item' cmdlet and/or set the envvar additionally to the process scope yourself. This change makes the helper also add process scope to the envvars, this way envvars set in provisioning can be simply referenced with '$env:NAME' in later provisioning scripts, which is consistent with the way you can use SetEnvVar helper in Unix and directly reference the envvar with just its variable name in later .sh scripts. This change also removes duplicate local scope envvar definitions now that Set-EnvironmentVariable helper does it. Change-Id: I804fa8f8dfce742a84e8b4bc077f466820589f7e Reviewed-by: Assam Boudjelthia Reviewed-by: Tero Heikkinen (cherry picked from commit 33ff9ebc9e5aff36399aed6ffe5fb61094247888) Reviewed-by: Qt Cherry-pick Bot --- coin/provisioning/common/windows/android.ps1 | 1 - coin/provisioning/common/windows/helpers.ps1 | 2 ++ coin/provisioning/common/windows/install-vcpkg.ps1 | 4 ---- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/coin/provisioning/common/windows/android.ps1 b/coin/provisioning/common/windows/android.ps1 index 5b2039d1..4e9dde67 100644 --- a/coin/provisioning/common/windows/android.ps1 +++ b/coin/provisioning/common/windows/android.ps1 @@ -57,7 +57,6 @@ $ndkFolderDefault = Install $ndkCachedUrlDefault $ndkZip $ndkChecksumDefault $nd Set-EnvironmentVariable "ANDROID_NDK_ROOT_DEFAULT" $ndkFolderDefault # To be used by vcpkg Set-EnvironmentVariable "ANDROID_NDK_HOME" $ndkFolderDefault -$env:ANDROID_NDK_HOME = "$ndkFolderDefault" if ($ndkVersionDefault -eq $ndkVersionLatest) { Write-Host "Android Latest version is the same than Default. NDK installation done." diff --git a/coin/provisioning/common/windows/helpers.ps1 b/coin/provisioning/common/windows/helpers.ps1 index ad01c499..9e4122ea 100644 --- a/coin/provisioning/common/windows/helpers.ps1 +++ b/coin/provisioning/common/windows/helpers.ps1 @@ -189,6 +189,8 @@ function Set-EnvironmentVariable Write-Host "Setting environment variable `"$($Key)`" to `"$($Value)`"" [Environment]::SetEnvironmentVariable($Key, $Value, [EnvironmentVariableTarget]::Machine) + # Make the envvar immediately available to subsequent scripts run in the same session. + [Environment]::SetEnvironmentVariable($Key, $Value, [EnvironmentVariableTarget]::Process) } function Is64BitWinHost diff --git a/coin/provisioning/common/windows/install-vcpkg.ps1 b/coin/provisioning/common/windows/install-vcpkg.ps1 index 1dc532c7..9b40afe0 100644 --- a/coin/provisioning/common/windows/install-vcpkg.ps1 +++ b/coin/provisioning/common/windows/install-vcpkg.ps1 @@ -75,11 +75,7 @@ Set-Content -Value "" -Path "$vcpkgRoot\vcpkg.disable-metrics" -Force Set-Location -Path "$vcpkgRoot" cmd.exe /c "$vcpkgRoot\bootstrap-vcpkg.bat" -# Setting VCPKG_ROOT using Set-EnvironmentVariable makes the variable only -# available during build time. In order to make it available during the -# provisioning, we need to directly set it via $env:VCPKG_ROOT as well. Set-EnvironmentVariable "VCPKG_ROOT" "$vcpkgRoot" -$env:VCPKG_ROOT = "$vcpkgRoot" # Set a source for vcpkg Binary and Asset Cache # The `coin/provisioning/common/windows/mount-vcpkg-cache-drive.ps1` script is