From 0d08e13079313bdfaf1fb28807057a1a10a06842 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Mon, 19 Oct 2020 08:24:21 +0300 Subject: [PATCH 01/26] test changes --- images/macos/provision/core/xcode-tools.sh | 28 +++++++++++---------- images/macos/provision/utils/utils.sh | 12 --------- images/macos/provision/utils/xcode-utils.sh | 4 +-- images/macos/toolsets/toolset-10.15.json | 13 +++++++++- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/images/macos/provision/core/xcode-tools.sh b/images/macos/provision/core/xcode-tools.sh index 643dc293..ebd6e43a 100755 --- a/images/macos/provision/core/xcode-tools.sh +++ b/images/macos/provision/core/xcode-tools.sh @@ -13,17 +13,20 @@ if [ -z $XCODE_INSTALL_USER ] || [ -z $XCODE_INSTALL_PASSWORD ]; then exit 1 fi -XCODE_LIST=($(get_xcode_list_from_toolset)) -LATEST_XCODE_VERSION=$(get_latest_xcode_from_toolset) -DEFAULT_XCODE_VERSION=$(get_default_xcode_from_toolset) +XCODE_COUNT=$(get_toolset_value '.xcode.versions | length') +DEFAULT_XCODE_VERSION=$(get_toolset_value '.xcode.default') WORK_DIR="${HOME}/Library/Caches/XcodeInstall" # Update the list of available versions xcversion update -for XCODE_VERSION in "${XCODE_LIST[@]}" -do - VERSION_TO_INSTALL="$(getXcodeVersionToInstall "$XCODE_VERSION")" +for ((XCODE_INDEX=0; XCODE_INDEX Date: Thu, 22 Oct 2020 18:01:14 +0300 Subject: [PATCH 02/26] xcode-tools --- images/macos/provision/core/xcode-tools.sh | 51 ++++-------------- images/macos/provision/utils/xcode-utils.sh | 58 +++++++++++++++------ images/macos/tests/Xcode.Tests.ps1 | 4 ++ images/macos/toolsets/toolset-10.15.json | 16 +++--- 4 files changed, 65 insertions(+), 64 deletions(-) diff --git a/images/macos/provision/core/xcode-tools.sh b/images/macos/provision/core/xcode-tools.sh index ebd6e43a..d9f33fe9 100755 --- a/images/macos/provision/core/xcode-tools.sh +++ b/images/macos/provision/core/xcode-tools.sh @@ -14,6 +14,7 @@ if [ -z $XCODE_INSTALL_USER ] || [ -z $XCODE_INSTALL_PASSWORD ]; then fi XCODE_COUNT=$(get_toolset_value '.xcode.versions | length') +XCODE_LOCAL_LIST=$(get_toolset_value '.xcode.versions[].localVersion') DEFAULT_XCODE_VERSION=$(get_toolset_value '.xcode.default') WORK_DIR="${HOME}/Library/Caches/XcodeInstall" @@ -25,64 +26,33 @@ for ((XCODE_INDEX=0; XCODE_INDEX 11.3.1, 11.2 -> 11.2.1 -if is_Catalina; then - ln -sf /Applications/Xcode_11.2.1.app /Applications/Xcode_11.2.app - ln -sf /Applications/Xcode_11.3.1.app /Applications/Xcode_11.3.app -fi - echo "Setting Xcode ${DEFAULT_XCODE_VERSION} as default" sudo xcode-select -s "/Applications/Xcode_${DEFAULT_XCODE_VERSION}.app/Contents/Developer" @@ -95,6 +65,5 @@ sudo /usr/sbin/DevToolsSecurity --enable echo "Setting environment variables 'XCODE__DEVELOPER_DIR'" setXcodeDeveloperDirVariables -# Cleanup echo "Doing cleanup. Emptying ${WORK_DIR}..." rm -rf "$WORK_DIR" diff --git a/images/macos/provision/utils/xcode-utils.sh b/images/macos/provision/utils/xcode-utils.sh index 729b59d9..5c5e871b 100644 --- a/images/macos/provision/utils/xcode-utils.sh +++ b/images/macos/provision/utils/xcode-utils.sh @@ -1,15 +1,14 @@ -createXamarinProvisionatorSymlink() { +downloadXcode() { local XCODE_VERSION="$1" - local FULL_VERSION=$(echo "${XCODE_VERSION}.0.0" | cut -d'.' -f 1,2,3) - # temporary trick for 12.0.1 - if [[ $XCODE_VERSION == "12" ]]; then - FULL_VERSION="12.0.1" + VERSION_TO_INSTALL=$(resolveLatestXcodeVersion "$XCODE_VERSION") + if [[ -z "$VERSION_TO_INSTALL" ]]; then + echo "No versions were found matching $XCODE_VERSION" + exit 1 fi - if [ $FULL_VERSION != $XCODE_VERSION ]; then - ln -sf "/Applications/Xcode_${XCODE_VERSION}.app" "/Applications/Xcode_${FULL_VERSION}.app" - fi + echo "Downloading Xcode $VERSION_TO_INSTALL ..." + xcversion install "$VERSION_TO_INSTALL" --no-install } resolveLatestXcodeVersion() { @@ -36,7 +35,7 @@ validateXcodeIntegrity() { spctl --assess --raw "${WORKING_DIR}/Xcode.app" } -approveLicense() { +approveXcodeLicense() { local XCODE_VERSION="$1" sudo "/Applications/Xcode_${XCODE_VERSION}.app/Contents/Developer/usr/bin/xcodebuild" -license accept } @@ -52,6 +51,24 @@ runFirstLaunch() { sudo "/Applications/Xcode_${XCODE_VERSION}.app/Contents/Developer/usr/bin/xcodebuild" -runFirstLaunch } +runFirstLaunchXcodeList() { + local XCODE_LIST=("$@") + if is_Less_Catalina; then + echo "Install additional packages for Xcode ${XCODE_LIST[0]}" + installAdditionalPackages ${XCODE_LIST[0]} + fi + + for XCODE_VERSION in "${XCODE_LIST[@]}" + do + if [[ $XCODE_VERSION == 8* || $XCODE_VERSION == 9* ]]; then + continue + fi + + echo "Running 'runFirstLaunch' for Xcode ${XCODE_VERSION}..." + runFirstLaunch $XCODE_VERSION + done +} + setXcodeDeveloperDirVariables() { stable_xcode_versions=$(get_xcode_list_from_toolset | tr " " "\n" | grep -v "beta") major_versions=($(echo ${stable_xcode_versions[@]} | tr " " "\n" | cut -d '.' -f 1 | uniq)) @@ -65,8 +82,7 @@ setXcodeDeveloperDirVariables() { extractXcodeXip() { local WORKING_DIR="$1" - local XCODE_VERSION="$2" - XCODE_XIP="${WORKING_DIR}/Xcode_${XCODE_VERSION// /_}.xip" + local XCODE_XIP=$(find "$WORKING_DIR" -name "Xcode_*.xip" | head -n1) open -W $XCODE_XIP @@ -80,9 +96,21 @@ extractXcodeXip() { fi } -createBetaSymlink() { - local XCODE_VERSION=$1 - if [[ $XCODE_VERSION =~ 1[01].* ]] || [[ $XCODE_VERSION == "12.0" ]]; then - ln -sf "/Applications/Xcode_${XCODE_VERSION}.app" "/Applications/Xcode_${XCODE_VERSION}_beta.app" +createXcodeSymlinks() { + local SOURCE_XCODE=$1 && shift + local SYMLINKS=($@) + + + for TARGET_XCODE in "${SYMLINKS[@]}" + do + echo "Creating symlink '/Applications/Xcode_${SOURCE_XCODE}.app' -> '/Applications/Xcode_${TARGET_XCODE}.app'" + ln -sf "/Applications/Xcode_${SOURCE_XCODE}.app" "/Applications/Xcode_${TARGET_XCODE}.app" + done + + # TO-DO, symlink is not correct + local FULL_XCODE_VERSION=$(echo "${XCODE_VERSION}.0.0" | cut -d'.' -f 1,2,3) + if [ $FULL_XCODE_VERSION != $SOURCE_XCODE ]; then + echo "Creating symlink '/Applications/Xcode_${SOURCE_XCODE}.app' -> '/Applications/Xcode_${FULL_XCODE_VERSION}.app'" + ln -sf "/Applications/Xcode_${SOURCE_XCODE}.app" "/Applications/Xcode_${FULL_XCODE_VERSION}.app" fi } \ No newline at end of file diff --git a/images/macos/tests/Xcode.Tests.ps1 b/images/macos/tests/Xcode.Tests.ps1 index 250c8d8a..fd12db68 100644 --- a/images/macos/tests/Xcode.Tests.ps1 +++ b/images/macos/tests/Xcode.Tests.ps1 @@ -13,6 +13,10 @@ Describe "Xcode" { (Get-CommandResult "xcodebuild -version").Output | Should -BeLike "Xcode $DEFAULT_XCODE*" } + It "Xcode.app points to default Xcode" { + + } + # Cut "_beta" postfix for test cases $testCases = $XCODE_VERSIONS | ForEach-Object { @{XcodeVersion = $_.Split("_")[0] } } diff --git a/images/macos/toolsets/toolset-10.15.json b/images/macos/toolsets/toolset-10.15.json index f7d7c6ae..1425c30a 100644 --- a/images/macos/toolsets/toolset-10.15.json +++ b/images/macos/toolsets/toolset-10.15.json @@ -5,15 +5,15 @@ { "localVersion": "12.2", "version": "12.2_beta" }, { "localVersion": "12.1", "version": "12.1_GM_seed" }, { "localVersion": "12.0", "version": "12.0.1", "symlinks": ["12"] }, - { "localVersion": "11.7", "version": "11.7" }, - { "localVersion": "11.6", "version": "11.6" }, - { "localVersion": "11.5", "version": "11.5" }, - { "localVersion": "11.4", "version": "11.4.1" }, - { "localVersion": "11.3", "version": "11.3.1", "symlinks": ["11.3"] }, - { "localVersion": "11.2", "version": "11.2.1", "symlinks": ["11.2"] }, - { "localVersion": "11.1", "version": "11.1" }, + { "localVersion": "11.7", "version": "11.7", "symlinks": ["11.7_beta"] }, + { "localVersion": "11.6", "version": "11.6", "symlinks": ["11.6_beta"] }, + { "localVersion": "11.5", "version": "11.5", "symlinks": ["11.5_beta"] }, + { "localVersion": "11.4", "version": "11.4.1", "symlinks": ["11.4_beta"] }, + { "localVersion": "11.3", "version": "11.3.1", "symlinks": ["11.3", "11.3_beta"] }, + { "localVersion": "11.2", "version": "11.2.1", "symlinks": ["11.2", "11.2_beta"] }, + { "localVersion": "11.1", "version": "11.1", "symlinks": ["11.1_beta"] }, { "localVersion": "11.0", "version": "11", "symlinks": ["11"] }, - { "localVersion": "10.3", "version": "10.3" } + { "localVersion": "10.3", "version": "10.3", "symlinks": ["10.3_beta"] } ] }, "xamarin": { From b49a705f6bad1f35383373c9f1460d1867d4e2cb Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Sat, 31 Oct 2020 18:41:04 +0300 Subject: [PATCH 03/26] need to test --- images/macos/helpers/Xcode.Helpers.psm1 | 20 ++- images/macos/helpers/Xcode.Installer.psm1 | 160 ++++++++++++++++++ .../configuration/configure-machine.sh | 4 + images/macos/provision/core/xcode-tools.sh | 69 -------- images/macos/provision/core/xcode.ps1 | 38 +++++ images/macos/provision/utils/xcode-utils.sh | 118 ------------- .../software-report/SoftwareReport.Xcode.psm1 | 24 ++- images/macos/templates/macOS-10.15.json | 10 +- images/macos/toolsets/toolset-10.15.json | 24 +-- 9 files changed, 245 insertions(+), 222 deletions(-) create mode 100644 images/macos/helpers/Xcode.Installer.psm1 delete mode 100755 images/macos/provision/core/xcode-tools.sh create mode 100644 images/macos/provision/core/xcode.ps1 delete mode 100644 images/macos/provision/utils/xcode-utils.sh diff --git a/images/macos/helpers/Xcode.Helpers.psm1 b/images/macos/helpers/Xcode.Helpers.psm1 index 52a182d5..2b2ebeef 100644 --- a/images/macos/helpers/Xcode.Helpers.psm1 +++ b/images/macos/helpers/Xcode.Helpers.psm1 @@ -8,9 +8,7 @@ function Get-XcodeRootPath { } function Get-DefaultXcodeRootPath { - $defaultXcodePath = "/Applications/Xcode.app" - $defaultXcodeItem = Get-Item -Path $defaultXcodePath - return $defaultXcodeItem.Target + return (Get-Item -Path "/Applications/Xcode.app").Target } function Get-XcodeToolPath { @@ -29,6 +27,22 @@ function Get-XcodeToolPath { return Join-Path $XcodeRootPath "Contents/Developer/usr/bin" $ToolName } +function Get-XcodeVersionInfo { + param( + [Parameter(Mandatory)] + [string]$XcodeRootPath + ) + + $xcodebuildPath = Get-XcodeToolPath -XcodeRootPath $XcodeRootPath -ToolName "xcodebuild" + [string]$output = Invoke-Expression "$xcodebuildPath -version" + $versionOutputParts = $output.Split(" ") + return @{ + Version = [System.Version]::Parse($versionOutputParts[1]) + Build = $versionOutputParts[4] + } +} + + function Switch-Xcode { param ( [Parameter(ParameterSetName = 'Version')] diff --git a/images/macos/helpers/Xcode.Installer.psm1 b/images/macos/helpers/Xcode.Installer.psm1 new file mode 100644 index 00000000..619d167e --- /dev/null +++ b/images/macos/helpers/Xcode.Installer.psm1 @@ -0,0 +1,160 @@ +Import-Module "$PSScriptRoot/Xcode.Helpers.psm1" + +function Install-XcodeVersion { + param( + [Parameter(Mandatory)] + [string]$Version, + [Parameter(Mandatory)] + [string]$LocalLink + ) + + $xcodeDownloadDirectory = "$env:HOME/Library/Caches/XcodeInstall" + $xcodeTargetPath = Get-XcodeRootPath -Version $LocalLink + Push-Location $xcodeDownloadDirectory + + Invoke-DownloadXcodeArchive -Version $Version + Expand-XcodeXipArchive -DownloadDirectory $xcodeDownloadDirectory -TargetPath $xcodeTargetPath + Confirm-XcodeIntegrity -XcodeRootPath $xcodeTargetPath + Approve-XcodeLicense -XcodeRootPath $xcodeTargetPath + + Get-ChildItem $xcodeDownloadDirectory | Remove-Item -Force +} + +function Invoke-DownloadXcodeArchive { + param( + [Parameter(Mandatory)] + [string]$Version + ) + + $resolvedVersion = Resolve-ExactXcodeVersion -Version $Version + if (-not $resolvedVersion) { + throw "Version '$Version' can't be matched to any available version" + } + + # TO-DO: Consider replacing of xcversion with own implementation + Write-Host "Downloading Xcode $resolvedVersion" + xcversion install "$resolvedVersion" --no-install +} + +function Resolve-ExactXcodeVersion { + param( + [Parameter(Mandatory)] + [string]$Version + ) + + # TO-DO + return $Version +} + +function Expand-XcodeXipArchive { + param( + [Parameter(Mandatory)] + [string]$DownloadDirectory, + [Parameter(Mandatory)] + [string]$TargetPath + ) + + $xcodeXipPath = Get-ChildItem -Path $DownloadDirectory -Filter "Xcode_*.xip" | Select-Object -First 1 + + Write-Host "Extracting Xcode from '$xcodeXipPath'" + Push-Location $DownloadDirectory + xip -x $xcodeXipPath + Pop-Location + + if (Test-Path "$DownloadDirectory/Xcode-beta.app") { + Write-Host "Renaming Xcode-beta.app to Xcode.app" + Rename-File -Path "$DownloadDirectory/Xcode-beta.app" -NewName "Xcode.app" + } + + if (-not (Test-Path "$DownloadDirectory/Xcode.app")) { + throw "XIP archive '$xcodeXipPath' doesn't contain 'Xcode.app'" + } + + Write-Host "Moving '$DownloadDirectory/Xcode.app' to '$TargetPath'" + Move-Item -Path "$DownloadDirectory/Xcode.app" -Destination $TargetPath +} + +function Confirm-XcodeIntegrity { + param( + [Parameter(Mandatory)] + [string]$XcodeRootPath + ) + + if (Test-XcodeStableRelease -XcodeRootPath $XcodeRootPath) { + spctl --assess --raw $XcodeRootPath + } +} + +function Approve-XcodeLicense { + param( + [Parameter(Mandatory)] + $XcodeRootPath + ) + + $xcodeBuildPath = Get-XcodeToolPath -XcodeRootPath $XcodeRootPath -ToolName "xcodebuild" + sudo $xcodeBuildPath -license accept +} + +function Install-XcodeAdditionalPackages { + param( + [Parameter(Mandatory)] + [string]$Version + ) + + Write-Host "Installing additional packages for Xcode $Version..." + $xcodeRootPath = Get-XcodeRootPath -Version $Version + $packages = Get-ChildItem -Path "$xcodeRootPath/Contents/Resources/Packages" -Filter "*.pkg" -Name -File + $packages | ForEach-Object { & sudo installer -pkg $_ -target / -allowUntrusted } +} + +function Invoke-XcodeRunFirstLaunch { + param( + [Parameter(Mandatory)] + [string]$Version + ) + + if ($Version.StartsWith("8.") -or $Version.StartsWith("9.")) { + return + } + + Write-Host "Running 'runFirstLaunch' for Xcode $Version..." + $xcodeRootPath = Get-XcodeToolPath -Version $Version -ToolName "xcodebuild" + & sudo $xcodeRootPath -runFirstLaunch +} + +function Build-XcodeSymlinks { + param( + [Parameter(Mandatory)] + [string]$Version, + [Parameter(Mandatory)] + [string[]]$Symlinks + ) + + $sourcePath = Get-XcodeRootPath -Version $Version + $Symlinks | ForEach-Object { + $targetPath = Get-XcodeRootPath -Version $_ + Write-Host "Creating symlink: '$targetPath' -> '$sourcePath'" + New-Item -Path $targetPath -ItemType SymbolicLink -Value $sourcePath + } +} + +function Build-ProvisionatorSymlink { + param( + [Parameter(Mandatory)] + [string]$Version + ) + + $sourcePath = Get-XcodeRootPath -Version $Version + $versionInfo = Get-XcodeVersionInfo -XcodeRootPath $sourcePath + + $targetVersion = [SemVer]::Parse($versionInfo.Version).ToString() + $targetPath = Get-XcodeRootPath -Version $targetVersion + if ($sourcePath -ne $targetPath) { + Write-Host "Creating provisionator symlink: '$targetPath' -> '$sourcePath'" + New-Item -Path $targetPath -ItemType SymbolicLink -Value $sourcePath + } +} + +function Set-XcodeDeveloperDirEnvironmentVariables { + # TO-DO +} \ No newline at end of file diff --git a/images/macos/provision/configuration/configure-machine.sh b/images/macos/provision/configuration/configure-machine.sh index dbfae673..126c5a7c 100644 --- a/images/macos/provision/configuration/configure-machine.sh +++ b/images/macos/provision/configuration/configure-machine.sh @@ -8,11 +8,15 @@ echo "Configuring system time to GMT..." rm -f /etc/localtime ln -sf /usr/share/zoneinfo/UTC /etc/localtime +echo "Enabling safari driver..." # https://developer.apple.com/documentation/webkit/testing_with_webdriver_in_safari # Safari’s executable is located at /usr/bin/safaridriver # Configure Safari to Enable WebDriver Support sudo safaridriver --enable +echo "Enabling developer mode..." +sudo /usr/sbin/DevToolsSecurity --enable + # Turn off hibernation and get rid of the sleepimage sudo pmset hibernatemode 0 sudo rm -f /var/vm/sleepimage diff --git a/images/macos/provision/core/xcode-tools.sh b/images/macos/provision/core/xcode-tools.sh deleted file mode 100755 index d9f33fe9..00000000 --- a/images/macos/provision/core/xcode-tools.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/sh - -# The script currently requires 2 external variables to be set: XCODE_INSTALL_USER -# and XCODE_INSTALL_PASSWORD, in order to access the Apple Developer Center - -set -e - -source ~/utils/utils.sh -source ~/utils/xcode-utils.sh - -if [ -z $XCODE_INSTALL_USER ] || [ -z $XCODE_INSTALL_PASSWORD ]; then - echo "Required environment variables XCODE_INSTALL_USER and XCODE_INSTALL_PASSWORD are not set" - exit 1 -fi - -XCODE_COUNT=$(get_toolset_value '.xcode.versions | length') -XCODE_LOCAL_LIST=$(get_toolset_value '.xcode.versions[].localVersion') -DEFAULT_XCODE_VERSION=$(get_toolset_value '.xcode.default') -WORK_DIR="${HOME}/Library/Caches/XcodeInstall" - -# Update the list of available versions -xcversion update - -for ((XCODE_INDEX=0; XCODE_INDEX '/Applications/Xcode.app'" -ln -s "/Applications/Xcode_${DEFAULT_XCODE_VERSION}.app" "/Applications/Xcode.app" - -echo "Enabling developer mode" -sudo /usr/sbin/DevToolsSecurity --enable - -echo "Setting environment variables 'XCODE__DEVELOPER_DIR'" -setXcodeDeveloperDirVariables - -echo "Doing cleanup. Emptying ${WORK_DIR}..." -rm -rf "$WORK_DIR" diff --git a/images/macos/provision/core/xcode.ps1 b/images/macos/provision/core/xcode.ps1 new file mode 100644 index 00000000..f3ea5564 --- /dev/null +++ b/images/macos/provision/core/xcode.ps1 @@ -0,0 +1,38 @@ +# The script currently requires 2 external variables to be set: XCODE_INSTALL_USER +# and XCODE_INSTALL_PASSWORD, in order to access the Apple Developer Center + +$ErrorActionPreference = "Stop" + +Import-Module "$PSScriptRoot/../../helpers/Common.Helpers.psm1" +Import-Module "$PSScriptRoot/../../helpers/Xcode.Installer.psm1" + +if ([string]::IsNullOrEmpty($env:XCODE_INSTALL_USER) -or [string]::IsNullOrEmpty($env:XCODE_INSTALL_PASSWORD)) { + throw "Required environment variables XCODE_INSTALL_USER and XCODE_INSTALL_PASSWORD are not set" +} + +$os = Get-OSVersion +$xcodeVersions = Get-ToolsetValue "xcode.versions" +$defaultXcode = Get-ToolsetValue "xcode.default" + +& xcversion update + +Write-Host "Installing Xcode versions..." +foreach ($xcode in $xcodeVersions) { + Install-XcodeVersion -Version $xcode.version -LocalLink $xcode.localLink + Build-XcodeSymlinks -Version $xcode.localLink -Symlinks $xcode.symlinks + Build-ProvisionatorSymlink -Version $xcode.version +} + +Write-Host "Configuring Xcode versions..." +if ($os.IsLessThanCatalina) { + Install-XcodeAdditionalPackages -Version $xcodeVersions[0].localLink +} +$xcodeVersions | ForEach-Object { Invoke-XcodeRunFirstLaunch -Version $_.localLink } +Invoke-XcodeRunFirstLaunch -Version $defaultXcode + +Write-Host "Setting default Xcode to $defaultXcode" +Switch-Xcode -Version $defaultXcode +New-Item -Path "/Applications/Xcode.app" -ItemType SymbolicLink -Value (Get-XcodeRootPath -Version $defaultXcode) + +Write-Host "Setting environment variables 'XCODE__DEVELOPER_DIR'" +Set-XcodeDeveloperDirEnvironmentVariables \ No newline at end of file diff --git a/images/macos/provision/utils/xcode-utils.sh b/images/macos/provision/utils/xcode-utils.sh deleted file mode 100644 index 0105f28a..00000000 --- a/images/macos/provision/utils/xcode-utils.sh +++ /dev/null @@ -1,118 +0,0 @@ -downloadXcode() { - local XCODE_VERSION="$1" - - VERSION_TO_INSTALL=$(resolveLatestXcodeVersion "$XCODE_VERSION") - if [[ -z "$VERSION_TO_INSTALL" ]]; then - echo "No versions were found matching $XCODE_VERSION" - exit 1 - fi - - echo "Downloading Xcode $VERSION_TO_INSTALL ..." - xcversion install "$VERSION_TO_INSTALL" --no-install -} - -resolveLatestXcodeVersion() { - local XCODE_VERSION="$1" - - if [[ $XCODE_VERSION == "12" ]]; then - echo "12.0.1" - elif [[ ! $XCODE_VERSION =~ "_beta" ]]; then - echo "${XCODE_VERSION//_/ }" - else - local XCODE_BETA="${XCODE_VERSION/_/ }" - echo "$(xcversion list | sort -r | grep -m 1 "$XCODE_BETA")" - fi -} - -validateXcodeIntegrity() { - local WORKING_DIR="$1" - local XCODE_VERSION="$2" - - if echo $XCODE_VERSION | grep "beta"; then - return 0 - fi - - spctl --assess --raw "${WORKING_DIR}/Xcode.app" -} - -approveXcodeLicense() { - local XCODE_VERSION="$1" - sudo "/Applications/Xcode_${XCODE_VERSION}.app/Contents/Developer/usr/bin/xcodebuild" -license accept -} - -installAdditionalPackages() { - # should be called only for old High Sierra and Mojave - local XCODE_VERSION="$1" - find /Applications/Xcode_${XCODE_VERSION}.app/Contents/Resources/Packages/ -name '*.pkg' | xargs -I '{}' sudo installer -pkg '{}' -target / -allowUntrusted -} - -runFirstLaunch() { - local XCODE_VERSION="$1" - sudo "/Applications/Xcode_${XCODE_VERSION}.app/Contents/Developer/usr/bin/xcodebuild" -runFirstLaunch -} - -runFirstLaunchXcodeList() { - local XCODE_LIST=("$@") - if is_Less_Catalina; then - echo "Install additional packages for Xcode ${XCODE_LIST[0]}" - installAdditionalPackages ${XCODE_LIST[0]} - fi - - for XCODE_VERSION in "${XCODE_LIST[@]}" - do - if [[ $XCODE_VERSION == 8* || $XCODE_VERSION == 9* ]]; then - continue - fi - - echo "Running 'runFirstLaunch' for Xcode ${XCODE_VERSION}..." - runFirstLaunch $XCODE_VERSION - done -} - -setXcodeDeveloperDirVariables() { - stable_xcode_versions=$(get_xcode_list_from_toolset | tr " " "\n" | grep -v "beta") - major_versions=($(echo ${stable_xcode_versions[@]} | tr " " "\n" | cut -d '.' -f 1 | uniq)) - for MAJOR_VERSION in "${major_versions[@]}" - do - LATEST_STABLE_VERSION=$(echo "${stable_xcode_versions[*]}" | grep "${MAJOR_VERSION}" | tail -n 1) - LATEST_STABLE_VERSION=$(echo $LATEST_STABLE_VERSION | cut -d"_" -f 1) - echo "export XCODE_${MAJOR_VERSION}_DEVELOPER_DIR=/Applications/Xcode_${LATEST_STABLE_VERSION}.app/Contents/Developer" >> "$HOME/.bashrc" - done -} - -extractXcodeXip() { - local WORKING_DIR="$1" - local XCODE_XIP=$(find "$WORKING_DIR" -name "Xcode_*.xip" | head -n1) - - pushd $WORKING_DIR - xip -x "${XCODE_XIP}" - popd - - if [[ -d "${WORKING_DIR}/Xcode-beta.app" ]]; then - mv -f "${WORKING_DIR}/Xcode-beta.app" "${WORKING_DIR}/Xcode.app" - fi - - if [[ ! -d "${WORKING_DIR}/Xcode.app" ]]; then - echo "'Xcode.app' doesn't exist after Xcode XIP extraction" - exit 1 - fi -} - -createXcodeSymlinks() { - local SOURCE_XCODE=$1 && shift - local SYMLINKS=($@) - - - for TARGET_XCODE in "${SYMLINKS[@]}" - do - echo "Creating symlink '/Applications/Xcode_${SOURCE_XCODE}.app' -> '/Applications/Xcode_${TARGET_XCODE}.app'" - ln -sf "/Applications/Xcode_${SOURCE_XCODE}.app" "/Applications/Xcode_${TARGET_XCODE}.app" - done - - # TO-DO, symlink is not correct - local FULL_XCODE_VERSION=$(echo "${XCODE_VERSION}.0.0" | cut -d'.' -f 1,2,3) - if [ $FULL_XCODE_VERSION != $SOURCE_XCODE ]; then - echo "Creating symlink '/Applications/Xcode_${SOURCE_XCODE}.app' -> '/Applications/Xcode_${FULL_XCODE_VERSION}.app'" - ln -sf "/Applications/Xcode_${SOURCE_XCODE}.app" "/Applications/Xcode_${FULL_XCODE_VERSION}.app" - fi -} \ No newline at end of file diff --git a/images/macos/software-report/SoftwareReport.Xcode.psm1 b/images/macos/software-report/SoftwareReport.Xcode.psm1 index 3d4cfa52..8fb84193 100644 --- a/images/macos/software-report/SoftwareReport.Xcode.psm1 +++ b/images/macos/software-report/SoftwareReport.Xcode.psm1 @@ -1,4 +1,5 @@ Import-Module "$PSScriptRoot/../helpers/Common.Helpers.psm1" +Import-Module "$PSScriptRoot/../helpers/Xcode.Helpers.psm1" $os = Get-OSVersion @@ -7,19 +8,16 @@ function Get-XcodePaths { return $xcodePaths | Select-Object -ExpandProperty Fullname } -function Get-XcodeVersionInfo { - [string]$output = Invoke-Expression "xcodebuild -version" - $versionOutputParts = $output.Split(" ") - return @{ - Version = [System.Version]::Parse($versionOutputParts[1]) - Build = $versionOutputParts[4] - } -} - function Get-XcodeSDKList { - $versionInfo = Get-XcodeVersionInfo + param( + [Parameter(Mandatory)] + [string]$XcodeRootPath + ) + + $versionInfo = Get-XcodeVersionInfo -XcodeRootPath $XcodeRootPath + $xcodebuildPath = Get-XcodeToolPath -XcodeRootPath $XcodeRootPath -ToolName "xcodebuild" if ($versionInfo.Version -le [System.Version]::Parse("9.4.1")) { - $output = Invoke-Expression "xcodebuild -showsdks" + $output = Invoke-Expression "$xcodebuildPath -showsdks" $sdkList = $output | Where-Object { $_ -Match "-sdk" } return $sdkList | ForEach-Object { @@ -31,7 +29,7 @@ function Get-XcodeSDKList { } } - [string]$output = Invoke-Expression "xcodebuild -showsdks -json" + [string]$output = Invoke-Expression "$xcodebuildPath -showsdks -json" return $output | ConvertFrom-Json } @@ -43,7 +41,7 @@ function Get-XcodeInfoList { $xcodeRootPath = $_ Switch-Xcode -XcodeRootPath $xcodeRootPath - $versionInfo = Get-XcodeVersionInfo + $versionInfo = Get-XcodeVersionInfo -XcodeRootPath $xcodeRootPath $versionInfo.Path = $xcodeRootPath $versionInfo.IsDefault = ($xcodeRootPath -eq $defaultXcodeRootPath) $versionInfo.IsStable = Test-XcodeStableRelease -XcodeRootPath $xcodeRootPath diff --git a/images/macos/templates/macOS-10.15.json b/images/macos/templates/macOS-10.15.json index a65bd72a..b7752e12 100644 --- a/images/macos/templates/macOS-10.15.json +++ b/images/macos/templates/macOS-10.15.json @@ -131,21 +131,17 @@ "scripts": [ "./provision/core/xcode-clt.sh", "./provision/core/homebrew.sh", - "./provision/core/dotnet.sh", - "./provision/core/python.sh", "./provision/core/azcopy.sh", "./provision/core/openssl.sh", "./provision/core/ruby.sh", "./provision/core/rubygem.sh", - "./provision/core/powershell.sh", - "./provision/core/git.sh", - "./provision/core/node.sh" + "./provision/core/powershell.sh" ] }, { "type": "shell", - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", - "script": "./provision/core/xcode-tools.sh", + "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}", + "script": "./provision/core/xcode.ps1", "environment_vars": [ "XCODE_INSTALL_USER={{user `xcode_install_user`}}", "XCODE_INSTALL_PASSWORD={{user `xcode_install_password`}}" diff --git a/images/macos/toolsets/toolset-10.15.json b/images/macos/toolsets/toolset-10.15.json index 94568cd0..21b09828 100644 --- a/images/macos/toolsets/toolset-10.15.json +++ b/images/macos/toolsets/toolset-10.15.json @@ -2,18 +2,18 @@ "xcode": { "default": "12", "versions": [ - { "localVersion": "12.2", "version": "12.2_beta" }, - { "localVersion": "12.1", "version": "12.1_GM_seed" }, - { "localVersion": "12.0", "version": "12.0.1", "symlinks": ["12"] }, - { "localVersion": "11.7", "version": "11.7", "symlinks": ["11.7_beta"] }, - { "localVersion": "11.6", "version": "11.6", "symlinks": ["11.6_beta"] }, - { "localVersion": "11.5", "version": "11.5", "symlinks": ["11.5_beta"] }, - { "localVersion": "11.4", "version": "11.4.1", "symlinks": ["11.4_beta"] }, - { "localVersion": "11.3", "version": "11.3.1", "symlinks": ["11.3", "11.3_beta"] }, - { "localVersion": "11.2", "version": "11.2.1", "symlinks": ["11.2", "11.2_beta"] }, - { "localVersion": "11.1", "version": "11.1", "symlinks": ["11.1_beta"] }, - { "localVersion": "11.0", "version": "11", "symlinks": ["11"] }, - { "localVersion": "10.3", "version": "10.3", "symlinks": ["10.3_beta"] } + { "link": "12.2", "version": "12.2 beta 3" }, + { "link": "12.1", "version": "12.1.1 Release Candidate" }, + { "link": "12", "version": "12.0.1" }, + { "link": "11.7", "version": "11.7", "symlinks": ["11.7_beta"] }, + { "link": "11.6", "version": "11.6", "symlinks": ["11.6_beta"] }, + { "link": "11.5", "version": "11.5", "symlinks": ["11.5_beta"] }, + { "link": "11.4.1", "version": "11.4.1", "symlinks": ["11.4", "11.4_beta"] }, + { "link": "11.3.1", "version": "11.3.1", "symlinks": ["11.3", "11.3_beta"] }, + { "link": "11.2.1", "version": "11.2.1", "symlinks": ["11.2", "11.2_beta"] }, + { "link": "11.1", "version": "11.1", "symlinks": ["11.1_beta"] }, + { "link": "11", "version": "11" }, + { "link": "10.3", "version": "10.3", "symlinks": ["10.3_beta"] } ] }, "xamarin": { From 85b8007337b59121cd17bad037e9414c9a4a19ba Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Sun, 1 Nov 2020 11:13:45 +0300 Subject: [PATCH 04/26] fix tests --- images/macos/helpers/Xcode.Installer.psm1 | 49 +++++++++--- images/macos/provision/core/xcode.ps1 | 22 +++--- images/macos/tests/Xcode.Tests.ps1 | 90 +++++++++++------------ 3 files changed, 92 insertions(+), 69 deletions(-) diff --git a/images/macos/helpers/Xcode.Installer.psm1 b/images/macos/helpers/Xcode.Installer.psm1 index 619d167e..e076f5e0 100644 --- a/images/macos/helpers/Xcode.Installer.psm1 +++ b/images/macos/helpers/Xcode.Installer.psm1 @@ -5,17 +5,14 @@ function Install-XcodeVersion { [Parameter(Mandatory)] [string]$Version, [Parameter(Mandatory)] - [string]$LocalLink + [string]$LinkTo ) $xcodeDownloadDirectory = "$env:HOME/Library/Caches/XcodeInstall" - $xcodeTargetPath = Get-XcodeRootPath -Version $LocalLink - Push-Location $xcodeDownloadDirectory + $xcodeTargetPath = Get-XcodeRootPath -Version $LinkTo Invoke-DownloadXcodeArchive -Version $Version Expand-XcodeXipArchive -DownloadDirectory $xcodeDownloadDirectory -TargetPath $xcodeTargetPath - Confirm-XcodeIntegrity -XcodeRootPath $xcodeTargetPath - Approve-XcodeLicense -XcodeRootPath $xcodeTargetPath Get-ChildItem $xcodeDownloadDirectory | Remove-Item -Force } @@ -33,6 +30,7 @@ function Invoke-DownloadXcodeArchive { # TO-DO: Consider replacing of xcversion with own implementation Write-Host "Downloading Xcode $resolvedVersion" + # TO-DO: handle exit code xcversion install "$resolvedVersion" --no-install } @@ -58,12 +56,13 @@ function Expand-XcodeXipArchive { Write-Host "Extracting Xcode from '$xcodeXipPath'" Push-Location $DownloadDirectory + # TO-DO: handle exit code xip -x $xcodeXipPath Pop-Location if (Test-Path "$DownloadDirectory/Xcode-beta.app") { Write-Host "Renaming Xcode-beta.app to Xcode.app" - Rename-File -Path "$DownloadDirectory/Xcode-beta.app" -NewName "Xcode.app" + Rename-Item -Path "$DownloadDirectory/Xcode-beta.app" -NewName "Xcode.app" } if (-not (Test-Path "$DownloadDirectory/Xcode.app")) { @@ -77,10 +76,12 @@ function Expand-XcodeXipArchive { function Confirm-XcodeIntegrity { param( [Parameter(Mandatory)] - [string]$XcodeRootPath + [string]$Version ) + $XcodeRootPath = Get-XcodeRootPath -Version $Version if (Test-XcodeStableRelease -XcodeRootPath $XcodeRootPath) { + # TO-DO: handle exit code spctl --assess --raw $XcodeRootPath } } @@ -88,10 +89,11 @@ function Confirm-XcodeIntegrity { function Approve-XcodeLicense { param( [Parameter(Mandatory)] - $XcodeRootPath + [string]$Version ) - $xcodeBuildPath = Get-XcodeToolPath -XcodeRootPath $XcodeRootPath -ToolName "xcodebuild" + $xcodeBuildPath = Get-XcodeToolPath -Version $Version -ToolName "xcodebuild" + # TO-DO: handle exit code sudo $xcodeBuildPath -license accept } @@ -103,8 +105,9 @@ function Install-XcodeAdditionalPackages { Write-Host "Installing additional packages for Xcode $Version..." $xcodeRootPath = Get-XcodeRootPath -Version $Version - $packages = Get-ChildItem -Path "$xcodeRootPath/Contents/Resources/Packages" -Filter "*.pkg" -Name -File - $packages | ForEach-Object { & sudo installer -pkg $_ -target / -allowUntrusted } + $packages = Get-ChildItem -Path "$xcodeRootPath/Contents/Resources/Packages" -Filter "*.pkg" -File + # TO-DO: handle exit code + $packages | ForEach-Object { & sudo installer -pkg $_.FullName -target / -allowUntrusted } } function Invoke-XcodeRunFirstLaunch { @@ -119,6 +122,7 @@ function Invoke-XcodeRunFirstLaunch { Write-Host "Running 'runFirstLaunch' for Xcode $Version..." $xcodeRootPath = Get-XcodeToolPath -Version $Version -ToolName "xcodebuild" + # TO-DO: handle exit code & sudo $xcodeRootPath -runFirstLaunch } @@ -156,5 +160,26 @@ function Build-ProvisionatorSymlink { } function Set-XcodeDeveloperDirEnvironmentVariables { - # TO-DO + param( + [Parameter(Mandatory)] + [string[]]$XcodeList + ) + + $exactVersionsList = $XcodeList | Where-Object { Test-XcodeStableRelease -Version $_ } | ForEach-Object { + $xcodeRootPath = Get-XcodeRootPath -Version $_ + $xcodeVersionInfo = Get-XcodeVersionInfo -XcodeRootPath $xcodeRootPath + return @{ + RootPath = $xcodeRootPath + Version = [SemVer]::Parse($xcodeVersionInfo.Version) + } + } | Sort-Object -Property Version -Descending + + $majorVersions = $exactVersionsList.Version.Major | Select-Object -Unique + $majorVersions | ForEach-Object { + $latestXcodeVersion = $exactVersionsList | Where-Object { $_.Version.Major -eq $_ } | Select-Object -First 1 + $variableName = "XCODE_${_}_DEVELOPER_DIR" + $variableValue = "$($latestXcodeVersion.RootPath)/Contents/Developer" + Write-Host "Set ${variableName}=${variableValue}" + "export ${variableName}=${variableValue}" | Out-File "$env:HOME/.bashrc" -Append + } } \ No newline at end of file diff --git a/images/macos/provision/core/xcode.ps1 b/images/macos/provision/core/xcode.ps1 index f3ea5564..58f100a3 100644 --- a/images/macos/provision/core/xcode.ps1 +++ b/images/macos/provision/core/xcode.ps1 @@ -14,25 +14,29 @@ $os = Get-OSVersion $xcodeVersions = Get-ToolsetValue "xcode.versions" $defaultXcode = Get-ToolsetValue "xcode.default" -& xcversion update - Write-Host "Installing Xcode versions..." -foreach ($xcode in $xcodeVersions) { - Install-XcodeVersion -Version $xcode.version -LocalLink $xcode.localLink - Build-XcodeSymlinks -Version $xcode.localLink -Symlinks $xcode.symlinks - Build-ProvisionatorSymlink -Version $xcode.version +$xcodeVersions | ForEach-Object { + Install-XcodeVersion -Version $_.version -LinkTo $_.link + Confirm-XcodeIntegrity -Version $_.link + Approve-XcodeLicense -Version $_.link } Write-Host "Configuring Xcode versions..." if ($os.IsLessThanCatalina) { - Install-XcodeAdditionalPackages -Version $xcodeVersions[0].localLink + Install-XcodeAdditionalPackages -Version $xcodeVersions[0].link } -$xcodeVersions | ForEach-Object { Invoke-XcodeRunFirstLaunch -Version $_.localLink } +$xcodeVersions | ForEach-Object { Invoke-XcodeRunFirstLaunch -Version $_.link } Invoke-XcodeRunFirstLaunch -Version $defaultXcode +Write-Host "Configuring Xcode symlinks..." +$xcodeVersions | ForEach-Object { + Build-XcodeSymlinks -Version $_.link -Symlinks $_.symlinks + Build-ProvisionatorSymlink -Version $_.link +} + Write-Host "Setting default Xcode to $defaultXcode" Switch-Xcode -Version $defaultXcode New-Item -Path "/Applications/Xcode.app" -ItemType SymbolicLink -Value (Get-XcodeRootPath -Version $defaultXcode) Write-Host "Setting environment variables 'XCODE__DEVELOPER_DIR'" -Set-XcodeDeveloperDirEnvironmentVariables \ No newline at end of file +Set-XcodeDeveloperDirEnvironmentVariables -XcodeList $xcodeVersions.link \ No newline at end of file diff --git a/images/macos/tests/Xcode.Tests.ps1 b/images/macos/tests/Xcode.Tests.ps1 index fd12db68..af7ac81f 100644 --- a/images/macos/tests/Xcode.Tests.ps1 +++ b/images/macos/tests/Xcode.Tests.ps1 @@ -2,39 +2,39 @@ Import-Module "$PSScriptRoot/../helpers/Common.Helpers.psm1" Import-Module "$PSScriptRoot/../helpers/Xcode.Helpers.psm1" Import-Module "$PSScriptRoot/../helpers/Tests.Helpers.psm1" -$XCODE_VERSIONS = Get-ToolsetValue "xcode.versions" -$DEFAULT_XCODE = Get-ToolsetValue "xcode.default" -$LATEST_XCODE_VERSION = $XCODE_VERSIONS | Select-Object -First 1 -$OS = Get-OSVersion +$xcodeVersions = Get-ToolsetValue "xcode.versions" +$defaultXcode = Get-ToolsetValue "xcode.default" +$latestXcodeVersion = $xcodeVersions | Select-Object -First 1 +$os = Get-OSVersion Describe "Xcode" { - It "Default Xcode is $DEFAULT_XCODE" { + $defaultXcodeTestCase = @{ DefaultXcode = $defaultXcode } + It "Default Xcode is " -TestCases $defaultXcodeTestCase { "xcodebuild -version" | Should -ReturnZeroExitCode - (Get-CommandResult "xcodebuild -version").Output | Should -BeLike "Xcode $DEFAULT_XCODE*" + (Get-CommandResult "xcodebuild -version").Output | Should -BeLike "Xcode ${DefaultXcode}.*" } - It "Xcode.app points to default Xcode" { - + It "Xcode.app points to default Xcode" -TestCases $defaultXcodeTestCase { + $xcodeApp = "/Applications/Xcode.app" + $expectedTarget = Get-XcodeRootPath -Version $DefaultXcode + $xcodeApp | Should -Exist + $expectedTarget | Should -Exist + (Get-Item $xcodeApp).Target | Should -Be $expectedTarget } - # Cut "_beta" postfix for test cases - $testCases = $XCODE_VERSIONS | ForEach-Object { @{XcodeVersion = $_.Split("_")[0] } } + $testCases = $xcodeVersions | ForEach-Object { @{ XcodeVersion = $_.link; LatestXcodeVersion = $xcodeVersions[0].link; Symlinks = $_.symlinks } } It "" -TestCases $testCases { - param ( [string] $XcodeVersion ) - $xcodebuildPath = Get-XcodeToolPath -Version $XcodeVersion -ToolName "xcodebuild" "$xcodebuildPath -version" | Should -ReturnZeroExitCode } It "Xcode tools are installed" -TestCases $testCases -Skip:($os.IsHighSierra) { - param ( [string] $XcodeVersion ) - $TOOLS_NOT_INSTALLED_EXIT_CODE = 69 $xcodebuildPath = Get-XcodeToolPath -Version $XcodeVersion -ToolName "xcodebuild" $result = Get-CommandResult "$xcodebuildPath -checkFirstLaunchStatus" - if ($XcodeVersion -ne $LATEST_XCODE_VERSION) { + if ($XcodeVersion -ne $LatestXcodeVersion) { $result.ExitCode | Should -Not -Be $TOOLS_NOT_INSTALLED_EXIT_CODE } else { $result.ExitCode | Should -BeIn (0, $TOOLS_NOT_INSTALLED_EXIT_CODE) @@ -42,13 +42,12 @@ Describe "Xcode" { } It "Xcode has correct beta symlink" -TestCases $testCases { - param ( [string] $XcodeVersion ) - - $xcodesWithBetaSymlink = @("12", "9.3", "9.4") - $shouldBetaSymlinkExists = $XcodeVersion.StartsWith("10") -or $XcodeVersion.StartsWith("11") -or ($XcodeVersion -in $xcodesWithBetaSymlink) - - $betaSymlinkPath = Get-XcodeRootPath -Version "${XcodeVersion}_beta" - Test-Path $betaSymlinkPath | Should -Be $shouldBetaSymlinkExists + $sourcePath = Get-XcodeRootPath -Version $XcodeVersion + $Symlinks | ForEach-Object { + $targetPath = Get-XcodeRootPath -Version $_ + $targetPath | Should -Exist + (Get-Item $targetPath).Target | Should -Be $sourcePath + } } It "/Applications/Xcode* symlinks are valid" { @@ -58,37 +57,32 @@ Describe "Xcode" { $_ | Should -Exist } } +} - Context "XCODE_DEVELOPER_DIR" { - $stableXcodeVersions = $XCODE_VERSIONS | ForEach-Object { $_.Split("_")[0] } | Where-Object { Test-XcodeStableRelease -Version $_ } - $majorXcodeVersions = $stableXcodeVersions | ForEach-Object { $_.Split(".")[0] } | Select-Object -Unique - $testCases = $majorXcodeVersions | ForEach-Object { - $majorXcodeVersion = $_ - $expectedVersion = $stableXcodeVersions | Where-Object { $_.StartsWith("$majorXcodeVersion") } | Select-Object -First 1 - return @{ - MajorXcodeVersion = $majorXcodeVersion - ExpectedVersion = $expectedVersion - } +Describe "XCODE_DEVELOPER_DIR variables" { + $exactVersionsList = $xcodeVersions.link | Where-Object { Test-XcodeStableRelease -Version $_ } | ForEach-Object { + $xcodeRootPath = Get-XcodeRootPath -Version $_ + $xcodeVersionInfo = Get-XcodeVersionInfo -XcodeRootPath $xcodeRootPath + return @{ + RootPath = $xcodeRootPath + Version = [SemVer]::Parse($xcodeVersionInfo.Version) } + } | Sort-Object -Property Version -Descending + $majorVersions = $exactVersionsList.Version.Major | Select-Object -Unique + $testCases = $majorVersions | ForEach-Object { @{ MajorVersion = $_; VersionsList = $exactVersionsList } } - It "XCODE__DEVELOPER_DIR" -TestCases $testCases { - param ( - [string] $MajorXcodeVersion, - [string] $ExpectedVersion - ) - - $variableName = "XCODE_${MajorXcodeVersion}_DEVELOPER_DIR" - $actualPath = Get-EnvironmentVariable $variableName - $expectedPath = Join-Path (Get-XcodeRootPath -Version $ExpectedVersion) "Contents/Developer" - - $actualPath | Should -Exist - $actualPath | Should -Be $expectedPath - } + It "XCODE__DEVELOPER_DIR" -TestCases $testCases { + $variableName = "XCODE_${MajorVersion}_DEVELOPER_DIR" + $actualPath = Get-EnvironmentVariable $variableName + $expectedVersion = $VersionsList | Where-Object { $_.Version.Major -eq $MajorVersion } | Select-Object -First 1 + $expectedPath = "$($expectedVersion.RootPath)/Contents/Developer" + $actualPath | Should -Exist + $actualPath | Should -Be $expectedPath } } Describe "Xcode simulators" { - $XCODE_VERSIONS | Where-Object { Test-XcodeStableRelease -Version $_ } | ForEach-Object { + $xcodeVersions | Where-Object { Test-XcodeStableRelease -Version $_ } | ForEach-Object { Switch-Xcode -Version $_ Context "$_" { @@ -105,7 +99,7 @@ Describe "Xcode simulators" { } AfterAll { - $DEFAULT_XCODE = Get-ToolsetValue "xcode.default" - Switch-Xcode -Version $DEFAULT_XCODE + $defaultXcode = Get-ToolsetValue "xcode.default" + Switch-Xcode -Version $defaultXcode } } \ No newline at end of file From 6ac87c213d0dc686dfcfb1e7555cf6cc5c2a1be3 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Sun, 1 Nov 2020 15:55:02 +0300 Subject: [PATCH 05/26] Update xcode.ps1 --- images/macos/provision/core/xcode.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/images/macos/provision/core/xcode.ps1 b/images/macos/provision/core/xcode.ps1 index 58f100a3..38287aa6 100644 --- a/images/macos/provision/core/xcode.ps1 +++ b/images/macos/provision/core/xcode.ps1 @@ -3,8 +3,8 @@ $ErrorActionPreference = "Stop" -Import-Module "$PSScriptRoot/../../helpers/Common.Helpers.psm1" -Import-Module "$PSScriptRoot/../../helpers/Xcode.Installer.psm1" +Import-Module "$env:HOME/image-generation/helpers/Common.Helpers.psm1" +Import-Module "$env:HOME/image-generation/helpers/Xcode.Installer.psm1" if ([string]::IsNullOrEmpty($env:XCODE_INSTALL_USER) -or [string]::IsNullOrEmpty($env:XCODE_INSTALL_PASSWORD)) { throw "Required environment variables XCODE_INSTALL_USER and XCODE_INSTALL_PASSWORD are not set" From cfaa7acb549bacf46977081f020016d61bb79f2c Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Mon, 2 Nov 2020 08:41:40 +0300 Subject: [PATCH 06/26] fix symlinks --- images/macos/helpers/Xcode.Installer.psm1 | 1 - images/macos/provision/core/xcode.ps1 | 2 ++ images/macos/toolsets/toolset-10.15.json | 6 ------ 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/images/macos/helpers/Xcode.Installer.psm1 b/images/macos/helpers/Xcode.Installer.psm1 index e076f5e0..c7213861 100644 --- a/images/macos/helpers/Xcode.Installer.psm1 +++ b/images/macos/helpers/Xcode.Installer.psm1 @@ -130,7 +130,6 @@ function Build-XcodeSymlinks { param( [Parameter(Mandatory)] [string]$Version, - [Parameter(Mandatory)] [string[]]$Symlinks ) diff --git a/images/macos/provision/core/xcode.ps1 b/images/macos/provision/core/xcode.ps1 index 38287aa6..858280df 100644 --- a/images/macos/provision/core/xcode.ps1 +++ b/images/macos/provision/core/xcode.ps1 @@ -1,6 +1,8 @@ # The script currently requires 2 external variables to be set: XCODE_INSTALL_USER # and XCODE_INSTALL_PASSWORD, in order to access the Apple Developer Center +Write-Host "Script begin" + $ErrorActionPreference = "Stop" Import-Module "$env:HOME/image-generation/helpers/Common.Helpers.psm1" diff --git a/images/macos/toolsets/toolset-10.15.json b/images/macos/toolsets/toolset-10.15.json index c2bdbd2c..b1b0215e 100644 --- a/images/macos/toolsets/toolset-10.15.json +++ b/images/macos/toolsets/toolset-10.15.json @@ -6,13 +6,7 @@ { "link": "12.1", "version": "12.1.1 Release Candidate" }, { "link": "12", "version": "12.0.1" }, { "link": "11.7", "version": "11.7", "symlinks": ["11.7_beta"] }, - { "link": "11.6", "version": "11.6", "symlinks": ["11.6_beta"] }, - { "link": "11.5", "version": "11.5", "symlinks": ["11.5_beta"] }, { "link": "11.4.1", "version": "11.4.1", "symlinks": ["11.4", "11.4_beta"] }, - { "link": "11.3.1", "version": "11.3.1", "symlinks": ["11.3", "11.3_beta"] }, - { "link": "11.2.1", "version": "11.2.1", "symlinks": ["11.2", "11.2_beta"] }, - { "link": "11.1", "version": "11.1", "symlinks": ["11.1_beta"] }, - { "link": "11", "version": "11" }, { "link": "10.3", "version": "10.3", "symlinks": ["10.3_beta"] } ] }, From 3feabfdb52c643b6a26935eca9062563b67c7292 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Mon, 2 Nov 2020 11:19:30 +0300 Subject: [PATCH 07/26] fix todos --- images/macos/helpers/Common.Helpers.psm1 | 13 ++++++ images/macos/helpers/Xcode.Installer.psm1 | 56 +++++++++++++++++------ 2 files changed, 54 insertions(+), 15 deletions(-) diff --git a/images/macos/helpers/Common.Helpers.psm1 b/images/macos/helpers/Common.Helpers.psm1 index dd8a2184..174ea050 100644 --- a/images/macos/helpers/Common.Helpers.psm1 +++ b/images/macos/helpers/Common.Helpers.psm1 @@ -83,3 +83,16 @@ function Invoke-RestMethodWithRetry { ) Invoke-RestMethod $Url -MaximumRetryCount 10 -RetryIntervalSec 30 } + +function Invoke-ExpressionWithValidation { + param( + [Parameter(Mandatory)] + [string]$Command + ) + + $output = Invoke-Expression -Command $Command + if ($LASTEXITCODE -ne 0) { + throw "Command '$Command' has finished with exit code $LASTEXITCODE" + } + return $output +} \ No newline at end of file diff --git a/images/macos/helpers/Xcode.Installer.psm1 b/images/macos/helpers/Xcode.Installer.psm1 index c7213861..0f0af1ae 100644 --- a/images/macos/helpers/Xcode.Installer.psm1 +++ b/images/macos/helpers/Xcode.Installer.psm1 @@ -30,8 +30,7 @@ function Invoke-DownloadXcodeArchive { # TO-DO: Consider replacing of xcversion with own implementation Write-Host "Downloading Xcode $resolvedVersion" - # TO-DO: handle exit code - xcversion install "$resolvedVersion" --no-install + Invoke-ExpressionWithValidation "xcversion install '$resolvedVersion' --no-install" } function Resolve-ExactXcodeVersion { @@ -40,8 +39,38 @@ function Resolve-ExactXcodeVersion { [string]$Version ) - # TO-DO - return $Version + # if toolset string contains spaces, consider it as a full name of Xcode + if ($Version -match "\s") { + return $Version + } + + $semverVersion = [SemVer]::Parse($Version) + $availableVersions = Get-AvailableXcodeVersions + $satisfiedVersions = $availableVersions | Where-Object { $semverVersion -eq $_.stableSemver } + return $satisfiedVersions | Select-Object -Last 1 -ExpandProperty rawVersion +} + +function Get-AvailableXcodeVersions { + $rawVersionsList = & xcversion list | ForEach-Object { $_.Trim() } | Where-Object { $_ -match "^\d" } + $availableVersions = $rawVersionsList | ForEach-Object { + $parts = $_.Split(" ", 2) + $stableSemver = [SemVer]::Parse($parts[0]) + if ($parts.Count -eq 1) { + $semver = $stableSemver + } else { + # Convert 'beta 3' -> 'beta.3', 'Release Candidate' -> 'releasecandidate', 'GM Seed 2' -> 'gmseed.2' + $normalizedLabel = $parts[1].toLower() -replace " (\d)", '.$1' -replace " ([a-z])", '$1' + $semver = [SemVer]::new($stableSemver.Major, $stableSemver.Minor, $stableSemver.Patch, $normalizedLabel) + } + + return [PSCustomObject]@{ + semver = $semver + rawVersion = $_ + stableSemver = $stableSemver + } + } + + return $availableVersions | Sort-Object -Property semver } function Expand-XcodeXipArchive { @@ -56,8 +85,7 @@ function Expand-XcodeXipArchive { Write-Host "Extracting Xcode from '$xcodeXipPath'" Push-Location $DownloadDirectory - # TO-DO: handle exit code - xip -x $xcodeXipPath + Invoke-ExpressionWithValidation "xip -x $xcodeXipPath" Pop-Location if (Test-Path "$DownloadDirectory/Xcode-beta.app") { @@ -81,8 +109,7 @@ function Confirm-XcodeIntegrity { $XcodeRootPath = Get-XcodeRootPath -Version $Version if (Test-XcodeStableRelease -XcodeRootPath $XcodeRootPath) { - # TO-DO: handle exit code - spctl --assess --raw $XcodeRootPath + Invoke-ExpressionWithValidation "spctl --assess --raw $XcodeRootPath" } } @@ -93,8 +120,7 @@ function Approve-XcodeLicense { ) $xcodeBuildPath = Get-XcodeToolPath -Version $Version -ToolName "xcodebuild" - # TO-DO: handle exit code - sudo $xcodeBuildPath -license accept + Invoke-ExpressionWithValidation "sudo $xcodeBuildPath -license accept" } function Install-XcodeAdditionalPackages { @@ -106,8 +132,9 @@ function Install-XcodeAdditionalPackages { Write-Host "Installing additional packages for Xcode $Version..." $xcodeRootPath = Get-XcodeRootPath -Version $Version $packages = Get-ChildItem -Path "$xcodeRootPath/Contents/Resources/Packages" -Filter "*.pkg" -File - # TO-DO: handle exit code - $packages | ForEach-Object { & sudo installer -pkg $_.FullName -target / -allowUntrusted } + $packages | ForEach-Object { + Invoke-ExpressionWithValidation "sudo installer -pkg $($_.FullName) -target / -allowUntrusted" + } } function Invoke-XcodeRunFirstLaunch { @@ -122,8 +149,7 @@ function Invoke-XcodeRunFirstLaunch { Write-Host "Running 'runFirstLaunch' for Xcode $Version..." $xcodeRootPath = Get-XcodeToolPath -Version $Version -ToolName "xcodebuild" - # TO-DO: handle exit code - & sudo $xcodeRootPath -runFirstLaunch + Invoke-ExpressionWithValidation "sudo $xcodeRootPath -runFirstLaunch" } function Build-XcodeSymlinks { @@ -134,7 +160,7 @@ function Build-XcodeSymlinks { ) $sourcePath = Get-XcodeRootPath -Version $Version - $Symlinks | ForEach-Object { + $Symlinks | Where-Object { $_ } | ForEach-Object { $targetPath = Get-XcodeRootPath -Version $_ Write-Host "Creating symlink: '$targetPath' -> '$sourcePath'" New-Item -Path $targetPath -ItemType SymbolicLink -Value $sourcePath From 74483e93da0d3ded7283787b2531bb8ff50ff920 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Mon, 2 Nov 2020 18:03:20 +0300 Subject: [PATCH 08/26] fix typos --- images/macos/helpers/Xcode.Installer.psm1 | 7 ++++--- images/macos/provision/core/xamarin.sh | 2 +- images/macos/provision/core/xcode-postbuild.sh | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/images/macos/helpers/Xcode.Installer.psm1 b/images/macos/helpers/Xcode.Installer.psm1 index 0f0af1ae..cdc35273 100644 --- a/images/macos/helpers/Xcode.Installer.psm1 +++ b/images/macos/helpers/Xcode.Installer.psm1 @@ -163,7 +163,7 @@ function Build-XcodeSymlinks { $Symlinks | Where-Object { $_ } | ForEach-Object { $targetPath = Get-XcodeRootPath -Version $_ Write-Host "Creating symlink: '$targetPath' -> '$sourcePath'" - New-Item -Path $targetPath -ItemType SymbolicLink -Value $sourcePath + New-Item -Path $targetPath -ItemType SymbolicLink -Value $sourcePath | Out-Null } } @@ -180,7 +180,7 @@ function Build-ProvisionatorSymlink { $targetPath = Get-XcodeRootPath -Version $targetVersion if ($sourcePath -ne $targetPath) { Write-Host "Creating provisionator symlink: '$targetPath' -> '$sourcePath'" - New-Item -Path $targetPath -ItemType SymbolicLink -Value $sourcePath + New-Item -Path $targetPath -ItemType SymbolicLink -Value $sourcePath | Out-Null } } @@ -201,7 +201,8 @@ function Set-XcodeDeveloperDirEnvironmentVariables { $majorVersions = $exactVersionsList.Version.Major | Select-Object -Unique $majorVersions | ForEach-Object { - $latestXcodeVersion = $exactVersionsList | Where-Object { $_.Version.Major -eq $_ } | Select-Object -First 1 + $majorVersion = $_ + $latestXcodeVersion = $exactVersionsList | Where-Object { $_.Version.Major -eq $majorVersion } | Select-Object -First 1 $variableName = "XCODE_${_}_DEVELOPER_DIR" $variableValue = "$($latestXcodeVersion.RootPath)/Contents/Developer" Write-Host "Set ${variableName}=${variableValue}" diff --git a/images/macos/provision/core/xamarin.sh b/images/macos/provision/core/xamarin.sh index 18eef321..387e3f45 100755 --- a/images/macos/provision/core/xamarin.sh +++ b/images/macos/provision/core/xamarin.sh @@ -9,7 +9,7 @@ XAMARIN_MAC_VERSIONS=($(get_toolset_value '.xamarin."mac-versions" | reverse | . XAMARIN_ANDROID_VERSIONS=($(get_toolset_value '.xamarin."android-versions" | reverse | .[]')) LATEST_SDK_SYMLINK=$(get_toolset_value '.xamarin.bundles[0].symlink') CURRENT_SDK_SYMLINK=$(get_toolset_value '.xamarin."bundle-default"') -DEFAULT_XCODE_VERSION=$(get_default_xcode_from_toolset) +DEFAULT_XCODE_VERSION=$(get_toolset_value '.xcode.default') if [ "$CURRENT_SDK_SYMLINK" == "latest" ]; then CURRENT_SDK_SYMLINK=$LATEST_SDK_SYMLINK diff --git a/images/macos/provision/core/xcode-postbuild.sh b/images/macos/provision/core/xcode-postbuild.sh index 6afd42c2..6b41348f 100644 --- a/images/macos/provision/core/xcode-postbuild.sh +++ b/images/macos/provision/core/xcode-postbuild.sh @@ -1,8 +1,8 @@ #!/bin/bash -e -o pipefail source ~/utils/utils.sh -XCODE_LIST=($(get_xcode_list_from_toolset)) -DEFAULT_XCODE_VERSION=$(get_default_xcode_from_toolset) +XCODE_LIST=($(get_toolset_value '.xcode.versions | reverse | .[]')) +DEFAULT_XCODE_VERSION=$(get_toolset_value '.xcode.default') # https://github.com/microsoft/appcenter/issues/847 # Assets.xcassets : error : CoreData: error: (6922) I/O error for database From 54269f76020404bad98227475180f3a79360c94b Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Mon, 2 Nov 2020 21:35:36 +0300 Subject: [PATCH 09/26] minor improvements --- images/macos/helpers/Xcode.Installer.psm1 | 2 +- images/macos/provision/core/xcode.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/images/macos/helpers/Xcode.Installer.psm1 b/images/macos/helpers/Xcode.Installer.psm1 index cdc35273..80a50eb0 100644 --- a/images/macos/helpers/Xcode.Installer.psm1 +++ b/images/macos/helpers/Xcode.Installer.psm1 @@ -179,7 +179,7 @@ function Build-ProvisionatorSymlink { $targetVersion = [SemVer]::Parse($versionInfo.Version).ToString() $targetPath = Get-XcodeRootPath -Version $targetVersion if ($sourcePath -ne $targetPath) { - Write-Host "Creating provisionator symlink: '$targetPath' -> '$sourcePath'" + Write-Host "Creating symlink: '$targetPath' -> '$sourcePath'" New-Item -Path $targetPath -ItemType SymbolicLink -Value $sourcePath | Out-Null } } diff --git a/images/macos/provision/core/xcode.ps1 b/images/macos/provision/core/xcode.ps1 index 858280df..3218a109 100644 --- a/images/macos/provision/core/xcode.ps1 +++ b/images/macos/provision/core/xcode.ps1 @@ -38,7 +38,7 @@ $xcodeVersions | ForEach-Object { Write-Host "Setting default Xcode to $defaultXcode" Switch-Xcode -Version $defaultXcode -New-Item -Path "/Applications/Xcode.app" -ItemType SymbolicLink -Value (Get-XcodeRootPath -Version $defaultXcode) +New-Item -Path "/Applications/Xcode.app" -ItemType SymbolicLink -Value (Get-XcodeRootPath -Version $defaultXcode) | Out-Null Write-Host "Setting environment variables 'XCODE__DEVELOPER_DIR'" Set-XcodeDeveloperDirEnvironmentVariables -XcodeList $xcodeVersions.link \ No newline at end of file From 8f1f707032b615eacc92420c665920c58c99eecd Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Mon, 2 Nov 2020 22:05:52 +0300 Subject: [PATCH 10/26] Update xcode-postbuild.sh --- images/macos/provision/core/xcode-postbuild.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/macos/provision/core/xcode-postbuild.sh b/images/macos/provision/core/xcode-postbuild.sh index 6b41348f..d0344726 100644 --- a/images/macos/provision/core/xcode-postbuild.sh +++ b/images/macos/provision/core/xcode-postbuild.sh @@ -1,7 +1,7 @@ #!/bin/bash -e -o pipefail source ~/utils/utils.sh -XCODE_LIST=($(get_toolset_value '.xcode.versions | reverse | .[]')) +XCODE_LIST=($(get_toolset_value '.xcode.versions | reverse | .[].link')) DEFAULT_XCODE_VERSION=$(get_toolset_value '.xcode.default') # https://github.com/microsoft/appcenter/issues/847 From 8c96dbb9bb660e512a8573514518b06976a4ba18 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Tue, 3 Nov 2020 09:13:58 +0300 Subject: [PATCH 11/26] fix tests --- .../software-report/SoftwareReport.Xcode.psm1 | 4 +- images/macos/templates/macOS-10.15.json | 6 +- images/macos/tests/Xcode.Tests.ps1 | 89 ++++++++++--------- 3 files changed, 56 insertions(+), 43 deletions(-) diff --git a/images/macos/software-report/SoftwareReport.Xcode.psm1 b/images/macos/software-report/SoftwareReport.Xcode.psm1 index 8fb84193..448e6f38 100644 --- a/images/macos/software-report/SoftwareReport.Xcode.psm1 +++ b/images/macos/software-report/SoftwareReport.Xcode.psm1 @@ -99,7 +99,7 @@ function Build-XcodeTable { } } -function Get-XcodeDevicesList { +function Build-XcodeDevicesList { param ( [Parameter(Mandatory)][object] $XcodeInfo, [Parameter(Mandatory)][object] $Runtime @@ -188,7 +188,7 @@ function Build-XcodeSimulatorsTable { $xcodeInfo.Values | ForEach-Object { $runtimeFound = $_.SimulatorsInfo.runtimes | Where-Object { $_.identifier -eq $runtime.identifier } | Select-Object -First 1 if ($runtimeFound) { - $devicesToAdd = Get-XcodeDevicesList -XcodeInfo $_ -Runtime $runtimeFound + $devicesToAdd = Build-XcodeDevicesList -XcodeInfo $_ -Runtime $runtimeFound $runtimeDevices += $devicesToAdd | Select-Object -ExpandProperty name $xcodeList += $_.VersionInfo.Version } diff --git a/images/macos/templates/macOS-10.15.json b/images/macos/templates/macOS-10.15.json index 75e0726e..c7412da1 100644 --- a/images/macos/templates/macOS-10.15.json +++ b/images/macos/templates/macOS-10.15.json @@ -136,11 +136,15 @@ "scripts": [ "./provision/core/xcode-clt.sh", "./provision/core/homebrew.sh", + "./provision/core/dotnet.sh", + "./provision/core/python.sh", "./provision/core/azcopy.sh", "./provision/core/openssl.sh", "./provision/core/ruby.sh", "./provision/core/rubygem.sh", - "./provision/core/powershell.sh" + "./provision/core/powershell.sh", + "./provision/core/git.sh", + "./provision/core/node.sh" ] }, { diff --git a/images/macos/tests/Xcode.Tests.ps1 b/images/macos/tests/Xcode.Tests.ps1 index af7ac81f..78c0ca07 100644 --- a/images/macos/tests/Xcode.Tests.ps1 +++ b/images/macos/tests/Xcode.Tests.ps1 @@ -8,45 +8,53 @@ $latestXcodeVersion = $xcodeVersions | Select-Object -First 1 $os = Get-OSVersion Describe "Xcode" { - $defaultXcodeTestCase = @{ DefaultXcode = $defaultXcode } - It "Default Xcode is " -TestCases $defaultXcodeTestCase { - "xcodebuild -version" | Should -ReturnZeroExitCode - (Get-CommandResult "xcodebuild -version").Output | Should -BeLike "Xcode ${DefaultXcode}.*" - } - - It "Xcode.app points to default Xcode" -TestCases $defaultXcodeTestCase { - $xcodeApp = "/Applications/Xcode.app" - $expectedTarget = Get-XcodeRootPath -Version $DefaultXcode - $xcodeApp | Should -Exist - $expectedTarget | Should -Exist - (Get-Item $xcodeApp).Target | Should -Be $expectedTarget - } - $testCases = $xcodeVersions | ForEach-Object { @{ XcodeVersion = $_.link; LatestXcodeVersion = $xcodeVersions[0].link; Symlinks = $_.symlinks } } - It "" -TestCases $testCases { - $xcodebuildPath = Get-XcodeToolPath -Version $XcodeVersion -ToolName "xcodebuild" - "$xcodebuildPath -version" | Should -ReturnZeroExitCode - } - - It "Xcode tools are installed" -TestCases $testCases -Skip:($os.IsHighSierra) { - $TOOLS_NOT_INSTALLED_EXIT_CODE = 69 - $xcodebuildPath = Get-XcodeToolPath -Version $XcodeVersion -ToolName "xcodebuild" - $result = Get-CommandResult "$xcodebuildPath -checkFirstLaunchStatus" - - if ($XcodeVersion -ne $LatestXcodeVersion) { - $result.ExitCode | Should -Not -Be $TOOLS_NOT_INSTALLED_EXIT_CODE - } else { - $result.ExitCode | Should -BeIn (0, $TOOLS_NOT_INSTALLED_EXIT_CODE) + Context "Versions" { + It "" -TestCases $testCases { + $xcodebuildPath = Get-XcodeToolPath -Version $XcodeVersion -ToolName "xcodebuild" + "$xcodebuildPath -version" | Should -ReturnZeroExitCode } } - It "Xcode has correct beta symlink" -TestCases $testCases { - $sourcePath = Get-XcodeRootPath -Version $XcodeVersion - $Symlinks | ForEach-Object { - $targetPath = Get-XcodeRootPath -Version $_ - $targetPath | Should -Exist - (Get-Item $targetPath).Target | Should -Be $sourcePath + Context "Default" { + $defaultXcodeTestCase = @{ DefaultXcode = $defaultXcode } + It "Default Xcode is " -TestCases $defaultXcodeTestCase { + "xcodebuild -version" | Should -ReturnZeroExitCode + (Get-CommandResult "xcodebuild -version").Output | Should -BeLike "Xcode ${DefaultXcode}.*" + } + + It "Xcode.app points to default Xcode" -TestCases $defaultXcodeTestCase { + $xcodeApp = "/Applications/Xcode.app" + $expectedTarget = Get-XcodeRootPath -Version $DefaultXcode + $xcodeApp | Should -Exist + $expectedTarget | Should -Exist + (Get-Item $xcodeApp).Target | Should -Be $expectedTarget + } + } + + Context "Additional tools" { + It "Xcode tools are installed" -TestCases $testCases -Skip:($os.IsHighSierra) { + $TOOLS_NOT_INSTALLED_EXIT_CODE = 69 + $xcodebuildPath = Get-XcodeToolPath -Version $XcodeVersion -ToolName "xcodebuild" + $result = Get-CommandResult "$xcodebuildPath -checkFirstLaunchStatus" + + if ($XcodeVersion -ne $LatestXcodeVersion) { + $result.ExitCode | Should -Not -Be $TOOLS_NOT_INSTALLED_EXIT_CODE + } else { + $result.ExitCode | Should -BeIn (0, $TOOLS_NOT_INSTALLED_EXIT_CODE) + } + } + } + + Context "Symlinks" { + It "Xcode has correct symlinks" -TestCases $testCases { + $sourcePath = Get-XcodeRootPath -Version $XcodeVersion + $Symlinks | Where-Object { $_ } | ForEach-Object { + $targetPath = Get-XcodeRootPath -Version $_ + $targetPath | Should -Exist + (Get-Item $targetPath).Target | Should -Be $sourcePath + } } } @@ -82,23 +90,24 @@ Describe "XCODE_DEVELOPER_DIR variables" { } Describe "Xcode simulators" { - $xcodeVersions | Where-Object { Test-XcodeStableRelease -Version $_ } | ForEach-Object { - Switch-Xcode -Version $_ - + $xcodeVersions.link | Where-Object { Test-XcodeStableRelease -Version $_ } | ForEach-Object { Context "$_" { - It "No duplicates in devices" { + $testCase = @{ XcodeVersion = $_ } + It "No duplicates in devices" -TestCases $testCase { + Switch-Xcode -Version $XcodeVersion [array]$devicesList = @(Get-XcodeDevicesList | Where-Object { $_ }) Validate-ArrayWithoutDuplicates $devicesList -Because "Found duplicate device simulators" } - It "No duplicates in pairs" { + It "No duplicates in pairs" -TestCases $testCase { + Switch-Xcode -Version $XcodeVersion [array]$pairsList = @(Get-XcodePairsList | Where-Object { $_ }) Validate-ArrayWithoutDuplicates $pairsList -Because "Found duplicate pairs simulators" } } } - AfterAll { + AfterEach { $defaultXcode = Get-ToolsetValue "xcode.default" Switch-Xcode -Version $defaultXcode } From 5907a2a1eea64ce95ade34b0b68243d23bd63054 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Tue, 3 Nov 2020 09:37:06 +0300 Subject: [PATCH 12/26] Update xcode-postbuild.sh --- images/macos/provision/core/xcode-postbuild.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/images/macos/provision/core/xcode-postbuild.sh b/images/macos/provision/core/xcode-postbuild.sh index d0344726..1a82545b 100644 --- a/images/macos/provision/core/xcode-postbuild.sh +++ b/images/macos/provision/core/xcode-postbuild.sh @@ -15,11 +15,6 @@ do #add sleep to let CoreSimulatorService to exit sleep 3 - # Version 12.2_beta installed into 12.2 directory and 12.1_GM_seed in 12.1 - pattern="[0-9]{1,2}.*_" - if [[ $XCODE_VERSION =~ $pattern ]] ; then - XCODE_VERSION=$(echo $XCODE_VERSION | cut -d"_" -f 1) - fi # Select xcode version by default sudo xcode-select -s "/Applications/Xcode_${XCODE_VERSION}.app/Contents/Developer" From 117cefd4b33b3ca782479aeffaa0e87450ed5b6c Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Tue, 3 Nov 2020 22:18:41 +0300 Subject: [PATCH 13/26] =?UTF-8?q?=D1=86=D1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- images/macos/software-report/SoftwareReport.Generator.ps1 | 2 +- images/macos/software-report/SoftwareReport.Xcode.psm1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/images/macos/software-report/SoftwareReport.Generator.ps1 b/images/macos/software-report/SoftwareReport.Generator.ps1 index 4eab767c..21b19ceb 100644 --- a/images/macos/software-report/SoftwareReport.Generator.ps1 +++ b/images/macos/software-report/SoftwareReport.Generator.ps1 @@ -4,7 +4,7 @@ param ( $ImageName ) -$ErrorActionPreference = "Stop" +$ErrorActionPreference = "Continue" Import-Module MarkdownPS Import-Module "$PSScriptRoot/SoftwareReport.Common.psm1" -DisableNameChecking diff --git a/images/macos/software-report/SoftwareReport.Xcode.psm1 b/images/macos/software-report/SoftwareReport.Xcode.psm1 index 448e6f38..31967d30 100644 --- a/images/macos/software-report/SoftwareReport.Xcode.psm1 +++ b/images/macos/software-report/SoftwareReport.Xcode.psm1 @@ -48,7 +48,7 @@ function Get-XcodeInfoList { $xcodeInfo.Add($xcodeRootPath, [PSCustomObject] @{ VersionInfo = $versionInfo - SDKInfo = Get-XcodeSDKList + SDKInfo = Get-XcodeSDKList -XcodeRootPath $xcodeRootPath SimulatorsInfo = Get-XcodeSimulatorsInfo }) } From 49aab970c14aa50d77145174f7433c1b9a39495d Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Tue, 3 Nov 2020 22:31:54 +0300 Subject: [PATCH 14/26] Update download-repo.ps1 --- images.CI/download-repo.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images.CI/download-repo.ps1 b/images.CI/download-repo.ps1 index 40270769..14374702 100644 --- a/images.CI/download-repo.ps1 +++ b/images.CI/download-repo.ps1 @@ -11,4 +11,4 @@ $env:GIT_REDIRECT_STDERR = '2>&1' git clone $RepoUrl . -b $RepoBranch --single-branch --depth 1 Write-Host "Latest commit:" -git log --pretty=format:"Date: %cd; Commit: %H - %s; Author: %an <%ae>" -1 \ No newline at end of file +git --no-pager log --pretty=format:"Date: %cd; Commit: %H - %s; Author: %an <%ae>" -1 \ No newline at end of file From 50f480ae16218f640ab2a12a88fe120c982eb04a Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 4 Nov 2020 10:14:19 +0300 Subject: [PATCH 15/26] update toolsets --- images/macos/toolsets/toolset-10.13.json | 14 +++++++++++++- images/macos/toolsets/toolset-10.14.json | 14 +++++++++++++- images/macos/toolsets/toolset-10.15.json | 12 ++++++++---- images/macos/toolsets/toolset-11.0.json | 3 ++- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/images/macos/toolsets/toolset-10.13.json b/images/macos/toolsets/toolset-10.13.json index e4834c8b..c828c198 100644 --- a/images/macos/toolsets/toolset-10.13.json +++ b/images/macos/toolsets/toolset-10.13.json @@ -2,7 +2,19 @@ "xcode": { "default": "10.1", "versions": [ - "10.1", "10", "9.4.1", "9.4", "9.3.1", "9.3", "9.2", "9.1", "9", "8.3.3", "8.2.1", "8.1", "8" + { "link": "10.1", "version": "10.1.0", "symlinks": [ "10.1_beta"] }, + { "link": "10", "version": "10.0.0", "symlinks": [ "10_beta"] }, + { "link": "9.4.1", "version": "9.4.1", "symlinks": [ "9.4.1_beta"] }, + { "link": "9.4", "version": "9.4.0", "symlinks": [ "9.4_beta"] }, + { "link": "9.3.1", "version": "9.3.1", "symlinks": [ "9.3.1_beta"] }, + { "link": "9.3", "version": "9.3.0", "symlinks": [ "9.3_beta"] }, + { "link": "9.2", "version": "9.2.0", "symlinks": [ "9.2_beta"] }, + { "link": "9.1", "version": "9.1.0", "symlinks": [ "9.1_beta"] }, + { "link": "9", "version": "9.0.0", "symlinks": [ "9_beta"] }, + { "link": "8.3.3", "version": "8.3.3", "symlinks": [ "8.3.3_beta"] }, + { "link": "8.2.1", "version": "8.2.1", "symlinks": [ "8.2.1_beta"] }, + { "link": "8.1", "version": "8.1.0", "symlinks": [ "8.1_beta"] }, + { "link": "8", "version": "8.0.0", "symlinks": [ "8_beta"] } ] }, "xamarin": { diff --git a/images/macos/toolsets/toolset-10.14.json b/images/macos/toolsets/toolset-10.14.json index 2d0972ca..75041b5c 100644 --- a/images/macos/toolsets/toolset-10.14.json +++ b/images/macos/toolsets/toolset-10.14.json @@ -2,7 +2,19 @@ "xcode": { "default": "11.3.1", "versions": [ - "11.3.1", "11.3", "11.2.1", "11.2", "11.1", "11", "10.3", "10.2.1", "10.2", "10.1", "10", "9.4.1" + { "link": "11.3.1", "version": "11.3.1", "symlinks": ["11.3.1_beta"] }, + { "link": "11.3", "version": "11.3.0", "symlinks": ["11.3_beta"] }, + { "link": "11.2.1", "version": "11.2.1", "symlinks": ["11.2.1_beta"] }, + { "link": "11.2", "version": "11.2.0", "symlinks": ["11.2_beta"] }, + { "link": "11.1", "version": "11.1.0", "symlinks": ["11.1_beta"] }, + { "link": "11", "version": "11.0.0", "symlinks": ["11_beta"] }, + { "link": "10.3", "version": "10.3.0", "symlinks": ["10.3_beta"] }, + { "link": "10.2.1", "version": "10.2.1", "symlinks": ["10.2.1_beta"] }, + { "link": "10.2", "version": "10.2.0", "symlinks": ["10.2_beta"] }, + { "link": "10.1", "version": "10.1.0", "symlinks": ["10.1_beta"] }, + { "link": "10.1", "version": "10.1.0", "symlinks": ["10.1_beta"] }, + { "link": "10", "version": "10.0.0", "symlinks": ["10_beta"] }, + { "link": "9.4.1", "version": "9.4.1", "symlinks": ["9.4.1_beta"] } ] }, "xamarin": { diff --git a/images/macos/toolsets/toolset-10.15.json b/images/macos/toolsets/toolset-10.15.json index 7f48b47a..39e6d5af 100644 --- a/images/macos/toolsets/toolset-10.15.json +++ b/images/macos/toolsets/toolset-10.15.json @@ -2,11 +2,15 @@ "xcode": { "default": "12", "versions": [ - { "link": "12.2", "version": "12.2 beta 3" }, - { "link": "12.1", "version": "12.1.1 Release Candidate" }, + { "link": "12.2", "version": "12.2.0" }, + { "link": "12.1", "version": "12.1.1" }, { "link": "12", "version": "12.0.1" }, - { "link": "11.7", "version": "11.7", "symlinks": ["11.7_beta"] }, - { "link": "11.4.1", "version": "11.4.1", "symlinks": ["11.4", "11.4_beta"] }, + { "link": "11.7", "version": "11.7.0", "symlinks": ["11.7_beta"] }, + { "link": "11.6", "version": "11.6.0", "symlinks": ["11.6_beta"] }, + { "link": "11.5", "version": "11.5.0", "symlinks": ["11.5_beta"] }, + { "link": "11.4.1", "version": "11.4.1", "symlinks": ["11.4", "11.4_beta", "11.4.1_beta"] }, + { "link": "11.3.1", "version": "11.3.1", "symlinks": ["11.3", "11.3_beta", "11.3.1_beta"] }, + { "link": "11.2.1", "version": "11.2.1", "symlinks": ["11.2", "11.2_beta", "11.2.1_beta"] }, { "link": "10.3", "version": "10.3", "symlinks": ["10.3_beta"] } ] }, diff --git a/images/macos/toolsets/toolset-11.0.json b/images/macos/toolsets/toolset-11.0.json index 874dec12..0409e270 100644 --- a/images/macos/toolsets/toolset-11.0.json +++ b/images/macos/toolsets/toolset-11.0.json @@ -2,7 +2,8 @@ "xcode": { "default": "11.7", "versions": [ - "12.2_beta", "11.7" + { "link": "12.2", "version": "12.2.0" }, + { "link": "11.7", "version": "11.7.0", "symlinks": ["11.7_beta"] } ] }, "xamarin": { From 52c265bd7aa04830c60eced668430fbca7551223 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 4 Nov 2020 10:14:30 +0300 Subject: [PATCH 16/26] Update SoftwareReport.Generator.ps1 --- images/macos/software-report/SoftwareReport.Generator.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/macos/software-report/SoftwareReport.Generator.ps1 b/images/macos/software-report/SoftwareReport.Generator.ps1 index 21b19ceb..4eab767c 100644 --- a/images/macos/software-report/SoftwareReport.Generator.ps1 +++ b/images/macos/software-report/SoftwareReport.Generator.ps1 @@ -4,7 +4,7 @@ param ( $ImageName ) -$ErrorActionPreference = "Continue" +$ErrorActionPreference = "Stop" Import-Module MarkdownPS Import-Module "$PSScriptRoot/SoftwareReport.Common.psm1" -DisableNameChecking From 067fc901f9fb98f2e1cf0cf895e73aa8fc370923 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 4 Nov 2020 10:40:20 +0300 Subject: [PATCH 17/26] update templates --- images/macos/templates/macOS-10.13.json | 12 +++++------- images/macos/templates/macOS-10.14.json | 8 +++----- images/macos/templates/macOS-11.0.json | 4 ++-- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/images/macos/templates/macOS-10.13.json b/images/macos/templates/macOS-10.13.json index 3eda456d..7bfd0184 100644 --- a/images/macos/templates/macOS-10.13.json +++ b/images/macos/templates/macOS-10.13.json @@ -148,12 +148,8 @@ }, { "type": "shell", - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", - "scripts": [ - "./provision/core/xcode-tools.sh", - "./provision/core/xcode-sims.sh", - "./provision/core/build-xcode-symlinks.sh" - ], + "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}", + "script": "./provision/core/xcode.ps1", "environment_vars": [ "XCODE_INSTALL_USER={{user `xcode_install_user`}}", "XCODE_INSTALL_PASSWORD={{user `xcode_install_password`}}" @@ -187,7 +183,9 @@ "./provision/core/firefox.sh", "./provision/core/toolcache-high-sierra.sh", "./provision/core/pypy.sh", - "./provision/core/pipx-packages.sh" + "./provision/core/pipx-packages.sh", + "./provision/core/xcode-sims.sh", + "./provision/core/build-xcode-symlinks.sh" ] }, { diff --git a/images/macos/templates/macOS-10.14.json b/images/macos/templates/macOS-10.14.json index 06e4dc7b..576e8183 100644 --- a/images/macos/templates/macOS-10.14.json +++ b/images/macos/templates/macOS-10.14.json @@ -148,11 +148,8 @@ }, { "type": "shell", - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", - "scripts": [ - "./provision/core/xcode-tools.sh", - "./provision/core/xcode-sims.sh" - ], + "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}", + "script": "./provision/core/xcode.ps1", "environment_vars": [ "XCODE_INSTALL_USER={{user `xcode_install_user`}}", "XCODE_INSTALL_PASSWORD={{user `xcode_install_password`}}" @@ -189,6 +186,7 @@ "./provision/core/edge.sh", "./provision/core/firefox.sh", "./provision/core/miniconda.sh", + "./provision/core/xcode-sims.sh", "./provision/core/xcode-postbuild.sh", "./provision/core/toolcache.sh", "./provision/core/pypy.sh", diff --git a/images/macos/templates/macOS-11.0.json b/images/macos/templates/macOS-11.0.json index 2a9b691b..f885cad3 100644 --- a/images/macos/templates/macOS-11.0.json +++ b/images/macos/templates/macOS-11.0.json @@ -149,8 +149,8 @@ }, { "type": "shell", - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", - "script": "./provision/core/xcode-tools.sh", + "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}", + "script": "./provision/core/xcode.ps1", "environment_vars": [ "XCODE_INSTALL_USER={{user `xcode_install_user`}}", "XCODE_INSTALL_PASSWORD={{user `xcode_install_password`}}" From bf48ac16ea816035f7d7de8b5b77d19553f50093 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 6 Nov 2020 14:38:43 +0300 Subject: [PATCH 18/26] fix typos --- images/macos/helpers/Xcode.Installer.psm1 | 5 ++++- images/macos/tests/Xcode.Tests.ps1 | 2 +- images/macos/toolsets/toolset-10.14.json | 1 - 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/images/macos/helpers/Xcode.Installer.psm1 b/images/macos/helpers/Xcode.Installer.psm1 index 80a50eb0..5f2169d7 100644 --- a/images/macos/helpers/Xcode.Installer.psm1 +++ b/images/macos/helpers/Xcode.Installer.psm1 @@ -109,6 +109,7 @@ function Confirm-XcodeIntegrity { $XcodeRootPath = Get-XcodeRootPath -Version $Version if (Test-XcodeStableRelease -XcodeRootPath $XcodeRootPath) { + Write-Host "Validating Xcode integrity for '$XcodeRootPath'..." Invoke-ExpressionWithValidation "spctl --assess --raw $XcodeRootPath" } } @@ -119,7 +120,9 @@ function Approve-XcodeLicense { [string]$Version ) - $xcodeBuildPath = Get-XcodeToolPath -Version $Version -ToolName "xcodebuild" + $XcodeRootPath = Get-XcodeRootPath -Version $Version + Write-Host "Approving Xcode license for '$XcodeRootPath'..." + $xcodeBuildPath = Get-XcodeToolPath -XcodeRootPath $XcodeRootPath -ToolName "xcodebuild" Invoke-ExpressionWithValidation "sudo $xcodeBuildPath -license accept" } diff --git a/images/macos/tests/Xcode.Tests.ps1 b/images/macos/tests/Xcode.Tests.ps1 index 78c0ca07..244b66dc 100644 --- a/images/macos/tests/Xcode.Tests.ps1 +++ b/images/macos/tests/Xcode.Tests.ps1 @@ -21,7 +21,7 @@ Describe "Xcode" { $defaultXcodeTestCase = @{ DefaultXcode = $defaultXcode } It "Default Xcode is " -TestCases $defaultXcodeTestCase { "xcodebuild -version" | Should -ReturnZeroExitCode - (Get-CommandResult "xcodebuild -version").Output | Should -BeLike "Xcode ${DefaultXcode}.*" + (Get-CommandResult "xcodebuild -version").Output | Should -BeLike "Xcode ${DefaultXcode}*" } It "Xcode.app points to default Xcode" -TestCases $defaultXcodeTestCase { diff --git a/images/macos/toolsets/toolset-10.14.json b/images/macos/toolsets/toolset-10.14.json index 75041b5c..68096c68 100644 --- a/images/macos/toolsets/toolset-10.14.json +++ b/images/macos/toolsets/toolset-10.14.json @@ -12,7 +12,6 @@ { "link": "10.2.1", "version": "10.2.1", "symlinks": ["10.2.1_beta"] }, { "link": "10.2", "version": "10.2.0", "symlinks": ["10.2_beta"] }, { "link": "10.1", "version": "10.1.0", "symlinks": ["10.1_beta"] }, - { "link": "10.1", "version": "10.1.0", "symlinks": ["10.1_beta"] }, { "link": "10", "version": "10.0.0", "symlinks": ["10_beta"] }, { "link": "9.4.1", "version": "9.4.1", "symlinks": ["9.4.1_beta"] } ] From c1a5ebfc6a38343e37654c6d7c705709012af7bf Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Mon, 9 Nov 2020 17:46:21 +0300 Subject: [PATCH 19/26] Update xcode.ps1 --- images/macos/provision/core/xcode.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/images/macos/provision/core/xcode.ps1 b/images/macos/provision/core/xcode.ps1 index 3218a109..19f4d3c7 100644 --- a/images/macos/provision/core/xcode.ps1 +++ b/images/macos/provision/core/xcode.ps1 @@ -15,6 +15,7 @@ if ([string]::IsNullOrEmpty($env:XCODE_INSTALL_USER) -or [string]::IsNullOrEmpty $os = Get-OSVersion $xcodeVersions = Get-ToolsetValue "xcode.versions" $defaultXcode = Get-ToolsetValue "xcode.default" +[Array]::Reverse($xcodeVersions) Write-Host "Installing Xcode versions..." $xcodeVersions | ForEach-Object { @@ -25,7 +26,8 @@ $xcodeVersions | ForEach-Object { Write-Host "Configuring Xcode versions..." if ($os.IsLessThanCatalina) { - Install-XcodeAdditionalPackages -Version $xcodeVersions[0].link + $latestXcodeVersion = $xcodeVersions | Select-Object -Last 1 -ExpandProperty link + Install-XcodeAdditionalPackages -Version $latestXcodeVersion } $xcodeVersions | ForEach-Object { Invoke-XcodeRunFirstLaunch -Version $_.link } Invoke-XcodeRunFirstLaunch -Version $defaultXcode From ee8face8f2dfc6038823a79bfec83f652de4a7af Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Tue, 10 Nov 2020 16:48:20 +0300 Subject: [PATCH 20/26] fix condition and toolsets --- images/macos/helpers/Xcode.Installer.psm1 | 2 +- images/macos/toolsets/toolset-10.14.json | 2 +- images/macos/toolsets/toolset-10.15.json | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/images/macos/helpers/Xcode.Installer.psm1 b/images/macos/helpers/Xcode.Installer.psm1 index 5f2169d7..59968b2b 100644 --- a/images/macos/helpers/Xcode.Installer.psm1 +++ b/images/macos/helpers/Xcode.Installer.psm1 @@ -146,7 +146,7 @@ function Invoke-XcodeRunFirstLaunch { [string]$Version ) - if ($Version.StartsWith("8.") -or $Version.StartsWith("9.")) { + if ($Version.StartsWith("8") -or $Version.StartsWith("9")) { return } diff --git a/images/macos/toolsets/toolset-10.14.json b/images/macos/toolsets/toolset-10.14.json index 68096c68..c7b8c1ef 100644 --- a/images/macos/toolsets/toolset-10.14.json +++ b/images/macos/toolsets/toolset-10.14.json @@ -13,7 +13,7 @@ { "link": "10.2", "version": "10.2.0", "symlinks": ["10.2_beta"] }, { "link": "10.1", "version": "10.1.0", "symlinks": ["10.1_beta"] }, { "link": "10", "version": "10.0.0", "symlinks": ["10_beta"] }, - { "link": "9.4.1", "version": "9.4.1", "symlinks": ["9.4.1_beta"] } + { "link": "9.4.1", "version": "9.4.1" } ] }, "xamarin": { diff --git a/images/macos/toolsets/toolset-10.15.json b/images/macos/toolsets/toolset-10.15.json index 8d4cc70d..011750b4 100644 --- a/images/macos/toolsets/toolset-10.15.json +++ b/images/macos/toolsets/toolset-10.15.json @@ -5,13 +5,13 @@ { "link": "12.2", "version": "12.2.0" }, { "link": "12.1.1", "version": "12.1.1" }, { "link": "12.1", "version": "12.1.0" }, - { "link": "12", "version": "12.0.1" }, + { "link": "12", "version": "12.0.1", "symlinks": ["12_beta"] }, { "link": "11.7", "version": "11.7.0", "symlinks": ["11.7_beta"] }, { "link": "11.6", "version": "11.6.0", "symlinks": ["11.6_beta"] }, { "link": "11.5", "version": "11.5.0", "symlinks": ["11.5_beta"] }, - { "link": "11.4.1", "version": "11.4.1", "symlinks": ["11.4", "11.4_beta", "11.4.1_beta"] }, - { "link": "11.3.1", "version": "11.3.1", "symlinks": ["11.3", "11.3_beta", "11.3.1_beta"] }, - { "link": "11.2.1", "version": "11.2.1", "symlinks": ["11.2", "11.2_beta", "11.2.1_beta"] }, + { "link": "11.4.1", "version": "11.4.1", "symlinks": ["11.4", "11.4.1_beta"] }, + { "link": "11.3.1", "version": "11.3.1", "symlinks": ["11.3", "11.3.1_beta"] }, + { "link": "11.2.1", "version": "11.2.1", "symlinks": ["11.2", "11.2.1_beta"] }, { "link": "10.3", "version": "10.3", "symlinks": ["10.3_beta"] } ] }, From 6bd14d8f7b693571e02b29763d2cee73b09724ce Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 11 Nov 2020 09:31:22 +0300 Subject: [PATCH 21/26] Update Readme.md --- images/macos/toolsets/Readme.md | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/images/macos/toolsets/Readme.md b/images/macos/toolsets/Readme.md index 671ef482..14453889 100644 --- a/images/macos/toolsets/Readme.md +++ b/images/macos/toolsets/Readme.md @@ -1,10 +1,27 @@ # Toolset JSON structure ## Xcode -- `default` - version of Xcode to set as default - **Example:** `"11.2.1"` +- `versions` - the array of objects that will present installed Xcode versions + - `link` property points to the place where Xcode will be located on image. `/Applications/Xcode_.app` + - `version` points to Xcode version that will be downloaded and installed + - `symlinks` describes the list of aliases where symlinks will be created to +- `default` - version of Xcode to set as default (should be metched with any `link` in `versions` property) + **Example:** `"11.2"` -- `versions` - the array of versions of Xcode to install - **Example:** `[ "11.3", "11.2.1", "11.2", "11.1", "11" ]` +**Note:** +- If `version` is specified with spaces, it is considered as exact Xcode name like `12.1.1 Release Candidate`. +- If `version` doesn't contain spaces, the latest version will be resolved with the following priority: + - stable version like `12.1` + - release candidate version like `12.1 Release Candidate N` (the latest N will be chosen) + - GM version like `12.1 GM Seed N` (the latest N will be chosen) + - beta version like `12.1 beta N` (the latest N will be chosen) + +**Example:** +``` +"versions": [ + { "link": "12.2", "version": "12.2.0" }, + { "link": "11.7", "version": "11.7.0", "symlinks": ["11.7_beta"] } +] +``` ## Xamarin - `vsmac` - version of Visual Studio For Mac to install. From c656a9ddf2779de26637f041e83083f08a79ecac Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 11 Nov 2020 13:24:11 +0300 Subject: [PATCH 22/26] fix nitpicks --- images/macos/helpers/Common.Helpers.psm1 | 2 +- images/macos/helpers/Xcode.Installer.psm1 | 12 +++++------ images/macos/provision/core/xcode.ps1 | 2 -- images/macos/toolsets/toolset-10.13.json | 26 +++++++++++------------ 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/images/macos/helpers/Common.Helpers.psm1 b/images/macos/helpers/Common.Helpers.psm1 index 1c14ab3a..e71aa765 100644 --- a/images/macos/helpers/Common.Helpers.psm1 +++ b/images/macos/helpers/Common.Helpers.psm1 @@ -84,7 +84,7 @@ function Invoke-RestMethodWithRetry { Invoke-RestMethod $Url -MaximumRetryCount 10 -RetryIntervalSec 30 } -function Invoke-ExpressionWithValidation { +function Invoke-ValidateCommand { param( [Parameter(Mandatory)] [string]$Command diff --git a/images/macos/helpers/Xcode.Installer.psm1 b/images/macos/helpers/Xcode.Installer.psm1 index 59968b2b..37b48c5b 100644 --- a/images/macos/helpers/Xcode.Installer.psm1 +++ b/images/macos/helpers/Xcode.Installer.psm1 @@ -30,7 +30,7 @@ function Invoke-DownloadXcodeArchive { # TO-DO: Consider replacing of xcversion with own implementation Write-Host "Downloading Xcode $resolvedVersion" - Invoke-ExpressionWithValidation "xcversion install '$resolvedVersion' --no-install" + Invoke-ValidateCommand "xcversion install '$resolvedVersion' --no-install" } function Resolve-ExactXcodeVersion { @@ -85,7 +85,7 @@ function Expand-XcodeXipArchive { Write-Host "Extracting Xcode from '$xcodeXipPath'" Push-Location $DownloadDirectory - Invoke-ExpressionWithValidation "xip -x $xcodeXipPath" + Invoke-ValidateCommand "xip -x $xcodeXipPath" Pop-Location if (Test-Path "$DownloadDirectory/Xcode-beta.app") { @@ -110,7 +110,7 @@ function Confirm-XcodeIntegrity { $XcodeRootPath = Get-XcodeRootPath -Version $Version if (Test-XcodeStableRelease -XcodeRootPath $XcodeRootPath) { Write-Host "Validating Xcode integrity for '$XcodeRootPath'..." - Invoke-ExpressionWithValidation "spctl --assess --raw $XcodeRootPath" + Invoke-ValidateCommand "spctl --assess --raw $XcodeRootPath" } } @@ -123,7 +123,7 @@ function Approve-XcodeLicense { $XcodeRootPath = Get-XcodeRootPath -Version $Version Write-Host "Approving Xcode license for '$XcodeRootPath'..." $xcodeBuildPath = Get-XcodeToolPath -XcodeRootPath $XcodeRootPath -ToolName "xcodebuild" - Invoke-ExpressionWithValidation "sudo $xcodeBuildPath -license accept" + Invoke-ValidateCommand "sudo $xcodeBuildPath -license accept" } function Install-XcodeAdditionalPackages { @@ -136,7 +136,7 @@ function Install-XcodeAdditionalPackages { $xcodeRootPath = Get-XcodeRootPath -Version $Version $packages = Get-ChildItem -Path "$xcodeRootPath/Contents/Resources/Packages" -Filter "*.pkg" -File $packages | ForEach-Object { - Invoke-ExpressionWithValidation "sudo installer -pkg $($_.FullName) -target / -allowUntrusted" + Invoke-ValidateCommand "sudo installer -pkg $($_.FullName) -target / -allowUntrusted" } } @@ -152,7 +152,7 @@ function Invoke-XcodeRunFirstLaunch { Write-Host "Running 'runFirstLaunch' for Xcode $Version..." $xcodeRootPath = Get-XcodeToolPath -Version $Version -ToolName "xcodebuild" - Invoke-ExpressionWithValidation "sudo $xcodeRootPath -runFirstLaunch" + Invoke-ValidateCommand "sudo $xcodeRootPath -runFirstLaunch" } function Build-XcodeSymlinks { diff --git a/images/macos/provision/core/xcode.ps1 b/images/macos/provision/core/xcode.ps1 index 19f4d3c7..46f11518 100644 --- a/images/macos/provision/core/xcode.ps1 +++ b/images/macos/provision/core/xcode.ps1 @@ -1,8 +1,6 @@ # The script currently requires 2 external variables to be set: XCODE_INSTALL_USER # and XCODE_INSTALL_PASSWORD, in order to access the Apple Developer Center -Write-Host "Script begin" - $ErrorActionPreference = "Stop" Import-Module "$env:HOME/image-generation/helpers/Common.Helpers.psm1" diff --git a/images/macos/toolsets/toolset-10.13.json b/images/macos/toolsets/toolset-10.13.json index c828c198..797a83e6 100644 --- a/images/macos/toolsets/toolset-10.13.json +++ b/images/macos/toolsets/toolset-10.13.json @@ -2,19 +2,19 @@ "xcode": { "default": "10.1", "versions": [ - { "link": "10.1", "version": "10.1.0", "symlinks": [ "10.1_beta"] }, - { "link": "10", "version": "10.0.0", "symlinks": [ "10_beta"] }, - { "link": "9.4.1", "version": "9.4.1", "symlinks": [ "9.4.1_beta"] }, - { "link": "9.4", "version": "9.4.0", "symlinks": [ "9.4_beta"] }, - { "link": "9.3.1", "version": "9.3.1", "symlinks": [ "9.3.1_beta"] }, - { "link": "9.3", "version": "9.3.0", "symlinks": [ "9.3_beta"] }, - { "link": "9.2", "version": "9.2.0", "symlinks": [ "9.2_beta"] }, - { "link": "9.1", "version": "9.1.0", "symlinks": [ "9.1_beta"] }, - { "link": "9", "version": "9.0.0", "symlinks": [ "9_beta"] }, - { "link": "8.3.3", "version": "8.3.3", "symlinks": [ "8.3.3_beta"] }, - { "link": "8.2.1", "version": "8.2.1", "symlinks": [ "8.2.1_beta"] }, - { "link": "8.1", "version": "8.1.0", "symlinks": [ "8.1_beta"] }, - { "link": "8", "version": "8.0.0", "symlinks": [ "8_beta"] } + { "link": "10.1", "version": "10.1.0", "symlinks": ["10.1_beta"] }, + { "link": "10", "version": "10.0.0", "symlinks": ["10_beta"] }, + { "link": "9.4.1", "version": "9.4.1", "symlinks": ["9.4.1_beta"] }, + { "link": "9.4", "version": "9.4.0", "symlinks": ["9.4_beta"] }, + { "link": "9.3.1", "version": "9.3.1", "symlinks": ["9.3.1_beta"] }, + { "link": "9.3", "version": "9.3.0", "symlinks": ["9.3_beta"] }, + { "link": "9.2", "version": "9.2.0", "symlinks": ["9.2_beta"] }, + { "link": "9.1", "version": "9.1.0", "symlinks": ["9.1_beta"] }, + { "link": "9", "version": "9.0.0", "symlinks": ["9_beta"] }, + { "link": "8.3.3", "version": "8.3.3", "symlinks": ["8.3.3_beta"] }, + { "link": "8.2.1", "version": "8.2.1", "symlinks": ["8.2.1_beta"] }, + { "link": "8.1", "version": "8.1.0", "symlinks": ["8.1_beta"] }, + { "link": "8", "version": "8.0.0", "symlinks": ["8_beta"] } ] }, "xamarin": { From 1aad4c7b8d87d7d998018698f16e2e973a8615fd Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 11 Nov 2020 14:33:35 +0300 Subject: [PATCH 23/26] accept proposal --- images/macos/helpers/Xcode.Helpers.psm1 | 1 - images/macos/helpers/Xcode.Installer.psm1 | 8 +++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/images/macos/helpers/Xcode.Helpers.psm1 b/images/macos/helpers/Xcode.Helpers.psm1 index 2b2ebeef..de3b94be 100644 --- a/images/macos/helpers/Xcode.Helpers.psm1 +++ b/images/macos/helpers/Xcode.Helpers.psm1 @@ -42,7 +42,6 @@ function Get-XcodeVersionInfo { } } - function Switch-Xcode { param ( [Parameter(ParameterSetName = 'Version')] diff --git a/images/macos/helpers/Xcode.Installer.psm1 b/images/macos/helpers/Xcode.Installer.psm1 index 37b48c5b..7ccf9fb1 100644 --- a/images/macos/helpers/Xcode.Installer.psm1 +++ b/images/macos/helpers/Xcode.Installer.psm1 @@ -53,11 +53,9 @@ function Resolve-ExactXcodeVersion { function Get-AvailableXcodeVersions { $rawVersionsList = & xcversion list | ForEach-Object { $_.Trim() } | Where-Object { $_ -match "^\d" } $availableVersions = $rawVersionsList | ForEach-Object { - $parts = $_.Split(" ", 2) - $stableSemver = [SemVer]::Parse($parts[0]) - if ($parts.Count -eq 1) { - $semver = $stableSemver - } else { + $partStable,$partMajor = $_.Split(" ", 2) + $semver = $stableSemver = [SemVer]::Parse($partStable) + if ($partMajor) { # Convert 'beta 3' -> 'beta.3', 'Release Candidate' -> 'releasecandidate', 'GM Seed 2' -> 'gmseed.2' $normalizedLabel = $parts[1].toLower() -replace " (\d)", '.$1' -replace " ([a-z])", '$1' $semver = [SemVer]::new($stableSemver.Major, $stableSemver.Minor, $stableSemver.Patch, $normalizedLabel) From 897349365a026806d0a8f5f918ffd896a2cb58f6 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Wed, 11 Nov 2020 14:34:50 +0300 Subject: [PATCH 24/26] Update Xcode.Installer.psm1 --- images/macos/helpers/Xcode.Installer.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/macos/helpers/Xcode.Installer.psm1 b/images/macos/helpers/Xcode.Installer.psm1 index 7ccf9fb1..64d2381b 100644 --- a/images/macos/helpers/Xcode.Installer.psm1 +++ b/images/macos/helpers/Xcode.Installer.psm1 @@ -57,7 +57,7 @@ function Get-AvailableXcodeVersions { $semver = $stableSemver = [SemVer]::Parse($partStable) if ($partMajor) { # Convert 'beta 3' -> 'beta.3', 'Release Candidate' -> 'releasecandidate', 'GM Seed 2' -> 'gmseed.2' - $normalizedLabel = $parts[1].toLower() -replace " (\d)", '.$1' -replace " ([a-z])", '$1' + $normalizedLabel = $partMajor.toLower() -replace " (\d)", '.$1' -replace " ([a-z])", '$1' $semver = [SemVer]::new($stableSemver.Major, $stableSemver.Minor, $stableSemver.Patch, $normalizedLabel) } From 380c4e86a73cedaa598738bf11c5629586984c9d Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Thu, 12 Nov 2020 12:07:53 +0300 Subject: [PATCH 25/26] Update toolset-10.13.json --- images/macos/toolsets/toolset-10.13.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/images/macos/toolsets/toolset-10.13.json b/images/macos/toolsets/toolset-10.13.json index 797a83e6..11338ef8 100644 --- a/images/macos/toolsets/toolset-10.13.json +++ b/images/macos/toolsets/toolset-10.13.json @@ -4,17 +4,17 @@ "versions": [ { "link": "10.1", "version": "10.1.0", "symlinks": ["10.1_beta"] }, { "link": "10", "version": "10.0.0", "symlinks": ["10_beta"] }, - { "link": "9.4.1", "version": "9.4.1", "symlinks": ["9.4.1_beta"] }, + { "link": "9.4.1", "version": "9.4.1" }, { "link": "9.4", "version": "9.4.0", "symlinks": ["9.4_beta"] }, - { "link": "9.3.1", "version": "9.3.1", "symlinks": ["9.3.1_beta"] }, + { "link": "9.3.1", "version": "9.3.1" }, { "link": "9.3", "version": "9.3.0", "symlinks": ["9.3_beta"] }, - { "link": "9.2", "version": "9.2.0", "symlinks": ["9.2_beta"] }, - { "link": "9.1", "version": "9.1.0", "symlinks": ["9.1_beta"] }, - { "link": "9", "version": "9.0.0", "symlinks": ["9_beta"] }, - { "link": "8.3.3", "version": "8.3.3", "symlinks": ["8.3.3_beta"] }, - { "link": "8.2.1", "version": "8.2.1", "symlinks": ["8.2.1_beta"] }, - { "link": "8.1", "version": "8.1.0", "symlinks": ["8.1_beta"] }, - { "link": "8", "version": "8.0.0", "symlinks": ["8_beta"] } + { "link": "9.2", "version": "9.2.0" }, + { "link": "9.1", "version": "9.1.0" }, + { "link": "9", "version": "9.0.0" }, + { "link": "8.3.3", "version": "8.3.3" }, + { "link": "8.2.1", "version": "8.2.1" }, + { "link": "8.1", "version": "8.1.0" }, + { "link": "8", "version": "8.0.0" } ] }, "xamarin": { From 6e5366d4f4a24866dfc78a221e545bc960a60b43 Mon Sep 17 00:00:00 2001 From: Maxim Lobanov Date: Fri, 13 Nov 2020 20:36:22 +0300 Subject: [PATCH 26/26] xcode versions --- images/macos/toolsets/toolset-10.15.json | 1 + images/macos/toolsets/toolset-11.0.json | 1 + 2 files changed, 2 insertions(+) diff --git a/images/macos/toolsets/toolset-10.15.json b/images/macos/toolsets/toolset-10.15.json index 011750b4..f00ea5d1 100644 --- a/images/macos/toolsets/toolset-10.15.json +++ b/images/macos/toolsets/toolset-10.15.json @@ -2,6 +2,7 @@ "xcode": { "default": "12", "versions": [ + { "link": "12.3", "version": "12.3.0"}, { "link": "12.2", "version": "12.2.0" }, { "link": "12.1.1", "version": "12.1.1" }, { "link": "12.1", "version": "12.1.0" }, diff --git a/images/macos/toolsets/toolset-11.0.json b/images/macos/toolsets/toolset-11.0.json index 0409e270..801c19c6 100644 --- a/images/macos/toolsets/toolset-11.0.json +++ b/images/macos/toolsets/toolset-11.0.json @@ -2,6 +2,7 @@ "xcode": { "default": "11.7", "versions": [ + { "link": "12.3", "version": "12.3.0"}, { "link": "12.2", "version": "12.2.0" }, { "link": "11.7", "version": "11.7.0", "symlinks": ["11.7_beta"] } ]