Scripts/lib/simulators.sh

2ad5d8160338d289a65d6a4d1c214a02bf916f1f
domain-dig/Scripts/lib/simulators.sh history · blame · raw

59 lines · 2450 bytes

3 symbols in this file
 1# Simulator selection shared by the test scripts. Sourced, not executed.
 2#
 3# The caller sets PROJECT and SCHEME first, then calls
 4# read_deployment_target once and select_sim per tier.
 5#
 6# Runtime coverage is not nested: a result on one iOS version does not imply
 7# the same result on another, in either direction. Scripts/audit-a11y.sh
 8# documents the measured accessibility differences; the unit suite has its own
 9# case, a Swift runtime bug in MarkerItem::create that aborts on releasing a
10# main-actor-isolated object under iOS 18.6 and is fixed by iOS 26.5. Both are
11# reasons to run floor and current rather than whichever simulator is handy.
12
13# Sets DEPLOYMENT_TARGET, DT_MAJOR, DT_MINOR and FLOOR_RANK from the project,
14# so the floor cannot drift away from the build setting.
15read_deployment_target() {
16  DEPLOYMENT_TARGET=$(
17    xcodebuild -project "$PROJECT" -scheme "$SCHEME" -showBuildSettings 2>/dev/null \
18      | awk -F' = ' '/ IPHONEOS_DEPLOYMENT_TARGET = /{print $2; exit}'
19  )
20
21  if [[ -z "${DEPLOYMENT_TARGET:-}" ]]; then
22    echo "error: could not read IPHONEOS_DEPLOYMENT_TARGET" >&2
23    return 1
24  fi
25
26  DT_MAJOR="${DEPLOYMENT_TARGET%%.*}"
27  DT_MINOR="${DEPLOYMENT_TARGET##*.}"
28  [[ "$DT_MINOR" = "$DEPLOYMENT_TARGET" ]] && DT_MINOR=0
29  FLOOR_RANK=$(( DT_MAJOR * 1000 + DT_MINOR ))
30}
31
32# Pick an iPhone simulator at or above the deployment target. A runtime BELOW it
33# is useless — the app cannot install there — which is why this filters rather
34# than just taking the oldest installed runtime.
35select_sim() {
36  local which="$1"
37  xcrun simctl list devices available --json \
38    | jq -c --argjson floor "$FLOOR_RANK" --arg which "$which" '
39        [ .devices | to_entries[]
40          | (.key | capture("SimRuntime\\.iOS-(?<maj>[0-9]+)-(?<min>[0-9]+)$")) as $v
41          | (($v.maj | tonumber) * 1000 + ($v.min | tonumber)) as $rank
42          | select($rank >= $floor)
43          | .value[]
44          | select(.name | startswith("iPhone"))
45          | { rank: $rank, udid: .udid, name: .name, os: "\($v.maj).\($v.min)" }
46        ]
47        | sort_by(.rank, .name)
48        | if length == 0 then empty
49          elif $which == "floor" then first
50          else last end
51      '
52}
53
54# True when the chosen "floor" simulator is a major version above the
55# deployment target, i.e. the floor is not actually covered.
56floor_is_approximate() {
57  local sim="$1"
58  [[ "$(echo "$sim" | jq -r .rank)" -ge $(( (DT_MAJOR + 1) * 1000 )) ]]
59}