From 25efb10e321352153d3998599ea21d528e52d84b Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Thu, 18 Feb 2021 15:08:41 +0300 Subject: [PATCH] Parallel installation of Xcode (#2432) * parallel xcode installation * resolve comments * fix changes * resolve comments and change ErrorActionPreference * return imports * switch ErrorActionPreference to Stop * add log for threadCount * add errorAction * use new approach for warning * change to bash -c * change approach to install xcodes through to parallel foreach * use & bash -c "command" * mv upper ErrorActionPreference and work on logs * mv $env:SPACESHIP_SKIP_2FA_UPGRADE = 1 * change process count to 5 * Invoke-XCVersion add out-host --- images/macos/helpers/Xcode.Installer.psm1 | 19 ++++++++++++++----- images/macos/provision/core/xcode.ps1 | 11 +++++++++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/images/macos/helpers/Xcode.Installer.psm1 b/images/macos/helpers/Xcode.Installer.psm1 index 6d21a613..97d4c132 100644 --- a/images/macos/helpers/Xcode.Installer.psm1 +++ b/images/macos/helpers/Xcode.Installer.psm1 @@ -10,15 +10,16 @@ function Install-XcodeVersion { $xcodeDownloadDirectory = "$env:HOME/Library/Caches/XcodeInstall" $xcodeTargetPath = Get-XcodeRootPath -Version $LinkTo + $xcodeXipDirectory = Invoke-DownloadXcodeArchive -DownloadDirectory $xcodeDownloadDirectory -Version $Version + Expand-XcodeXipArchive -DownloadDirectory $xcodeXipDirectory -TargetPath $xcodeTargetPath - Invoke-DownloadXcodeArchive -Version $Version - Expand-XcodeXipArchive -DownloadDirectory $xcodeDownloadDirectory -TargetPath $xcodeTargetPath - - Get-ChildItem $xcodeDownloadDirectory | Remove-Item -Force + Remove-Item -Path $xcodeXipDirectory -Force -Recurse } function Invoke-DownloadXcodeArchive { param( + [Parameter(Mandatory)] + [string]$DownloadDirectory, [Parameter(Mandatory)] [string]$Version ) @@ -28,7 +29,15 @@ function Invoke-DownloadXcodeArchive { throw "Version '$Version' can't be matched to any available version" } Write-Host "Downloading Xcode $resolvedVersion" - Invoke-XCVersion -Arguments "install '$resolvedVersion' --no-install" + Invoke-XCVersion -Arguments "install '$resolvedVersion' --no-install" | Out-Host + + $xcodeXipName = "$resolvedVersion" -replace " ", "_" + $xcodeXipFile = Get-ChildItem -Path $DownloadDirectory -Filter "Xcode_$xcodeXipName.xip" | Select-Object -First 1 + $tempXipDirectory = New-Item -Path $DownloadDirectory -Name "Xcode$xcodeXipName" -ItemType "Directory" + Move-Item -Path "$xcodeXipFile" -Destination $tempXipDirectory + + return $tempXipDirectory + } function Resolve-ExactXcodeVersion { diff --git a/images/macos/provision/core/xcode.ps1 b/images/macos/provision/core/xcode.ps1 index 00139405..0ce0eb8f 100644 --- a/images/macos/provision/core/xcode.ps1 +++ b/images/macos/provision/core/xcode.ps1 @@ -18,9 +18,14 @@ $os = Get-OSVersion $xcodeVersions = Get-ToolsetValue "xcode.versions" $defaultXcode = Get-ToolsetValue "xcode.default" [Array]::Reverse($xcodeVersions) +$threadCount = "5" Write-Host "Installing Xcode versions..." -$xcodeVersions | ForEach-Object { +$xcodeVersions | ForEach-Object -ThrottleLimit $threadCount -Parallel { + $ErrorActionPreference = "Stop" + Import-Module "$env:HOME/image-generation/helpers/Common.Helpers.psm1" + Import-Module "$env:HOME/image-generation/helpers/Xcode.Installer.psm1" + Install-XcodeVersion -Version $_.version -LinkTo $_.link Confirm-XcodeIntegrity -Version $_.link Approve-XcodeLicense -Version $_.link @@ -31,7 +36,9 @@ if ($os.IsLessThanCatalina) { $latestXcodeVersion = $xcodeVersions | Select-Object -Last 1 -ExpandProperty link Install-XcodeAdditionalPackages -Version $latestXcodeVersion } -$xcodeVersions | ForEach-Object { Invoke-XcodeRunFirstLaunch -Version $_.link } +$xcodeVersions | ForEach-Object { + Invoke-XcodeRunFirstLaunch -Version $_.link +} Invoke-XcodeRunFirstLaunch -Version $defaultXcode Write-Host "Configuring Xcode symlinks..."