Commit cd0ddce9 authored by Yegor's avatar Yegor

Merge pull request #2402 from yjbanov/use-xcrun

[ios] use xcrun to launch simulator instead of hardcoded path
parents e321e431 e69f6562
...@@ -21,9 +21,6 @@ import 'mac.dart'; ...@@ -21,9 +21,6 @@ import 'mac.dart';
const String _xcrunPath = '/usr/bin/xcrun'; const String _xcrunPath = '/usr/bin/xcrun';
const String _simulatorPath =
'/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator';
class IOSSimulators extends PollingDeviceDiscovery { class IOSSimulators extends PollingDeviceDiscovery {
IOSSimulators() : super('IOSSimulators'); IOSSimulators() : super('IOSSimulators');
...@@ -56,33 +53,34 @@ class SimControl { ...@@ -56,33 +53,34 @@ class SimControl {
if (_isAnyConnected()) if (_isAnyConnected())
return true; return true;
if (deviceId == null) { if (deviceId == null)
runDetached([_simulatorPath]); deviceId = 'iPhone 6 (9.2)';
Future<bool> checkConnection([int attempts = 20]) async {
if (attempts == 0) { // `xcrun instruments` requires a template (-t). @yjbanov has no idea what
printStatus('Timed out waiting for iOS Simulator to boot.'); // "template" is but the built-in 'Blank' seems to work.
return false; List<String> args = [_xcrunPath, 'instruments', '-w', deviceId, '-t', 'Blank'];
} printTrace(args.join(' '));
if (!_isAnyConnected()) { runDetached(args);
printStatus('Waiting for iOS Simulator to boot...'); printStatus('Waiting for iOS Simulator to boot...');
return await new Future.delayed(new Duration(milliseconds: 500),
() => checkConnection(attempts - 1) bool connected = false;
); int attempted = 0;
} while (!connected && attempted < 20) {
return true; connected = await _isAnyConnected();
} if (!connected) {
return await checkConnection(); printStatus('Still waiting for iOS Simulator to boot...');
} else { await new Future.delayed(new Duration(seconds: 1));
try {
runCheckedSync([_xcrunPath, 'simctl', 'boot', deviceId]);
return true;
} catch (e) {
printError('Unable to boot iOS Simulator $deviceId: ', e);
return false;
} }
attempted++;
} }
return false; if (connected) {
printStatus('Connected to iOS Simulator.');
return true;
} else {
printStatus('Timed out waiting for iOS Simulator to boot.');
return false;
}
} }
/// Returns a list of all available devices, both potential and connected. /// Returns a list of all available devices, both potential and connected.
......
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