Unverified Commit 410af14f authored by Victoria Ashworth's avatar Victoria Ashworth Committed by GitHub

Select simulator runtime for tests based on Xcode's preferred runtime build (#139919)

When creating a simulator for a test, select the runtime based on the selected Xcode's preferred build. This is to prevent it from using a runtime greater than its greatest supported version.

Fixes https://github.com/flutter/flutter/issues/139917.

Example test with both iOS 16 and 17 available: https://chromium-swarm.appspot.com/task?id=6672aca184395a10
parent da202622
...@@ -56,8 +56,6 @@ Future<void> testWithNewIOSSimulator( ...@@ -56,8 +56,6 @@ Future<void> testWithNewIOSSimulator(
SimulatorFunction testFunction, { SimulatorFunction testFunction, {
String deviceTypeId = 'com.apple.CoreSimulator.SimDeviceType.iPhone-11', String deviceTypeId = 'com.apple.CoreSimulator.SimDeviceType.iPhone-11',
}) async { }) async {
// 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( final String availableRuntimes = await eval(
'xcrun', 'xcrun',
<String>[ <String>[
...@@ -68,11 +66,48 @@ Future<void> testWithNewIOSSimulator( ...@@ -68,11 +66,48 @@ Future<void> testWithNewIOSSimulator(
workingDirectory: flutterDirectory.path, workingDirectory: flutterDirectory.path,
); );
final String runtimesForSelectedXcode = await eval(
'xcrun',
<String>[
'simctl',
'runtime',
'match',
'list',
'--json',
],
workingDirectory: flutterDirectory.path,
);
// Get the preferred runtime build for the selected Xcode version. Preferred
// means the runtime was either bundled with Xcode, exactly matched your SDK
// version, or it's indicated a better match for your SDK.
final Map<String, Object?> decodeResult = json.decode(runtimesForSelectedXcode) as Map<String, Object?>;
final String? iosKey = decodeResult.keys
.where((String key) => key.contains('iphoneos'))
.firstOrNull;
final Object? iosDetails = decodeResult[iosKey];
String? runtimeBuildForSelectedXcode;
if (iosDetails != null && iosDetails is Map<String, Object?>) {
final Object? preferredBuild = iosDetails['preferredBuild'];
if (preferredBuild is String) {
runtimeBuildForSelectedXcode = preferredBuild;
}
}
String? iOSSimRuntime; String? iOSSimRuntime;
final RegExp iOSRuntimePattern = RegExp(r'iOS .*\) - (.*)'); final RegExp iOSRuntimePattern = RegExp(r'iOS .*\) - (.*)');
// [availableRuntimes] may include runtime versions greater than the selected
// Xcode's greatest supported version. Use [runtimeBuildForSelectedXcode] when
// possible to pick which runtime to use.
// For example, iOS 17 (released with Xcode 15) may be available even if the
// selected Xcode version is 14.
for (final String runtime in LineSplitter.split(availableRuntimes)) { for (final String runtime in LineSplitter.split(availableRuntimes)) {
if (runtimeBuildForSelectedXcode != null &&
!runtime.contains(runtimeBuildForSelectedXcode)) {
continue;
}
// These seem to be in order, so allow matching multiple lines so it grabs // These seem to be in order, so allow matching multiple lines so it grabs
// the last (hopefully latest) one. // the last (hopefully latest) one.
final RegExpMatch? iOSRuntimeMatch = iOSRuntimePattern.firstMatch(runtime); final RegExpMatch? iOSRuntimeMatch = iOSRuntimePattern.firstMatch(runtime);
...@@ -82,8 +117,12 @@ Future<void> testWithNewIOSSimulator( ...@@ -82,8 +117,12 @@ Future<void> testWithNewIOSSimulator(
} }
} }
if (iOSSimRuntime == null) { if (iOSSimRuntime == null) {
if (runtimeBuildForSelectedXcode != null) {
throw 'iOS simulator runtime $runtimeBuildForSelectedXcode not found. Available runtimes:\n$availableRuntimes';
} else {
throw 'No iOS simulator runtime found. Available runtimes:\n$availableRuntimes'; throw 'No iOS simulator runtime found. Available runtimes:\n$availableRuntimes';
} }
}
final String deviceId = await eval( final String deviceId = await eval(
'xcrun', 'xcrun',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment