fix(ios): improve UUID extraction with better regex patterns
Enhanced UUID extraction with multiple fallback strategies:
UUID Extraction Improvements:
- Primary: Extended regex to match UUID pattern (36-char hex with dashes)
- Fallback 1: Basic regex to get first parentheses content
- Fallback 2: Extended regex with explicit UUID format if status was extracted
- Handles both macOS sed (BSD) and GNU sed compatibility
Regex Patterns:
- Primary: sed -E 's/.*\(([0-9A-F-]{36})\).*/\1/'
- Fallback: sed 's/.*(\([^)]*\)).*/\1/'
- UUID format: 8-4-4-4-12 hex characters with dashes
Fixes:
- Status extraction: Detects if status was extracted instead of UUID
- UUID matching: Multiple patterns ensure UUID is found
- Compatibility: Works with both BSD and GNU sed
Result: Should now correctly extract UUID regardless of sed version
This commit is contained in:
@@ -92,10 +92,16 @@ if [ -z "$1" ]; then
|
||||
# Extract device ID (UUID in first set of parentheses, not status in second)
|
||||
# Format: " iPhone 17 Pro (68D19D08-4701-422C-AF61-2E21ACA1DD4C) (Shutdown)"
|
||||
# We want the UUID, which is in the first parentheses
|
||||
SIMULATOR_ID=$(echo "$SIMULATOR_LINE" | sed -n 's/.*(\([0-9A-F-]\{36\}\)).*/\1/p' | head -1)
|
||||
if [ -z "$SIMULATOR_ID" ]; then
|
||||
# Fallback: try to get first parentheses content (should be UUID)
|
||||
SIMULATOR_ID=$(echo "$SIMULATOR_LINE" | sed -n 's/.*(\([^)]*\)).*/\1/p' | head -1)
|
||||
# Try extended regex first (works on macOS sed)
|
||||
SIMULATOR_ID=$(echo "$SIMULATOR_LINE" | sed -E 's/.*\(([0-9A-F-]{36})\).*/\1/' 2>/dev/null)
|
||||
if [ -z "$SIMULATOR_ID" ] || [ "$SIMULATOR_ID" = "$SIMULATOR_LINE" ]; then
|
||||
# Fallback: use basic regex to get first parentheses content
|
||||
SIMULATOR_ID=$(echo "$SIMULATOR_LINE" | sed 's/.*(\([^)]*\)).*/\1/' | head -1)
|
||||
# If that gives us "Shutdown" or similar status, try a different approach
|
||||
if [ "$SIMULATOR_ID" = "Shutdown" ] || [ "$SIMULATOR_ID" = "Booted" ]; then
|
||||
# Extract UUID by matching the pattern before the status
|
||||
SIMULATOR_ID=$(echo "$SIMULATOR_LINE" | sed -E 's/.*\(([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})\).*/\1/' 2>/dev/null)
|
||||
fi
|
||||
fi
|
||||
log_info "Auto-detected simulator: $SIMULATOR_DEVICE (ID: $SIMULATOR_ID)"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user