diff --git a/dev/devicelab/bin/tasks/ios_app_with_watch_companion.dart b/dev/devicelab/bin/tasks/ios_app_with_watch_companion.dart index 4bc7a599d0..82cf8fa2eb 100644 --- a/dev/devicelab/bin/tasks/ios_app_with_watch_companion.dart +++ b/dev/devicelab/bin/tasks/ios_app_with_watch_companion.dart @@ -74,7 +74,57 @@ Future main() async { section('Create build for a simulator device'); - // Create iOS simulator devices. + // Xcode 11.4 simctl create makes the runtime argument optional, and defaults to latest. + // TODO(jmagman): Remove runtime parsing when devicelab upgrades to Xcode 11.4 https://github.com/flutter/flutter/issues/54889 + final String availableRuntimes = await eval( + 'xcrun', + [ + 'simctl', + 'list', + 'runtimes', + ], + canFail: false, + workingDirectory: flutterDirectory.path, + ); + + // Example simctl list: + // == Runtimes == + // iOS 10.3 (10.3.1 - 14E8301) - com.apple.CoreSimulator.SimRuntime.iOS-10-3 + // iOS 13.4 (13.4 - 17E255) - com.apple.CoreSimulator.SimRuntime.iOS-13-4 + // tvOS 13.4 (13.4 - 17L255) - com.apple.CoreSimulator.SimRuntime.tvOS-13-4 + // watchOS 6.2 (6.2 - 17T256) - com.apple.CoreSimulator.SimRuntime.watchOS-6-2 + String iOSSimRuntime; + String watchSimRuntime; + + final RegExp iOSRuntimePattern = RegExp(r'iOS .*\) - (.*)'); + final RegExp watchOSRuntimePattern = RegExp(r'watchOS .*\) - (.*)'); + + for (final String runtime in LineSplitter.split(availableRuntimes)) { + // These seem to be in order, so allow matching multiple lines so it grabs + // the last (hopefully latest) one. + final RegExpMatch iOSRuntimeMatch = iOSRuntimePattern.firstMatch(runtime); + if (iOSRuntimeMatch != null) { + iOSSimRuntime = iOSRuntimeMatch.group(1).trim(); + continue; + } + final RegExpMatch watchOSRuntimeMatch = watchOSRuntimePattern.firstMatch(runtime); + if (watchOSRuntimeMatch != null) { + watchSimRuntime = watchOSRuntimeMatch.group(1).trim(); + } + } + if (iOSSimRuntime == null || watchSimRuntime == null) { + String message; + if (iOSSimRuntime != null) { + message = 'Found "$iOSSimRuntime", but no watchOS simulator runtime found.'; + } else if (watchSimRuntime != null) { + message = 'Found "$watchSimRuntime", but no iOS simulator runtime found.'; + } else { + message = 'watchOS and iOS simulator runtimes not found.'; + } + return TaskResult.failure('$message Available runtimes:\n$availableRuntimes'); + } + + // Create iOS simulator. phoneDeviceID = await eval( 'xcrun', [ @@ -82,12 +132,13 @@ Future main() async { 'create', 'TestFlutteriPhoneWithWatch', 'com.apple.CoreSimulator.SimDeviceType.iPhone-11', - 'com.apple.CoreSimulator.SimRuntime.iOS-13-2', + iOSSimRuntime, ], canFail: false, workingDirectory: flutterDirectory.path, ); + // Create watchOS simulator. watchDeviceID = await eval( 'xcrun', [ @@ -95,7 +146,7 @@ Future main() async { 'create', 'TestFlutterWatch', 'com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-5-44mm', - 'com.apple.CoreSimulator.SimRuntime.watchOS-6-1' + watchSimRuntime, ], canFail: false, workingDirectory: flutterDirectory.path,