forked from firka/flutter
Update flutter start for iOS simulator
This commit is contained in:
@@ -187,20 +187,12 @@ class IOSDevice extends Device {
|
||||
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
|
||||
Future<bool> startApp(ApplicationPackage app) async {
|
||||
logging.fine("Attempting to build and install ${app.name} on $id");
|
||||
|
||||
// Step 1: Install the precompiled application if necessary
|
||||
bool buildResult = await buildPrecompiledApplication(app);
|
||||
bool buildResult = await _buildIOSXcodeProject(app, true);
|
||||
|
||||
if (!buildResult) {
|
||||
logging.severe('Could not build the precompiled application for the device');
|
||||
@@ -257,11 +249,6 @@ class IOSDevice extends Device {
|
||||
]);
|
||||
return true;
|
||||
} 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;
|
||||
@@ -364,8 +351,6 @@ class IOSSimulator extends Device {
|
||||
List<IOSSimulator> devices = [];
|
||||
String id = _getRunningSimulatorID(mockIOS);
|
||||
if (id != null) {
|
||||
// TODO(iansf): get the simulator's name
|
||||
// String name = _getDeviceName(id, mockIOS);
|
||||
devices.add(new IOSSimulator(id: id));
|
||||
}
|
||||
return devices;
|
||||
@@ -448,20 +433,53 @@ class IOSSimulator extends Device {
|
||||
|
||||
@override
|
||||
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;
|
||||
}
|
||||
try {
|
||||
if (id == defaultDeviceID) {
|
||||
runCheckedSync(
|
||||
[xcrunPath, 'simctl', 'launch', 'booted', app.id]);
|
||||
} else {
|
||||
runCheckedSync([xcrunPath, 'simctl', 'launch', id, app.id]);
|
||||
}
|
||||
return true;
|
||||
} catch (e) {
|
||||
|
||||
// Step 2: Assert that the Xcode project was successfully built
|
||||
Directory bundle = new Directory(path.join(app.localPath, 'build', 'Release-iphonesimulator', 'Runner.app'));
|
||||
bool bundleExists = await bundle.exists();
|
||||
if (!bundleExists) {
|
||||
logging.severe('Could not find the built application bundle at ${bundle.path}');
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
logging.fine('Successfully started ${app.name} on $id');
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -1038,7 +1056,11 @@ class DeviceStore {
|
||||
break;
|
||||
case TargetPlatform.iOSSimulator:
|
||||
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;
|
||||
case TargetPlatform.mac:
|
||||
case TargetPlatform.linux:
|
||||
@@ -1049,3 +1071,17 @@ class DeviceStore {
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user