Skip to content

Commit 5496362

Browse files
compnerdshahmishal
authored andcommitted
utils: refactor Fetch-Dependencies for future changes
Future work to enable Android SDKs requires fetching additional dependencies (e.g. Android NDK). Refactor the fetch dependencies method to allow us to share the download logic rather than replicating it for each piece. This will also allow us to fetch the Python dependency for the ARM64 toolchain cross-compilation. (cherry picked from commit 726bf5c)
1 parent b586fae commit 5496362

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

utils/build.ps1

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -486,41 +486,37 @@ function Fetch-Dependencies {
486486

487487
$WebClient = New-Object Net.WebClient
488488

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

493-
if (-not (Test-Path $BinaryCache\WiX-$WiXVersion.zip)) {
494-
Write-Output "WiX not found. Downloading from nuget.org ..."
495-
New-Item -ItemType Directory -ErrorAction Ignore $BinaryCache | Out-Null
494+
Write-Output "$Destination not found. Downloading ..."
496495
if ($ToBatch) {
497-
Write-Output "curl.exe -sL $WiXURL -o $BinaryCache\WiX-$WiXVersion.zip"
496+
Write-Output "md `"$(Split-Path -Path $Destination -Parent)`""
497+
Write-Output "curl.exe -sL $URL -o $Destination"
498+
Write-Output "(certutil -HashFile $Destination SHA256) == $Hash || (exit /b)"
498499
} else {
499-
$WebClient.DownloadFile($WiXURL, "$BinaryCache\WiX-$WiXVersion.zip")
500-
$SHA256 = Get-FileHash -Path "$BinaryCache\WiX-$WiXVersion.zip" -Algorithm SHA256
501-
if ($SHA256.Hash -ne $WiXHash) {
502-
throw "WiX SHA256 mismatch ($($SHA256.Hash) vs $WiXHash)"
500+
New-Item -ItemType Directory (Split-Path -Path $Destination -Parent) -ErrorAction Ignore | Out-Null
501+
$WebClient.DownloadFile($URL, $Destination)
502+
$SHA256 = Get-FileHash -Path $Destination -Algorithm SHA256
503+
if ($SHA256.Hash -ne $Hash) {
504+
throw "SHA256 mismatch ($($SHA256.Hash) vs $Hash)"
503505
}
504506
}
505507
}
506508

509+
$WiXVersion = "4.0.4"
510+
$WiXURL = "https://www.nuget.org/api/v2/package/wix/$WiXVersion"
511+
$WiXHash = "A9CA12214E61BB49430A8C6E5E48AC5AE6F27DC82573B5306955C4D35F2D34E2"
512+
DownloadAndVerify $WixURL "$BinaryCache\WiX-$WiXVersion.zip" $WiXHash
513+
507514
# TODO(compnerd) stamp/validate that we need to re-extract
508515
New-Item -ItemType Directory -ErrorAction Ignore $BinaryCache\WiX-$WiXVersion | Out-Null
509516
Write-Output "Extracting WiX ..."
510517
Expand-Archive -Path $BinaryCache\WiX-$WiXVersion.zip -Destination $BinaryCache\WiX-$WiXVersion -Force
511518

512-
if (-not (Test-Path $BinaryCache\$PinnedToolchain.exe)) {
513-
Write-Output "Swift toolchain not found. Downloading from swift.org..."
514-
if ($ToBatch) {
515-
Write-Output "curl.exe -sL $PinnedBuild -o $BinaryCache\$PinnedToolchain.exe"
516-
} else {
517-
$WebClient.DownloadFile("$PinnedBuild", "$BinaryCache\$PinnedToolchain.exe")
518-
$SHA256 = Get-FileHash -Path "$BinaryCache\$PinnedToolchain.exe" -Algorithm SHA256
519-
if ($SHA256.Hash -ne $PinnedSHA256) {
520-
throw "$PinnedToolchain SHA256 mismatch ($($SHA256.Hash) vs $PinnedSHA256)"
521-
}
522-
}
523-
}
519+
DownloadAndVerify $PinnedBuild "$BinaryCache\$PinnedToolchain.exe" $PinnedSHA256
524520

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

0 commit comments

Comments
 (0)