From be118a32fb6035a70e6f901f9f9ae98e43903739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20Petter=20Ska=CC=8Alerud?= Date: Mon, 1 Dec 2025 10:59:08 +0100 Subject: [PATCH] macOS, Xcode: Harden error-handling when installing Xcode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current script relies on some commands intentionally failing during provisioning because they only apply to certain versions of Xcode. These errors are silenced using pipes. This is error-prone because we can no longer catch when these commands are failing in the case where they should not. This patch introduces some additional error-handling and conditionals to make sure we only run commands when they are intended to succeed. Pick-to: 6.10 6.8 Change-Id: Ic5048f54adb31d263e28f51312f44fe3b55e6fe5 Reviewed-by: Tor Arne Vestbø (cherry picked from commit ba6a77312d58b17181b7a5a9e0d1a56ae93bb4fe) Reviewed-by: Qt Cherry-pick Bot --- coin/provisioning/common/macos/install_xcode.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/coin/provisioning/common/macos/install_xcode.sh b/coin/provisioning/common/macos/install_xcode.sh index 95f611a7..69f6a761 100755 --- a/coin/provisioning/common/macos/install_xcode.sh +++ b/coin/provisioning/common/macos/install_xcode.sh @@ -2,6 +2,8 @@ # Copyright (C) 2021 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +set -ex + # shellcheck source=./../unix/DownloadURL.sh source "${BASH_SOURCE%/*}/../unix/DownloadURL.sh" @@ -20,6 +22,11 @@ function InstallXCode() { sourceFile=$1 version=$2 + if ! [[ $version =~ ^[0-9] ]]; then + echo "Error: version input must start with a digit" + exit 1 + fi + echo "Uncompressing and installing '$sourceFile'" if [[ $sourceFile =~ tar ]]; then cd /Applications/ && sudo tar -zxf "$sourceFile" @@ -35,7 +42,7 @@ function InstallXCode() { fi echo "Versioning application bundle" - majorVersion=$(echo "$version" | cut -d '.' -f 1) + majorVersion="${version%%[^0-9]*}" versionedAppBundle="/Applications/Xcode${majorVersion}.app" sudo mv /Applications/Xcode*.app "${versionedAppBundle}" @@ -46,11 +53,12 @@ function InstallXCode() { sudo xcodebuild -license accept echo "Install packages" - # -runFirstLaunch is valid in 9.x - sudo xcodebuild -runFirstLaunch || true + sudo xcodebuild -runFirstLaunch # Metal toolchain not included by default in Xcode 26 - xcodebuild -downloadComponent MetalToolchain || true + if ((majorVersion >= 26)); then + xcodebuild -downloadComponent MetalToolchain + fi echo "Enabling developer mode, so that using lldb does not require interactive password entry" sudo /usr/sbin/DevToolsSecurity -enable