2023-11-28 02:25:03 +01:00
|
|
|
################################################################################
|
|
|
|
|
## File: Install-Xcode.ps1
|
|
|
|
|
## Desc: Install Xcode
|
|
|
|
|
################################################################################
|
|
|
|
|
|
2020-10-31 18:41:04 +03:00
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
|
|
2020-11-01 15:55:02 +03:00
|
|
|
Import-Module "$env:HOME/image-generation/helpers/Common.Helpers.psm1"
|
2023-07-26 17:41:57 +02:00
|
|
|
Import-Module "$env:HOME/image-generation/helpers/Xcode.Installer.psm1" -DisableNameChecking
|
2020-10-31 18:41:04 +03:00
|
|
|
|
2023-12-04 12:13:08 +01:00
|
|
|
$arch = Get-Architecture
|
|
|
|
|
[Array]$xcodeVersions = (Get-ToolsetContent).xcode.$arch.versions
|
2023-05-12 13:30:13 +02:00
|
|
|
write-host $xcodeVersions
|
2023-12-04 12:13:08 +01:00
|
|
|
$defaultXcode = (Get-ToolsetContent).xcode.default
|
2020-11-09 17:46:21 +03:00
|
|
|
[Array]::Reverse($xcodeVersions)
|
2021-02-18 15:08:41 +03:00
|
|
|
$threadCount = "5"
|
2020-10-31 18:41:04 +03:00
|
|
|
|
|
|
|
|
Write-Host "Installing Xcode versions..."
|
2021-02-18 15:08:41 +03:00
|
|
|
$xcodeVersions | ForEach-Object -ThrottleLimit $threadCount -Parallel {
|
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
|
Import-Module "$env:HOME/image-generation/helpers/Common.Helpers.psm1"
|
2023-07-26 17:41:57 +02:00
|
|
|
Import-Module "$env:HOME/image-generation/helpers/Xcode.Installer.psm1" -DisableNameChecking
|
2021-02-18 15:08:41 +03:00
|
|
|
|
2023-12-15 16:44:17 +01:00
|
|
|
Install-XcodeVersion -Version $_.version -LinkTo $_.link -Sha256Sum $_.sha256
|
2020-11-01 11:13:45 +03:00
|
|
|
Confirm-XcodeIntegrity -Version $_.link
|
2023-08-22 10:01:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$xcodeVersions | ForEach-Object {
|
2020-11-01 11:13:45 +03:00
|
|
|
Approve-XcodeLicense -Version $_.link
|
2020-10-31 18:41:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Write-Host "Configuring Xcode versions..."
|
2021-07-29 16:15:45 +03:00
|
|
|
$xcodeVersions | ForEach-Object {
|
2023-03-01 10:43:47 +01:00
|
|
|
Write-Host "Configuring Xcode $($_.link) ..."
|
2021-07-29 16:15:45 +03:00
|
|
|
Invoke-XcodeRunFirstLaunch -Version $_.link
|
2023-03-01 10:43:47 +01:00
|
|
|
|
2023-10-20 11:22:53 +02:00
|
|
|
if ($_.install_runtimes -eq 'true') {
|
2023-07-07 16:24:33 +02:00
|
|
|
# Additional simulator runtimes are included by default for Xcode < 14
|
|
|
|
|
Install-AdditionalSimulatorRuntimes -Version $_.link
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-11 13:39:00 +02:00
|
|
|
ForEach($runtime in $_.runtimes) {
|
|
|
|
|
Write-Host "Installing Additional runtimes for Xcode '$runtime' ..."
|
|
|
|
|
$xcodebuildPath = Get-XcodeToolPath -Version $_.link -ToolName 'xcodebuild'
|
2023-09-13 11:45:19 +02:00
|
|
|
Invoke-ValidateCommand "sudo $xcodebuildPath -downloadPlatform $runtime" | Out-Null
|
2023-09-11 13:39:00 +02:00
|
|
|
}
|
2023-07-07 16:24:33 +02:00
|
|
|
}
|
2023-06-30 17:14:01 +02:00
|
|
|
|
2020-10-31 18:41:04 +03:00
|
|
|
Invoke-XcodeRunFirstLaunch -Version $defaultXcode
|
|
|
|
|
|
2020-11-01 11:13:45 +03:00
|
|
|
Write-Host "Configuring Xcode symlinks..."
|
|
|
|
|
$xcodeVersions | ForEach-Object {
|
|
|
|
|
Build-XcodeSymlinks -Version $_.link -Symlinks $_.symlinks
|
2021-09-18 01:10:15 +03:00
|
|
|
|
|
|
|
|
# Skip creating symlink to install multiple releases of the same Xcode version side-by-side
|
|
|
|
|
if ($_."skip-symlink" -ne "true") {
|
|
|
|
|
Build-ProvisionatorSymlink -Version $_.link
|
|
|
|
|
}
|
2020-11-01 11:13:45 +03:00
|
|
|
}
|
|
|
|
|
|
2021-12-01 12:58:26 +05:00
|
|
|
Write-Host "Rebuilding Launch Services database ..."
|
|
|
|
|
$xcodeVersions | ForEach-Object {
|
2023-12-04 12:13:08 +01:00
|
|
|
Initialize-XcodeLaunchServicesDb -Version $_.link
|
2021-12-01 12:58:26 +05:00
|
|
|
}
|
|
|
|
|
|
2020-10-31 18:41:04 +03:00
|
|
|
Write-Host "Setting default Xcode to $defaultXcode"
|
|
|
|
|
Switch-Xcode -Version $defaultXcode
|
2020-11-02 21:35:36 +03:00
|
|
|
New-Item -Path "/Applications/Xcode.app" -ItemType SymbolicLink -Value (Get-XcodeRootPath -Version $defaultXcode) | Out-Null
|
2020-10-31 18:41:04 +03:00
|
|
|
|
|
|
|
|
Write-Host "Setting environment variables 'XCODE_<VERSION>_DEVELOPER_DIR'"
|
2021-01-20 14:11:00 +07:00
|
|
|
Set-XcodeDeveloperDirEnvironmentVariables -XcodeList $xcodeVersions.link
|