Files
qt5/coin/provisioning/common/windows/install-vcpkg.ps1
Elias Toivola 30a92ce1f2 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 <assam.boudjelthia@qt.io>
Reviewed-by: Tero Heikkinen <tero.heikkinen@qt.io>
(cherry picked from commit 33ff9ebc9e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2025-06-24 10:36:41 +00:00

87 lines
2.8 KiB
PowerShell

# Copyright (C) 2023 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
param([string]$arch="x64")
. "$PSScriptRoot\helpers.ps1"
# This script will install vcpkg
Write-Host "Installing vcpkg"
$n = Get-Content "$PSScriptRoot\..\shared\vcpkg_version.txt"
$n = $n.Split('=')
$vcpkgVersion = $n[1]
$nonDottedVersion = $vcpkgVersion.Replace(".", "")
# Download vcpkg
$vcpkgRoot = "C:\Utils\vcpkg-$vcpkgVersion"
$vcpkgRepo = Get-Content -Path "$PSScriptRoot\..\shared\vcpkg_registry_mirror.txt" | Select-Object -First 1
Write-Host "Cloning the vcpkg repo"
git.exe clone "$vcpkgRepo" "$vcpkgRoot"
git.exe -C "$vcpkgRoot" checkout "tags/$vcpkgVersion"
# Download vcpkg-tool, i.e., vcpkg.exe
$releaseTagFileContent = Get-Content "$PSScriptRoot\..\shared\vcpkg_tool_release_tag.txt"
$n = $releaseTagFileContent.Split("`n")
$sha1key = "windows_" + $arch + "_sha1"
foreach ($keyValue in $n) {
$keyValue = $keyValue.Split('=')
if($keyValue[0] -eq "vcpkg_tool_release_tag") {
$vcpkgExeReleaseTag = $keyValue[1]
} elseif($keyValue[0] -eq $sha1key) {
$vcpkgExeSHA1 = $keyValue[1]
}
}
if(!$vcpkgExeReleaseTag) {
Write-Host "Unable to read release tag from $PSScriptRoot\..\shared\vcpkg_tool_release_tag.txt"
Write-Host "Content:"
Write-Host "$releaseTagFileContent"
exit 1
}
$nonDottedReleaseTag = $vcpkgExeReleaseTag.replace('-', "")
if(!$vcpkgExeSHA1) {
Write-Host "Unable to read vcpkg tool SHA1 from $PSScriptRoot\..\shared\vcpkg_tool_release_tag.txt"
Write-Host "Content:"
Write-Host "$releaseTagFileContent"
exit 1
}
$suffix = "-$arch"
if($arch -eq "x64") {
$suffix = ""
}
$vcpkgExeOfficialUrl = "https://github.com/microsoft/vcpkg-tool/releases/download/$vcpkgExeReleaseTag/vcpkg$suffix.exe"
$vcpkgExeCacheUrl = "\\ci-files01-hki.ci.qt.io\provisioning\vcpkg\vcpkg-$nonDottedReleaseTag-windows-$arch.exe"
$vcpkgExe = "C:\Windows\Temp\vcpkg.exe"
Download "$vcpkgExeOfficialUrl" "$vcpkgExeCacheUrl" "$vcpkgExe"
Verify-Checksum $vcpkgExe $vcpkgExeSHA1
Move-Item "$vcpkgExe" -Destination "$vcpkgRoot" -Force
if(![System.IO.File]::Exists("$vcpkgRoot\vcpkg.exe")){
Write-Host "Can't find $vcpkgRoot\vcpkg.exe."
exit 1
}
# Disable telemetry
Set-Content -Value "" -Path "$vcpkgRoot\vcpkg.disable-metrics" -Force
# Bootstrap vcpkg
Set-Location -Path "$vcpkgRoot"
cmd.exe /c "$vcpkgRoot\bootstrap-vcpkg.bat"
Set-EnvironmentVariable "VCPKG_ROOT" "$vcpkgRoot"
# Set a source for vcpkg Binary and Asset Cache
# The `coin/provisioning/common/windows/mount-vcpkg-cache-drive.ps1` script is
# mounting the SMB share located in `vcpkg-server.ci.qt.io/vcpkg` to drive V:\
$env:VCPKG_BINARY_SOURCES = "files,V:/binaries,readwrite"
$env:X_VCPKG_ASSET_SOURCES = "x-azurl,file:///V:/assets,,readwrite"
Write-Output "vcpkg = $vcpkgVersion" >> ~/versions.txt