Skip to content

utils: refactor Fetch-Dependencies for future changes #73058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions utils/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -446,41 +446,37 @@ function Fetch-Dependencies {

$WebClient = New-Object Net.WebClient

$WiXVersion = "4.0.4"
$WiXURL = "https://www.nuget.org/api/v2/package/wix/$WiXVersion"
$WiXHash = "A9CA12214E61BB49430A8C6E5E48AC5AE6F27DC82573B5306955C4D35F2D34E2"
function DownloadAndVerify($URL, $Destination, $Hash) {
if (Test-Path $Destination) {
return
}

if (-not (Test-Path $BinaryCache\WiX-$WiXVersion.zip)) {
Write-Output "WiX not found. Downloading from nuget.org ..."
New-Item -ItemType Directory -ErrorAction Ignore $BinaryCache | Out-Null
Write-Output "$Destination not found. Downloading ..."
if ($ToBatch) {
Write-Output "curl.exe -sL $WiXURL -o $BinaryCache\WiX-$WiXVersion.zip"
Write-Output "md `"$(Split-Path -Path $Destination -Parent)`""
Write-Output "curl.exe -sL $URL -o $Destination"
Write-Output "(certutil -HashFile $Destination SHA256) == $Hash || (exit /b)"
} else {
$WebClient.DownloadFile($WiXURL, "$BinaryCache\WiX-$WiXVersion.zip")
$SHA256 = Get-FileHash -Path "$BinaryCache\WiX-$WiXVersion.zip" -Algorithm SHA256
if ($SHA256.Hash -ne $WiXHash) {
throw "WiX SHA256 mismatch ($($SHA256.Hash) vs $WiXHash)"
New-Item -ItemType Directory (Split-Path -Path $Destination -Parent) -ErrorAction Ignore | Out-Null
$WebClient.DownloadFile($URL, $Destination)
$SHA256 = Get-FileHash -Path $Destination -Algorithm SHA256
if ($SHA256.Hash -ne $Hash) {
throw "SHA256 mismatch ($($SHA256.Hash) vs $Hash)"
}
}
}

$WiXVersion = "4.0.4"
$WiXURL = "https://www.nuget.org/api/v2/package/wix/$WiXVersion"
$WiXHash = "A9CA12214E61BB49430A8C6E5E48AC5AE6F27DC82573B5306955C4D35F2D34E2"
DownloadAndVerify $WixURL "$BinaryCache\WiX-$WiXVersion.zip" $WiXHash

# TODO(compnerd) stamp/validate that we need to re-extract
New-Item -ItemType Directory -ErrorAction Ignore $BinaryCache\WiX-$WiXVersion | Out-Null
Write-Output "Extracting WiX ..."
Expand-Archive -Path $BinaryCache\WiX-$WiXVersion.zip -Destination $BinaryCache\WiX-$WiXVersion -Force

if (-not (Test-Path $BinaryCache\$PinnedToolchain.exe)) {
Write-Output "Swift toolchain not found. Downloading from swift.org..."
if ($ToBatch) {
Write-Output "curl.exe -sL $PinnedBuild -o $BinaryCache\$PinnedToolchain.exe"
} else {
$WebClient.DownloadFile("$PinnedBuild", "$BinaryCache\$PinnedToolchain.exe")
$SHA256 = Get-FileHash -Path "$BinaryCache\$PinnedToolchain.exe" -Algorithm SHA256
if ($SHA256.Hash -ne $PinnedSHA256) {
throw "$PinnedToolchain SHA256 mismatch ($($SHA256.Hash) vs $PinnedSHA256)"
}
}
}
DownloadAndVerify $PinnedBuild "$BinaryCache\$PinnedToolchain.exe" $PinnedSHA256

# TODO(compnerd) stamp/validate that we need to re-extract
Write-Output "Extracting $PinnedToolchain ..."
Expand Down