From 225686b1a70b75f9d0476225cfafc407d5d76bc8 Mon Sep 17 00:00:00 2001 From: Yegor Jbanov Date: Mon, 14 Mar 2016 22:31:32 -0700 Subject: [PATCH] [ios] improve test device naming The new name format is "DEVICE_TYPE_NAME (Flutter)". For example: iPhone 6 (Flutter) iPhone 6s Plus (Flutter) The names are taken from `xcrun simctl list --json devicetypes`. Fixes #2682 --- .../flutter_tools/lib/src/ios/simulators.dart | 42 +++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/packages/flutter_tools/lib/src/ios/simulators.dart b/packages/flutter_tools/lib/src/ios/simulators.dart index 962364286c..fe02d31f8f 100644 --- a/packages/flutter_tools/lib/src/ios/simulators.dart +++ b/packages/flutter_tools/lib/src/ios/simulators.dart @@ -22,7 +22,7 @@ import 'mac.dart'; const String _xcrunPath = '/usr/bin/xcrun'; /// Test device created by Flutter when no other device is available. -const String _kFlutterTestDevice = 'flutter.test.device'; +const String _kFlutterTestDeviceSuffix = '(Flutter)'; class IOSSimulators extends PollingDeviceDiscovery { IOSSimulators() : super('IOSSimulators'); @@ -97,7 +97,7 @@ class SimControl { } SimDevice _createTestDevice() { - String deviceType = _findSuitableDeviceType(); + SimDeviceType deviceType = _findSuitableDeviceType(); if (deviceType == null) { return null; } @@ -109,18 +109,19 @@ class SimControl { // Delete any old test devices getDevices() - .where((SimDevice d) => d.name == _kFlutterTestDevice) + .where((SimDevice d) => d.name.endsWith(_kFlutterTestDeviceSuffix)) .forEach(_deleteDevice); // Create new device - List args = [_xcrunPath, 'simctl', 'create', _kFlutterTestDevice, deviceType, runtime]; + String deviceName = '${deviceType.name} $_kFlutterTestDeviceSuffix'; + List args = [_xcrunPath, 'simctl', 'create', deviceName, deviceType.identifier, runtime]; printTrace(args.join(' ')); runCheckedSync(args); - return getDevices().firstWhere((SimDevice d) => d.name == _kFlutterTestDevice); + return getDevices().firstWhere((SimDevice d) => d.name == deviceName); } - String _findSuitableDeviceType() { + SimDeviceType _findSuitableDeviceType() { List> allTypes = _list(SimControlListSection.devicetypes); List> usableTypes = allTypes .where((Map info) => info['name'].startsWith('iPhone')) @@ -136,7 +137,10 @@ class SimControl { ); } - return usableTypes.first['identifier']; + return new SimDeviceType( + usableTypes.first['name'], + usableTypes.first['identifier'] + ); } String _findSuitableRuntime() { @@ -300,6 +304,30 @@ class SimControlListSection { static const SimControlListSection pairs = const SimControlListSection._('pairs'); } +/// A simulated device type. +/// +/// Simulated device types can be listed using the command +/// `xcrun simctl list devicetypes`. +class SimDeviceType { + SimDeviceType(this.name, this.identifier); + + /// The name of the device type. + /// + /// Examples: + /// + /// "iPhone 6s" + /// "iPhone 6 Plus" + final String name; + + /// The identifier of the device type. + /// + /// Examples: + /// + /// "com.apple.CoreSimulator.SimDeviceType.iPhone-6s" + /// "com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus" + final String identifier; +} + class SimDevice { SimDevice(this.category, this.data);