Skip to content

Commit d46ce6d

Browse files
authored
[CI] Dynamically pick latest simulator device
1 parent 8f858bd commit d46ce6d

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

scripts/build.sh

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,19 +168,44 @@ function CheckUnexpectedFailures() {
168168
fi
169169
}
170170

171+
# Dynamically fetches the latest available simulator for a given OS and device type.
172+
function get_latest_simulator() {
173+
local os_name="$1"
174+
local device_keyword="$2"
175+
local simulator_name
176+
177+
simulator_name=$(xcrun simctl list devices available -j \
178+
| jq -r --arg os "$os_name" --arg dev "$device_keyword" '
179+
.devices |
180+
to_entries |
181+
map(select(.key | contains($os))) |
182+
sort_by(.key) |
183+
last |
184+
.value |
185+
map(select(.name | contains($dev))) |
186+
first |
187+
.name
188+
')
189+
190+
if [[ -z "$simulator_name" ]] || [[ "$simulator_name" == "null" ]]; then
191+
echo "Error: Could not find a simulator for OS '$os_name' and device '$device_keyword'." >&2
192+
return 1
193+
fi
194+
195+
echo "Selected $os_name Simulator: $simulator_name"
196+
}
197+
171198
if [[ "$xcode_major" -lt 16 && "$method" != "cmake" ]]; then
172199
echo "Unsupported Xcode major version being used: $xcode_major"
173200
exit 1
174201
else
175-
iphone_simulator_name="iPhone 16"
176-
if [[ "$xcode_major" -gt 16 ]]; then
177-
iphone_simulator_name="iPhone 16e"
178-
fi
202+
iphone_simulator_name=$(get_latest_simulator "iOS" "iPhone")
179203
ios_flags=(
180-
-destination "platform=iOS Simulator,name=${iphone_simulator_name}"
204+
-destination "platform=iOS Simulator,OS=latest,name=${iphone_simulator_name}"
181205
)
206+
watchos_simulator_name=$(get_latest_simulator "watchOS" "Apple Watch")
182207
watchos_flags=(
183-
-destination 'platform=watchOS Simulator,name=Apple Watch Series 11 (42mm)'
208+
-destination "platform=watchOS Simulator,OS=latest,name=${watchos_simulator_name}"
184209
)
185210
fi
186211

@@ -195,8 +220,9 @@ ipad_flags=(
195220
macos_flags=(
196221
-destination 'platform=OS X,arch=x86_64'
197222
)
223+
tvos_simulator_name=$(get_latest_simulator "tvOS" "Apple TV")
198224
tvos_flags=(
199-
-destination 'platform=tvOS Simulator,name=Apple TV'
225+
-destination "platform=tvOS Simulator,OS=latest,name=${tvos_simulator_name}"
200226
)
201227
if [[ "$xcode_major" -ge 26 ]]; then
202228
visionos_flags=(

0 commit comments

Comments
 (0)