Skip to content

Ensure simulator used in flutter framework tests is compatible with Xcode version #139917

@vashworth

Description

@vashworth

With macOS 13, simulators are handled separately from Xcode. So it's possible to have a newer simulator available that's not compatible with the selected version of Xcode.

For example, iOS 17 can be available even if Xcode 14 is selected.

So when you do xcrun simctl list runtimes, iOS 17 will be listed.

This is potential problem because we use the greatest runtime from xcrun simctl list runtimes to create a simulator and run tests on it.

Future<void> testWithNewIOSSimulator(
String deviceName,
SimulatorFunction testFunction, {
String deviceTypeId = 'com.apple.CoreSimulator.SimDeviceType.iPhone-11',
}) 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(
'xcrun',
<String>[
'simctl',
'list',
'runtimes',
],
workingDirectory: flutterDirectory.path,
);
String? iOSSimRuntime;
final RegExp iOSRuntimePattern = RegExp(r'iOS .*\) - (.*)');
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;
}
}
if (iOSSimRuntime == null) {
throw 'No iOS simulator runtime found. Available runtimes:\n$availableRuntimes';
}
final String deviceId = await eval(
'xcrun',
<String>[
'simctl',
'create',
deviceName,
deviceTypeId,
iOSSimRuntime,
],
workingDirectory: flutterDirectory.path,
);
await eval(
'xcrun',
<String>[
'simctl',
'boot',
deviceId,
],
workingDirectory: flutterDirectory.path,
);
await testFunction(deviceId);
}

For Xcode 14, we want an iOS 16 simulator to be used, not iOS 17.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listplatform-iosiOS applications specificallyteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions