Skip to content

Commit 76d9242

Browse files
authored
[system-dependencies] Make simulator runtime installation a bit more resilient. (#24243)
* If there are any unusable simulator runtimes, delete them all. A frequent failure is when a simulator runtime isn't ready because "Unusable - Other Failure: Duplicate of ...", so hopefully this will solve those problems. * Don't pass -buildVersion to 'xcodebuild -downloadPlatform', Apple's tooling doesn't seem able to handle it correctly and gets confused. * Remove a stray 'sleep 60'.
1 parent 0e48207 commit 76d9242

File tree

1 file changed

+49
-11
lines changed

1 file changed

+49
-11
lines changed

system-dependencies.sh

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

317+
function delete_all_simulator_runtimes ()
318+
{
319+
log "Executing 'xcrun simctl runtime delete all'..."
320+
xcrun simctl runtime delete all
321+
322+
local TMPFILE
323+
TMPFILE=$(mktemp)
324+
325+
local COUNT
326+
327+
# sadly simulator deletion is done asynchronously, so we have to wait until they're all gone
328+
log "Waiting for the simulator runtimes to be deleted..."
329+
printf " "
330+
for i in $(seq 1 60); do
331+
sleep 1
332+
xcrun simctl runtime list -j --json-output="$TMPFILE"
333+
COUNT=$(jq "length" -r "$TMPFILE")
334+
if [[ "$COUNT" == "0" ]]; then
335+
break
336+
fi
337+
printf "$COUNT"
338+
done
339+
printf "\n"
340+
if [[ "$COUNT" != "0" ]]; then
341+
warn "Waited for 60 seconds, but there are still $COUNT simulators waiting to deleted."
342+
fi
343+
344+
rm -rf "$TMPFILE"
345+
}
346+
317347
SIMULATORS_WITHOUT_X64=()
318348
SIMULATORS_WITHOUT_X64_COUNT=0
319349
function get_non_universal_simulator_runtimes ()
@@ -350,21 +380,30 @@ function xcodebuild_download_selected_platforms ()
350380

351381
IOS_BUILD_VERSION=
352382
TVOS_BUILD_VERSION=
353-
if is_at_least_version "$XCODE_VERSION" 26.1; then
354-
# passing -buildVersion .. --architectureVariant .. doesn't quite work in Xcode 26.0 (it works the first time, but then it always thinks it's the first time, tries to download and install, and gets confused), let's see if they fix it in Xcode 26.1
355-
if [[ "$XCODE_IS_STABLE" == "YES" ]]; then
356-
# we always want the universal variant, so that we can run x64 test apps on arm64
357-
IOS_NUGET_OS_VERSION=$(grep '^IOS_NUGET_OS_VERSION=' Make.versions | sed 's/.*=//')
358-
IOS_BUILD_VERSION=" -buildVersion $IOS_NUGET_OS_VERSION -architectureVariant universal"
359-
TVOS_NUGET_OS_VERSION=$(grep '^TVOS_NUGET_OS_VERSION=' Make.versions | sed 's/.*=//')
360-
TVOS_BUILD_VERSION=" -buildVersion $TVOS_NUGET_OS_VERSION -architectureVariant universal"
361-
fi
362-
elif is_at_least_version "$XCODE_VERSION" 26.0; then
383+
if is_at_least_version "$XCODE_VERSION" 26.0; then
363384
# we always want the universal variant, so that we can run x64 test apps on arm64
364385
IOS_BUILD_VERSION=" -architectureVariant universal"
365386
TVOS_BUILD_VERSION=" -architectureVariant universal"
366387
fi
367388

389+
local TMPFILE
390+
TMPFILE=$(mktemp)
391+
log "Checking if there are any simulator runtimes that aren't ready..."
392+
xcrun simctl runtime list --json "--json-output=$TMPFILE"
393+
NOT_READY_COUNT=$(jq 'map({identifier: .identifier, state: .state}) | map(select(.state != "Ready")) | length' "$TMPFILE")
394+
if [[ "$NOT_READY_COUNT" != "0" ]]; then
395+
log "Found simulator runtimes that aren't ready, will proceed to delete all simulator runtimes:"
396+
(
397+
export IFS=$'\n'
398+
for line in $(jq 'map({identifier: .identifier, state: .state}) | map(select(.state != "Ready"))[] | "\(.identifier): \(.state)"' -r "$TMPFILE"); do
399+
log " $line"
400+
done
401+
)
402+
delete_all_simulator_runtimes
403+
else
404+
log " none found."
405+
fi
406+
368407
# If we're executing on arm64, we need simulator runtimes that support x64 in order to run
369408
# x64 apps in the simulator (aka the universal architecture variant). If we have any simulator
370409
# runtimes that don't support x64, then delete those, so that we can re-install the universal
@@ -383,7 +422,6 @@ function xcodebuild_download_selected_platforms ()
383422
log "Found ${SIMULATORS_WITHOUT_X64_COUNT} simulator runtimes that don't support x64, which will now be deleted: ${SIMULATORS_WITHOUT_X64[@]}"
384423
for sim in "${SIMULATORS_WITHOUT_X64[@]}"; do
385424
log "Executing 'xcrun simctl runtime delete $sim'"
386-
sleep 60
387425
xcrun simctl runtime delete "$sim"
388426
done
389427
# sadly simulator deletion is done asynchronously, so we have to wait until they're all gone

0 commit comments

Comments
 (0)