@@ -446,41 +446,37 @@ function Fetch-Dependencies {
446446
447447 $WebClient = New-Object Net.WebClient
448448
449- $WiXVersion = " 4.0.4"
450- $WiXURL = " https://www.nuget.org/api/v2/package/wix/$WiXVersion "
451- $WiXHash = " A9CA12214E61BB49430A8C6E5E48AC5AE6F27DC82573B5306955C4D35F2D34E2"
449+ function DownloadAndVerify ($URL , $Destination , $Hash ) {
450+ if (Test-Path $Destination ) {
451+ return
452+ }
452453
453- if (-not (Test-Path $BinaryCache \WiX- $WiXVersion.zip )) {
454- Write-Output " WiX not found. Downloading from nuget.org ..."
455- New-Item - ItemType Directory - ErrorAction Ignore $BinaryCache | Out-Null
454+ Write-Output " $Destination not found. Downloading ..."
456455 if ($ToBatch ) {
457- Write-Output " curl.exe -sL $WiXURL -o $BinaryCache \WiX-$WiXVersion .zip"
456+ Write-Output " md `" $ ( Split-Path - Path $Destination - Parent) `" "
457+ Write-Output " curl.exe -sL $URL -o $Destination "
458+ Write-Output " (certutil -HashFile $Destination SHA256) == $Hash || (exit /b)"
458459 } else {
459- $WebClient.DownloadFile ($WiXURL , " $BinaryCache \WiX-$WiXVersion .zip" )
460- $SHA256 = Get-FileHash - Path " $BinaryCache \WiX-$WiXVersion .zip" - Algorithm SHA256
461- if ($SHA256.Hash -ne $WiXHash ) {
462- throw " WiX SHA256 mismatch ($ ( $SHA256.Hash ) vs $WiXHash )"
460+ New-Item - ItemType Directory (Split-Path - Path $Destination - Parent) - ErrorAction Ignore | Out-Null
461+ $WebClient.DownloadFile ($URL , $Destination )
462+ $SHA256 = Get-FileHash - Path $Destination - Algorithm SHA256
463+ if ($SHA256.Hash -ne $Hash ) {
464+ throw " SHA256 mismatch ($ ( $SHA256.Hash ) vs $Hash )"
463465 }
464466 }
465467 }
466468
469+ $WiXVersion = " 4.0.4"
470+ $WiXURL = " https://www.nuget.org/api/v2/package/wix/$WiXVersion "
471+ $WiXHash = " A9CA12214E61BB49430A8C6E5E48AC5AE6F27DC82573B5306955C4D35F2D34E2"
472+ DownloadAndVerify $WixURL " $BinaryCache \WiX-$WiXVersion .zip" $WiXHash
473+
467474 # TODO(compnerd) stamp/validate that we need to re-extract
468475 New-Item - ItemType Directory - ErrorAction Ignore $BinaryCache \WiX- $WiXVersion | Out-Null
469476 Write-Output " Extracting WiX ..."
470477 Expand-Archive - Path $BinaryCache \WiX- $WiXVersion.zip - Destination $BinaryCache \WiX- $WiXVersion - Force
471478
472- if (-not (Test-Path $BinaryCache \$PinnedToolchain.exe )) {
473- Write-Output " Swift toolchain not found. Downloading from swift.org..."
474- if ($ToBatch ) {
475- Write-Output " curl.exe -sL $PinnedBuild -o $BinaryCache \$PinnedToolchain .exe"
476- } else {
477- $WebClient.DownloadFile (" $PinnedBuild " , " $BinaryCache \$PinnedToolchain .exe" )
478- $SHA256 = Get-FileHash - Path " $BinaryCache \$PinnedToolchain .exe" - Algorithm SHA256
479- if ($SHA256.Hash -ne $PinnedSHA256 ) {
480- throw " $PinnedToolchain SHA256 mismatch ($ ( $SHA256.Hash ) vs $PinnedSHA256 )"
481- }
482- }
483- }
479+ DownloadAndVerify $PinnedBuild " $BinaryCache \$PinnedToolchain .exe" $PinnedSHA256
484480
485481 # TODO(compnerd) stamp/validate that we need to re-extract
486482 Write-Output " Extracting $PinnedToolchain ..."
0 commit comments