Commit 5776c6e3 authored by Devon Carew's avatar Devon Carew

Merge pull request #1327 from devoncarew/ios_simulator_name

parse out the ios simulator device name
parents 51e2a0a2 a14c2d21
...@@ -295,8 +295,9 @@ class IOSSimulator extends Device { ...@@ -295,8 +295,9 @@ class IOSSimulator extends Device {
IOSSimulator device = Device._unique(id ?? defaultDeviceID, (String id) => new IOSSimulator._(id)); IOSSimulator device = Device._unique(id ?? defaultDeviceID, (String id) => new IOSSimulator._(id));
device._name = name; device._name = name;
if (iOSSimulatorPath == null) { if (iOSSimulatorPath == null) {
iOSSimulatorPath = path.join('/Applications', 'iOS Simulator.app', iOSSimulatorPath = path.join(
'Contents', 'MacOS', 'iOS Simulator'); '/Applications', 'iOS Simulator.app', 'Contents', 'MacOS', 'iOS Simulator'
);
} }
device._iOSSimPath = iOSSimulatorPath; device._iOSSimPath = iOSSimulatorPath;
return device; return device;
...@@ -304,23 +305,28 @@ class IOSSimulator extends Device { ...@@ -304,23 +305,28 @@ class IOSSimulator extends Device {
IOSSimulator._(String id) : super._(id); IOSSimulator._(String id) : super._(id);
static String _getRunningSimulatorID([IOSSimulator mockIOS]) { static _IOSSimulatorInfo _getRunningSimulatorInfo([IOSSimulator mockIOS]) {
String xcrunPath = mockIOS != null ? mockIOS.xcrunPath : _xcrunPath; String xcrunPath = mockIOS != null ? mockIOS.xcrunPath : _xcrunPath;
String output = runCheckedSync([xcrunPath, 'simctl', 'list', 'devices']); String output = runCheckedSync([xcrunPath, 'simctl', 'list', 'devices']);
Match match; Match match;
Iterable<Match> matches = new RegExp(r'[^\(]+\(([^\)]+)\) \(Booted\)', /// iPhone 6s Plus (8AC808E1-6BAE-4153-BBC5-77F83814D414) (Booted)
multiLine: true).allMatches(output); Iterable<Match> matches = new RegExp(
r'[\W]*(.*) \(([^\)]+)\) \(Booted\)',
multiLine: true
).allMatches(output);
if (matches.length > 1) { if (matches.length > 1) {
// More than one simulator is listed as booted, which is not allowed but // More than one simulator is listed as booted, which is not allowed but
// sometimes happens erroneously. Kill them all because we don't know // sometimes happens erroneously. Kill them all because we don't know
// which one is actually running. // which one is actually running.
logging.warning('Multiple running simulators were detected, ' logging.warning('Multiple running simulators were detected, '
'which is not supposed to happen.'); 'which is not supposed to happen.');
for (Match m in matches) { for (Match match in matches) {
if (m.groupCount > 0) { if (match.groupCount > 0) {
logging.warning('Killing simulator ${m.group(1)}'); // TODO: We're killing simulator devices inside an accessor method;
runSync([xcrunPath, 'simctl', 'shutdown', m.group(1)]); // we probably shouldn't be changing state here.
logging.warning('Killing simulator ${match.group(1)}');
runSync([xcrunPath, 'simctl', 'shutdown', match.group(2)]);
} }
} }
} else if (matches.length == 1) { } else if (matches.length == 1) {
...@@ -328,7 +334,7 @@ class IOSSimulator extends Device { ...@@ -328,7 +334,7 @@ class IOSSimulator extends Device {
} }
if (match != null && match.groupCount > 0) { if (match != null && match.groupCount > 0) {
return match.group(1); return new _IOSSimulatorInfo(match.group(2), match.group(1));
} else { } else {
logging.info('No running simulators found'); logging.info('No running simulators found');
return null; return null;
...@@ -336,39 +342,33 @@ class IOSSimulator extends Device { ...@@ -336,39 +342,33 @@ class IOSSimulator extends Device {
} }
String _getSimulatorPath() { String _getSimulatorPath() {
String deviceID = id == defaultDeviceID ? _getRunningSimulatorID() : id; String deviceID = id == defaultDeviceID ? _getRunningSimulatorInfo()?.id : id;
String homeDirectory = path.absolute(Platform.environment['HOME']); String homeDirectory = path.absolute(Platform.environment['HOME']);
if (deviceID == null) { if (deviceID == null)
return null; return null;
} return path.join(homeDirectory, 'Library', 'Developer', 'CoreSimulator', 'Devices', deviceID);
return path.join(homeDirectory, 'Library', 'Developer', 'CoreSimulator',
'Devices', deviceID);
} }
String _getSimulatorAppHomeDirectory(ApplicationPackage app) { String _getSimulatorAppHomeDirectory(ApplicationPackage app) {
String simulatorPath = _getSimulatorPath(); String simulatorPath = _getSimulatorPath();
if (simulatorPath == null) { if (simulatorPath == null)
return null; return null;
}
return path.join(simulatorPath, 'data'); return path.join(simulatorPath, 'data');
} }
static List<IOSSimulator> getAttachedDevices([IOSSimulator mockIOS]) { static List<IOSSimulator> getAttachedDevices([IOSSimulator mockIOS]) {
List<IOSSimulator> devices = []; List<IOSSimulator> devices = [];
String id = _getRunningSimulatorID(mockIOS); _IOSSimulatorInfo deviceInfo = _getRunningSimulatorInfo(mockIOS);
if (id != null) { if (deviceInfo != null)
devices.add(new IOSSimulator(id: id)); devices.add(new IOSSimulator(id: deviceInfo.id, name: deviceInfo.name));
}
return devices; return devices;
} }
Future<bool> boot() async { Future<bool> boot() async {
if (!Platform.isMacOS) { if (!Platform.isMacOS)
return false; return false;
} if (isConnected())
if (isConnected()) {
return true; return true;
}
if (id == defaultDeviceID) { if (id == defaultDeviceID) {
runDetached([iOSSimPath]); runDetached([iOSSimPath]);
Future<bool> checkConnection([int attempts = 20]) async { Future<bool> checkConnection([int attempts = 20]) async {
...@@ -397,9 +397,9 @@ class IOSSimulator extends Device { ...@@ -397,9 +397,9 @@ class IOSSimulator extends Device {
@override @override
bool installApp(ApplicationPackage app) { bool installApp(ApplicationPackage app) {
if (!isConnected()) { if (!isConnected())
return false; return false;
}
try { try {
if (id == defaultDeviceID) { if (id == defaultDeviceID) {
runCheckedSync([xcrunPath, 'simctl', 'install', 'booted', app.localPath]); runCheckedSync([xcrunPath, 'simctl', 'install', 'booted', app.localPath]);
...@@ -414,16 +414,15 @@ class IOSSimulator extends Device { ...@@ -414,16 +414,15 @@ class IOSSimulator extends Device {
@override @override
bool isConnected() { bool isConnected() {
if (!Platform.isMacOS) { if (!Platform.isMacOS)
return false; return false;
} _IOSSimulatorInfo deviceInfo = _getRunningSimulatorInfo();
String simulatorID = _getRunningSimulatorID(); if (deviceInfo == null) {
if (simulatorID == null) {
return false; return false;
} else if (id == defaultDeviceID) { } else if (deviceInfo.id == defaultDeviceID) {
return true; return true;
} else { } else {
return _getRunningSimulatorID() == id; return _getRunningSimulatorInfo()?.id == id;
} }
} }
...@@ -498,8 +497,7 @@ class IOSSimulator extends Device { ...@@ -498,8 +497,7 @@ class IOSSimulator extends Device {
ApplicationPackage app, String localFile, String targetFile) async { ApplicationPackage app, String localFile, String targetFile) async {
if (Platform.isMacOS) { if (Platform.isMacOS) {
String simulatorHomeDirectory = _getSimulatorAppHomeDirectory(app); String simulatorHomeDirectory = _getSimulatorAppHomeDirectory(app);
runCheckedSync( runCheckedSync(['cp', localFile, path.join(simulatorHomeDirectory, targetFile)]);
['cp', localFile, path.join(simulatorHomeDirectory, targetFile)]);
return true; return true;
} }
return false; return false;
...@@ -509,21 +507,31 @@ class IOSSimulator extends Device { ...@@ -509,21 +507,31 @@ class IOSSimulator extends Device {
TargetPlatform get platform => TargetPlatform.iOSSimulator; TargetPlatform get platform => TargetPlatform.iOSSimulator;
Future<int> logs({bool clear: false}) async { Future<int> logs({bool clear: false}) async {
if (!isConnected()) { if (!isConnected())
return 2; return 2;
}
String homeDirectory = path.absolute(Platform.environment['HOME']); String homeDirectory = path.absolute(Platform.environment['HOME']);
String simulatorDeviceID = _getRunningSimulatorID(); String simulatorDeviceID = _getRunningSimulatorInfo().id;
String logFilePath = path.join(homeDirectory, 'Library', 'Logs', String logFilePath = path.join(
'CoreSimulator', simulatorDeviceID, 'system.log'); homeDirectory, 'Library', 'Logs', 'CoreSimulator', simulatorDeviceID, 'system.log'
if (clear) { );
if (clear)
runSync(['rm', logFilePath]); runSync(['rm', logFilePath]);
} return await runCommandAndStreamOutput(
return await runCommandAndStreamOutput(['tail', '-f', logFilePath], ['tail', '-f', logFilePath],
prefix: 'iOS sim: ', filter: new RegExp(r'.*SkyShell.*')); prefix: 'iOS sim: ',
filter: new RegExp(r'.*SkyShell.*')
);
} }
} }
class _IOSSimulatorInfo {
final String id;
final String name;
_IOSSimulatorInfo(this.id, this.name);
}
class AndroidDevice extends Device { class AndroidDevice extends Device {
static const int minApiLevel = 16; static const int minApiLevel = 16;
static const String minVersionName = 'Jelly Bean'; static const String minVersionName = 'Jelly Bean';
......
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