Skip to content

Commit b5c3f3b

Browse files
authored
[release/10.0.1xx] [system-dependencies] Check if a universal simulator is needed, and if so delete any existing non-universal simulators. (#24087)
1. We run x64 test apps on all machines. 2. Arm64 machines need a universal simulator to run x64 apps. 3. So if we're on an arm64 bot, and we only have the arm64 simulator, delete it and re-install the universal simulator. There are also a few other misc cleanups here as well. Backport of #24030.
1 parent 10b89df commit b5c3f3b

File tree

1 file changed

+75
-25
lines changed

1 file changed

+75
-25
lines changed

system-dependencies.sh

Lines changed: 75 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,23 @@ function install_mono () {
314314
rm -f $MONO_PKG
315315
}
316316

317+
SIMULATORS_WITHOUT_X64=()
318+
SIMULATORS_WITHOUT_X64_COUNT=0
319+
function get_non_universal_simulator_runtimes ()
320+
{
321+
local TMPFILE
322+
TMPFILE=$(mktemp)
323+
324+
xcrun simctl runtime list -j --json-output="$TMPFILE"
325+
326+
# this json query filters the json to simulator runtimes where iOS/tvOS >= 26.0 and where x64 is *not* supported (which we need to run x64 apps in the simulator on arm64)
327+
JQ_QUERY='map({identifier: .identifier, version: .version, supportedArchitectures: .supportedArchitectures | join("|"), majorVersion: .version | split(".")[0] | tonumber }) | map(select(.majorVersion>=26) ) | map(select(.supportedArchitectures | contains("x86_64") | not)) | .[].identifier'
328+
SIMULATORS_WITHOUT_X64=($(jq "$JQ_QUERY" -r "$TMPFILE"))
329+
SIMULATORS_WITHOUT_X64_COUNT="${#SIMULATORS_WITHOUT_X64[@]}"
330+
331+
rm -f "$TMPFILE"
332+
}
333+
317334
function xcodebuild_download_selected_platforms ()
318335
{
319336
local XCODE_DEVELOPER_ROOT
@@ -342,13 +359,60 @@ function xcodebuild_download_selected_platforms ()
342359
TVOS_NUGET_OS_VERSION=$(grep '^TVOS_NUGET_OS_VERSION=' Make.versions | sed 's/.*=//')
343360
TVOS_BUILD_VERSION=" -buildVersion $TVOS_NUGET_OS_VERSION -architectureVariant universal"
344361
fi
362+
elif is_at_least_version "$XCODE_VERSION" 26.0; then
363+
# we always want the universal variant, so that we can run x64 test apps on arm64
364+
IOS_BUILD_VERSION=" -architectureVariant universal"
365+
TVOS_BUILD_VERSION=" -architectureVariant universal"
366+
fi
367+
368+
# If we're executing on arm64, we need simulator runtimes that support x64 in order to run
369+
# x64 apps in the simulator (aka the universal architecture variant). If we have any simulator
370+
# runtimes that don't support x64, then delete those, so that we can re-install the universal
371+
# variant.
372+
local DOTNET_ARCH
373+
if [[ "$(arch)" == "arm64" ]]; then
374+
DOTNET_ARCH=arm64
375+
elif [[ "$(sysctl -n sysctl.proc_translated 2>/dev/null)" == "1" ]]; then
376+
DOTNET_ARCH=arm64
377+
fi
378+
if [[ "$DOTNET_ARCH" == "arm64" ]]; then
379+
log "Looking for iOS/tvOS 26+ simulator runtimes that don't support x64..."
380+
381+
get_non_universal_simulator_runtimes
382+
if [[ "$SIMULATORS_WITHOUT_X64_COUNT" -gt 0 ]]; then
383+
log "Found ${SIMULATORS_WITHOUT_X64_COUNT} simulator runtimes that don't support x64, which will now be deleted: ${SIMULATORS_WITHOUT_X64[@]}"
384+
for sim in "${SIMULATORS_WITHOUT_X64[@]}"; do
385+
log "Executing 'xcrun simctl runtime delete $sim'"
386+
sleep 60
387+
xcrun simctl runtime delete "$sim"
388+
done
389+
# sadly simulator deletion is done asynchronously, so we have to wait until they're all gone
390+
log "Waiting for the simulators to be deleted..."
391+
printf " "
392+
for i in $(seq 1 60); do
393+
sleep 1
394+
get_non_universal_simulator_runtimes
395+
if [[ "$SIMULATORS_WITHOUT_X64_COUNT" == "0" ]]; then
396+
break
397+
fi
398+
printf "$SIMULATORS_WITHOUT_X64_COUNT"
399+
done
400+
printf "\n"
401+
if [[ "$SIMULATORS_WITHOUT_X64_COUNT" != "0" ]]; then
402+
warn "Waited for 60 seconds, but there are still $SIMULATORS_WITHOUT_X64_COUNT simulators waiting to deleted."
403+
fi
404+
else
405+
log "All installed iOS/tvOS 26+ simulators support x64"
406+
fi
345407
fi
346408

347409
log "Executing '$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild -downloadPlatform iOS$IOS_BUILD_VERSION' $1"
348-
"$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild" -downloadPlatform iOS $IOS_BUILD_VERSION
410+
"$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild" -downloadPlatform iOS $IOS_BUILD_VERSION 2>&1 | sed 's/^/ /'
349411

350412
log "Executing '$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild -downloadPlatform tvOS$TVOS_BUILD_VERSION' $1"
351-
"$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild" -downloadPlatform tvOS $TVOS_BUILD_VERSION
413+
"$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild" -downloadPlatform tvOS $TVOS_BUILD_VERSION 2>&1 | sed 's/^/ /'
414+
415+
exit 0
352416
}
353417

354418
function download_xcode_platforms ()
@@ -377,38 +441,24 @@ function download_xcode_platforms ()
377441
$SUDO pkill -9 -f "CoreSimulator.framework" || true
378442
if ! xcodebuild_download_selected_platforms; then
379443
log "Executing '$XCODE_DEVELOPER_ROOT/usr/bin/simctl runtime list -v"
380-
"$XCODE_DEVELOPER_ROOT/usr/bin/simctl" runtime list -v
444+
"$XCODE_DEVELOPER_ROOT/usr/bin/simctl" runtime list -v 2>&1 | sed 's/^/ /'
381445
# Don't exit here, just hope for the best instead.
382-
set +x
383-
echo "##vso[task.logissue type=warning;sourcepath=system-dependencies.sh]Failed to download all simulator platforms, this may result in problems executing tests in the simulator."
384-
set -x
446+
(
447+
set +x
448+
echo "##vso[task.logissue type=warning;sourcepath=system-dependencies.sh]Failed to download all simulator platforms, this may result in problems executing tests in the simulator."
449+
set -x
450+
)
385451
else
386452
log "Executing '$XCODE_DEVELOPER_ROOT/usr/bin/simctl runtime list -v"
387-
"$XCODE_DEVELOPER_ROOT/usr/bin/simctl" runtime list -v
453+
"$XCODE_DEVELOPER_ROOT/usr/bin/simctl" runtime list -v 2>&1 | sed 's/^/ /'
388454
log "Executing '$XCODE_DEVELOPER_ROOT/usr/bin/simctl list -v"
389-
"$XCODE_DEVELOPER_ROOT/usr/bin/simctl" list -v
455+
"$XCODE_DEVELOPER_ROOT/usr/bin/simctl" list -v 2>&1 | sed 's/^/ /'
390456
fi
391457

392-
xcodebuild_download_selected_platforms "(second time)" || true
393-
xcodebuild_download_selected_platforms "(third time)" || true
394-
xcodebuild_download_selected_platforms "(fourth time)" || true
395-
396458
log "Executing '$SUDO $XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild -runFirstLaunch'"
397459
$SUDO "$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild" -runFirstLaunch
398460
log "Executed '$SUDO $XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild -runFirstLaunch'"
399461

400-
# This is a workaround for a bug in Xcode 15 where we need to open the platforms panel for it to register the simulators.
401-
log "Executing 'open xcpref://Xcode.PreferencePane.Platforms'"
402-
log "Killing Xcode"
403-
pkill -9 "Xcode" || log "Xcode was not running."
404-
log "Opening Xcode preferences panel"
405-
open xcpref://Xcode.PreferencePane.Platforms
406-
log "waiting 10 secs for Xcode to open the preferences panel"
407-
sleep 10
408-
log "Killing Xcode"
409-
pkill -9 "Xcode" || log "Xcode was not running."
410-
log "Executed 'open xcpref://Xcode.PreferencePane.Platforms'"
411-
412462
log "Finished installing Xcode platforms"
413463
}
414464

@@ -1020,7 +1070,7 @@ function check_old_simulators ()
10201070
$action "The $os $version simulator is not installed. Execute ${COLOR_MAGENTA}xcodebuild -downloadPlatform $os -buildVersion $version${COLOR_RESET} to install."
10211071
else
10221072
warn "The $os $version simulator is not installed. Now executing ${COLOR_BLUE}"$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild" -downloadPlatform $os -buildVersion $version${COLOR_RESET} to install..."
1023-
"$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild" -downloadPlatform "$os" -buildVersion "$version"
1073+
"$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild" -downloadPlatform "$os" -buildVersion "$version" 2>&1 | sed 's/^/ /'
10241074
warn "Successfully executed ${COLOR_BLUE}"$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild" -downloadPlatform $os -buildVersion $version${COLOR_RESET}."
10251075
fi
10261076
done

0 commit comments

Comments
 (0)