Skip to content

Commit a82a7c4

Browse files
abueideclaude
andcommitted
fix(android,ios): fail device sync in strict mode when runtimes are missing
In pure/CI mode (DEVBOX_PURE_SHELL=1), devices sync now exits 1 when devices are skipped due to unavailable runtimes or system images. In normal dev mode, behavior is unchanged (warn and continue). Also fixes Android android_ensure_avd_from_definition to return code 3 for skipped devices (consistent with iOS) and corrects result tracking in sync. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 57efc1f commit a82a7c4

3 files changed

Lines changed: 51 additions & 13 deletions

File tree

plugins/android/virtenv/scripts/domain/avd.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ android_setup_avds() {
353353
first_avd_file="${ANDROID_AVD_HOME}/.first_avd"
354354
rm -f "$first_avd_file"
355355

356+
# Track skipped devices (loop runs in subshell, so use temp file)
357+
skip_count_file="$(mktemp "${TMPDIR:-/tmp}/android-avd-skips-XXXXXX")"
358+
echo "0" > "$skip_count_file"
359+
356360
# Get default system image tag
357361
default_image_tag="${ANDROID_SYSTEM_IMAGE_TAG:-google_apis}"
358362

@@ -370,6 +374,7 @@ android_setup_avds() {
370374
# Validate required fields
371375
if [ -z "$api_level" ] || [ -z "$device_hardware" ]; then
372376
echo "ERROR: Device definition missing required fields (api, device)" >&2
377+
echo "$(( $(cat "$skip_count_file") + 1 ))" > "$skip_count_file"
373378
continue
374379
fi
375380

@@ -388,6 +393,7 @@ android_setup_avds() {
388393
echo "ERROR: Device '$device_hardware' not found in avdmanager" >&2
389394
echo " Run: avdmanager list device" >&2
390395
echo " Use exact device ID from the list" >&2
396+
echo "$(( $(cat "$skip_count_file") + 1 ))" > "$skip_count_file"
391397
continue
392398
fi
393399

@@ -398,6 +404,7 @@ android_setup_avds() {
398404
echo " Preferred ABI: ${preferred_abi:-auto}" >&2
399405
echo " Check: ${ANDROID_SDK_ROOT}/system-images/android-${api_level}" >&2
400406
echo " Re-enter devbox shell to download system images" >&2
407+
echo "$(( $(cat "$skip_count_file") + 1 ))" > "$skip_count_file"
401408
continue
402409
fi
403410

@@ -476,6 +483,18 @@ android_setup_avds() {
476483
fi
477484
fi
478485

486+
# Check for skipped devices in strict mode
487+
avd_skips="$(cat "$skip_count_file" 2>/dev/null || echo "0")"
488+
rm -f "$skip_count_file"
489+
if [ "$avd_skips" -gt 0 ]; then
490+
if [ "${DEVBOX_PURE_SHELL:-}" = "1" ] || [ "${ANDROID_STRICT_SYNC:-}" = "1" ]; then
491+
echo ""
492+
echo "ERROR: $avd_skips device(s) skipped due to missing system images (strict mode)" >&2
493+
echo " Re-enter devbox shell to download system images or update device definitions" >&2
494+
exit 1
495+
fi
496+
fi
497+
479498
echo ""
480499
echo "AVD setup complete!"
481500
echo "Start emulator: emulator -avd <name> --netdelay none --netspeed full"
@@ -512,14 +531,14 @@ android_ensure_avd_from_definition() {
512531
device_hardware="$(android_resolve_device_hardware "$device" || true)"
513532
if [ -z "$device_hardware" ]; then
514533
echo " ⚠ Device hardware '$device' not available, skipping $name"
515-
return 0
534+
return 3
516535
fi
517536

518537
# Pick system image
519538
system_image="$(android_pick_system_image "$api" "$tag" "$preferred_abi" || true)"
520539
if [ -z "$system_image" ]; then
521540
echo " ⚠ System image not available (API $api, tag $tag), skipping $name"
522-
return 0
541+
return 3
523542
fi
524543

525544
# Extract expected ABI from system image package

plugins/android/virtenv/scripts/user/devices.sh

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -555,17 +555,16 @@ case "$command_name" in
555555
device_json="$temp_dir/device_${device_index}.json"
556556
jq -c ".devices[$device_index]" "$lock_file_path" > "$device_json"
557557

558-
# Call ensure function and track result
559-
if android_ensure_avd_from_definition "$device_json"; then
560-
result=$?
561-
case $result in
562-
0) matched=$((matched + 1)) ;;
563-
1) recreated=$((recreated + 1)) ;;
564-
2) created=$((created + 1)) ;;
565-
esac
566-
else
567-
skipped=$((skipped + 1))
568-
fi
558+
# Call ensure function and track result (use || true to prevent early exit)
559+
android_ensure_avd_from_definition "$device_json" || result=$?
560+
result=${result:-0}
561+
case $result in
562+
0) matched=$((matched + 1)) ;;
563+
1) recreated=$((recreated + 1)) ;;
564+
2) created=$((created + 1)) ;;
565+
3) skipped=$((skipped + 1)) ;;
566+
*) skipped=$((skipped + 1)) ;;
567+
esac
569568

570569
device_index=$((device_index + 1))
571570
done
@@ -582,6 +581,16 @@ case "$command_name" in
582581
if [ "$skipped" -gt 0 ]; then
583582
echo " ⚠ Skipped: $skipped"
584583
fi
584+
585+
# In strict mode (pure shell / CI), fail if any devices were skipped
586+
if [ "$skipped" -gt 0 ]; then
587+
if [ "${DEVBOX_PURE_SHELL:-}" = "1" ] || [ "${ANDROID_STRICT_SYNC:-}" = "1" ]; then
588+
echo ""
589+
echo "ERROR: $skipped device(s) skipped due to missing system images (strict mode)" >&2
590+
echo " Re-enter devbox shell to download system images or update device definitions" >&2
591+
exit 1
592+
fi
593+
fi
585594
;;
586595

587596
# --------------------------------------------------------------------------

plugins/ios/virtenv/scripts/user/devices.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,16 @@ case "$command_name" in
328328
if [ "$skipped" -gt 0 ]; then
329329
echo " ⚠ Skipped: $skipped"
330330
fi
331+
332+
# In strict mode (pure shell / CI), fail if any devices were skipped
333+
if [ "$skipped" -gt 0 ]; then
334+
if [ "${DEVBOX_PURE_SHELL:-}" = "1" ] || [ "${IOS_STRICT_SYNC:-}" = "1" ]; then
335+
echo ""
336+
echo "ERROR: $skipped device(s) skipped due to missing runtimes (strict mode)" >&2
337+
echo " Install missing runtimes or update device definitions" >&2
338+
exit 1
339+
fi
340+
fi
331341
exit 0
332342
;;
333343

0 commit comments

Comments
 (0)