Commit 602a3561 authored by Chinmay Garde's avatar Chinmay Garde

Update `flutter start` for iOS simulator

parent 02f423f5
...@@ -187,20 +187,12 @@ class IOSDevice extends Device { ...@@ -187,20 +187,12 @@ class IOSDevice extends Device {
return false; return false;
} }
Future<bool> buildPrecompiledApplication(ApplicationPackage app) async {
int result = await runCommandAndStreamOutput([
'/usr/bin/env', 'xcrun', 'xcodebuild', '-target', 'Runner', '-configuration', 'Release'
], workingDirectory: app.localPath);
return result == 0;
}
@override @override
Future<bool> startApp(ApplicationPackage app) async { Future<bool> startApp(ApplicationPackage app) async {
logging.fine("Attempting to build and install ${app.name} on $id"); logging.fine("Attempting to build and install ${app.name} on $id");
// Step 1: Install the precompiled application if necessary // Step 1: Install the precompiled application if necessary
bool buildResult = await buildPrecompiledApplication(app); bool buildResult = await _buildIOSXcodeProject(app, true);
if (!buildResult) { if (!buildResult) {
logging.severe('Could not build the precompiled application for the device'); logging.severe('Could not build the precompiled application for the device');
...@@ -257,11 +249,6 @@ class IOSDevice extends Device { ...@@ -257,11 +249,6 @@ class IOSDevice extends Device {
]); ]);
return true; return true;
} else { } else {
// TODO(iansf): It may be possible to make this work on Linux. Since this
// functionality appears to be the only that prevents us from
// supporting iOS on Linux, it may be worth putting some time
// into investigating this.
// See https://bbs.archlinux.org/viewtopic.php?id=192655
return false; return false;
} }
return false; return false;
...@@ -364,8 +351,6 @@ class IOSSimulator extends Device { ...@@ -364,8 +351,6 @@ class IOSSimulator extends Device {
List<IOSSimulator> devices = []; List<IOSSimulator> devices = [];
String id = _getRunningSimulatorID(mockIOS); String id = _getRunningSimulatorID(mockIOS);
if (id != null) { if (id != null) {
// TODO(iansf): get the simulator's name
// String name = _getDeviceName(id, mockIOS);
devices.add(new IOSSimulator(id: id)); devices.add(new IOSSimulator(id: id));
} }
return devices; return devices;
...@@ -448,20 +433,53 @@ class IOSSimulator extends Device { ...@@ -448,20 +433,53 @@ class IOSSimulator extends Device {
@override @override
Future<bool> startApp(ApplicationPackage app) async { Future<bool> startApp(ApplicationPackage app) async {
if (!isAppInstalled(app)) { logging.fine('Building ${app.name} for ${id}');
// Step 1: Build the Xcode project
bool buildResult = await _buildIOSXcodeProject(app, false);
if (!buildResult) {
logging.severe('Could not build the application for the simulator');
return false; return false;
} }
try {
if (id == defaultDeviceID) { // Step 2: Assert that the Xcode project was successfully built
runCheckedSync( Directory bundle = new Directory(path.join(app.localPath, 'build', 'Release-iphonesimulator', 'Runner.app'));
[xcrunPath, 'simctl', 'launch', 'booted', app.id]); bool bundleExists = await bundle.exists();
} else { if (!bundleExists) {
runCheckedSync([xcrunPath, 'simctl', 'launch', id, app.id]); logging.severe('Could not find the built application bundle at ${bundle.path}');
} return false;
return true; }
} catch (e) {
// Step 3: Install the updated bundle to the simulator
int installResult = await runCommandAndStreamOutput([
xcrunPath,
'simctl',
'install',
id == defaultDeviceID ? 'booted' : id,
path.absolute(bundle.path)
]);
if (installResult != 0) {
logging.severe('Could not install the application bundle on the simulator');
return false;
}
// Step 4: Launch the updated application in the simulator
int launchResult = await runCommandAndStreamOutput([
xcrunPath,
'simctl',
'launch',
id == defaultDeviceID ? 'booted' : id,
app.id
]);
if (launchResult != 0) {
logging.severe('Could not launch the freshly installed application on the simulator');
return false; return false;
} }
logging.fine('Successfully started ${app.name} on $id');
return true;
} }
@override @override
...@@ -1038,7 +1056,11 @@ class DeviceStore { ...@@ -1038,7 +1056,11 @@ class DeviceStore {
break; break;
case TargetPlatform.iOSSimulator: case TargetPlatform.iOSSimulator:
assert(iOSSimulator == null); assert(iOSSimulator == null);
iOSSimulator = new IOSSimulator(); iOSSimulator = _deviceForConfig(config, IOSSimulator.getAttachedDevices());
if (iOSSimulator == null) {
// Creates a simulator with the default identifier
iOSSimulator = new IOSSimulator();
}
break; break;
case TargetPlatform.mac: case TargetPlatform.mac:
case TargetPlatform.linux: case TargetPlatform.linux:
...@@ -1049,3 +1071,17 @@ class DeviceStore { ...@@ -1049,3 +1071,17 @@ class DeviceStore {
return new DeviceStore(android: android, iOS: iOS, iOSSimulator: iOSSimulator); return new DeviceStore(android: android, iOS: iOS, iOSSimulator: iOSSimulator);
} }
} }
Future<bool> _buildIOSXcodeProject(ApplicationPackage app, bool isDevice) async {
List<String> command = [
'/usr/bin/env', 'xcrun', 'xcodebuild', '-target', 'Runner', '-configuration', 'Release'
];
if (!isDevice) {
command.addAll(['-sdk', 'iphonesimulator']);
}
int result = await runCommandAndStreamOutput(command,
workingDirectory: app.localPath);
return result == 0;
}
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