Skip to content

Commit ddedfe0

Browse files
committed
[Build][Windows] Don't extract archives needlessly.
Avoid extracting archives every time you run a build.
1 parent a72c167 commit ddedfe0

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

utils/build.ps1

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -631,32 +631,53 @@ function Fetch-Dependencies {
631631

632632
Write-Output "Extracting '$ZipFileName' ..."
633633
New-Item -ItemType Directory -ErrorAction Ignore -Path $BinaryCache | Out-Null
634-
Expand-Archive -Path $source -DestinationPath $BinaryCache -Force
634+
Expand-Archive -Path $source -DestinationPath $destination -Force
635+
}
636+
637+
function Extract-Toolchain {
638+
param (
639+
[string]$InstallerExeName,
640+
[string]$BinaryCache,
641+
[string]$ToolchainName
642+
)
643+
644+
$source = Join-Path -Path $BinaryCache -ChildPath $InstallerExeName
645+
$destination = Join-Path -Path $BinaryCache -ChildPath toolchains\$ToolchainName
646+
647+
# Check if the extracted directory already exists and is up to date.
648+
if (Test-Path $destination) {
649+
$installerWriteTime = (Get-Item $source).LastWriteTime
650+
$extractedWriteTime = (Get-Item $destination).LastWriteTime
651+
if ($installerWriteTime -le $extractedWriteTime) {
652+
Write-Output "'$ToolchainName' is already extracted and up to date."
653+
return
654+
}
655+
}
656+
657+
Write-Output "Extracting '$ToolchainName' ..."
658+
659+
# The new runtime MSI is built to expand files into the immediate directory. So, setup the installation location.
660+
New-Item -ItemType Directory -ErrorAction Ignore $BinaryCache\toolchains\$PinnedToolchain\LocalApp\Programs\Swift\Runtimes\0.0.0\usr\bin | Out-Null
661+
Invoke-Program $BinaryCache\WiX-$WiXVersion\tools\net6.0\any\wix.exe -- burn extract $BinaryCache\$ToolchainName.exe -out $BinaryCache\toolchains\ -outba $BinaryCache\toolchains\
662+
Get-ChildItem "$BinaryCache\toolchains\WixAttachedContainer" -Filter "*.msi" | % {
663+
$LogFile = [System.IO.Path]::ChangeExtension($_.Name, "log")
664+
$TARGETDIR = if ($_.Name -eq "rtl.msi") { "$BinaryCache\toolchains\$ToolchainName\LocalApp\Programs\Swift\Runtimes\5.10.1\usr\bin" } else { "$BinaryCache\toolchains\$ToolchainName" }
665+
Invoke-Program -OutNull msiexec.exe /lvx! $BinaryCache\toolchains\$LogFile /qn /a $BinaryCache\toolchains\WixAttachedContainer\$_ ALLUSERS=0 TARGETDIR=$TARGETDIR
666+
}
635667
}
636668

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

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

647676
DownloadAndVerify $PinnedBuild "$BinaryCache\$PinnedToolchain.exe" $PinnedSHA256
648677

649678
# TODO(compnerd) stamp/validate that we need to re-extract
650-
Write-Output "Extracting $PinnedToolchain ..."
651679
New-Item -ItemType Directory -ErrorAction Ignore $BinaryCache\toolchains | Out-Null
652-
# The new runtime MSI is built to expand files into the immediate directory. So, setup the installation location.
653-
New-Item -ItemType Directory -ErrorAction Ignore $BinaryCache\toolchains\$PinnedToolchain\LocalApp\Programs\Swift\Runtimes\0.0.0\usr\bin | Out-Null
654-
Invoke-Program $BinaryCache\WiX-$WiXVersion\tools\net6.0\any\wix.exe -- burn extract $BinaryCache\$PinnedToolchain.exe -out $BinaryCache\toolchains\ -outba $BinaryCache\toolchains\
655-
Get-ChildItem "$BinaryCache\toolchains\WixAttachedContainer" -Filter "*.msi" | % {
656-
$LogFile = [System.IO.Path]::ChangeExtension($_.Name, "log")
657-
$TARGETDIR = if ($_.Name -eq "rtl.msi") { "$BinaryCache\toolchains\$PinnedToolchain\LocalApp\Programs\Swift\Runtimes\5.10.1\usr\bin" } else { "$BinaryCache\toolchains\$PinnedToolchain" }
658-
Invoke-Program -OutNull msiexec.exe /lvx! $BinaryCache\toolchains\$LogFile /qn /a $BinaryCache\toolchains\WixAttachedContainer\$_ ALLUSERS=0 TARGETDIR=$TARGETDIR
659-
}
680+
Extract-Toolchain "$PinnedToolchain.exe" $BinaryCache $PinnedToolchain
660681

661682
function Download-Python($ArchName) {
662683
$PythonAMD64URL = "https://www.nuget.org/api/v2/package/python/$PythonVersion"
@@ -668,10 +689,7 @@ function Fetch-Dependencies {
668689
DownloadAndVerify (Get-Variable -Name "Python${ArchName}URL").Value $BinaryCache\Python$ArchName-$PythonVersion.zip (Get-Variable -Name "Python${ArchName}Hash").Value
669690

670691
if (-not $ToBatch) {
671-
# TODO(compnerd) stamp/validate that we need to re-extract
672-
New-Item -ItemType Directory -ErrorAction Ignore $BinaryCache\Python$ArchName-$PythonVersion | Out-Null
673-
Write-Output "Extracting Python ($ArchName) ..."
674-
Expand-Archive -Path $BinaryCache\Python$ArchName-$PythonVersion.zip -Destination $BinaryCache\Python$ArchName-$PythonVersion -Force
692+
Extract-ZipFile Python$ArchName-$PythonVersion.zip $BinaryCache Python$ArchName-$PythonVersion
675693
}
676694
}
677695

0 commit comments

Comments
 (0)