Commit e802858b authored by Eric Seidel's avatar Eric Seidel

Merge pull request #2329 from chinmaygarde/master

iOS Simulator: Attempt 'sideloading' the updated Flutter application if the application runner is already up
parents d9d94b16 9f4fdcb8
3a48f9c90b6406b10d5a8a1897c147c71ccc59ba
d474e9d2b60a9cb111c09844c10081b68bde9252
......@@ -14,6 +14,7 @@ import '../base/context.dart';
import '../base/process.dart';
import '../build_configuration.dart';
import '../device.dart';
import '../flx.dart' as flx;
import '../globals.dart';
import '../toolchain.dart';
import 'mac.dart';
......@@ -314,32 +315,20 @@ class IOSSimulator extends Device {
int debugPort: observatoryDefaultPort,
Map<String, dynamic> platformArgs
}) async {
// TODO(chinmaygarde): Use mainPath, route.
printTrace('Building ${app.name} for $id.');
if (clearLogs)
this.clearLogs();
// Step 1: Build the Xcode project.
bool buildResult = await buildIOSXcodeProject(app, buildForDevice: false);
if (!buildResult) {
printError('Could not build the application for the simulator.');
return false;
}
// 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) {
printError('Could not find the built application bundle at ${bundle.path}.');
if(!(await _setupUpdatedApplicationBundle(app, toolchain)))
return false;
}
// Step 3: Install the updated bundle to the simulator.
SimControl.instance.install(id, path.absolute(bundle.path));
// Step 4: Prepare launch arguments.
List<String> args = <String>[];
// Prepare launch arguments.
List<String> args = <String>[
"--flx=${path.absolute(path.join('build', 'app.flx'))}",
"--dart-main=${path.absolute(mainPath)}",
"--package-root=${path.absolute('packages')}",
];
if (checked)
args.add("--enable-checked-mode");
......@@ -350,7 +339,7 @@ class IOSSimulator extends Device {
if (debugPort != observatoryDefaultPort)
args.add("--observatory-port=$debugPort");
// Step 5: Launch the updated application in the simulator.
// Launch the updated application in the simulator.
try {
SimControl.instance.launch(id, app.id, args);
} catch (error) {
......@@ -363,6 +352,57 @@ class IOSSimulator extends Device {
return true;
}
bool _applicationIsInstalledAndRunning(ApplicationPackage app) {
bool isInstalled = exitsHappy([
'xcrun',
'simctl',
'get_app_container',
'booted',
app.id,
]);
bool isRunning = exitsHappy([
'/usr/bin/killall',
'Runner',
]);
return isInstalled && isRunning;
}
Future<bool> _setupUpdatedApplicationBundle(ApplicationPackage app, Toolchain toolchain) async {
if (_applicationIsInstalledAndRunning(app)) {
return _sideloadUpdatedAssetsForInstalledApplicationBundle(app, toolchain);
} else {
return _buildAndInstallApplicationBundle(app);
}
}
Future<bool> _buildAndInstallApplicationBundle(ApplicationPackage app) async {
// Step 1: Build the Xcode project.
bool buildResult = await buildIOSXcodeProject(app, buildForDevice: false);
if (!buildResult) {
printError('Could not build the application for the simulator.');
return false;
}
// 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) {
printError('Could not find the built application bundle at ${bundle.path}.');
return false;
}
// Step 3: Install the updated bundle to the simulator.
SimControl.instance.install(id, path.absolute(bundle.path));
return true;
}
Future<bool> _sideloadUpdatedAssetsForInstalledApplicationBundle(
ApplicationPackage app, Toolchain toolchain) async {
return (await flx.build(toolchain, precompiledSnapshot: true)) == 0;
}
@override
Future<bool> stopApp(ApplicationPackage app) async {
// Currently we don't have a way to stop an app running on iOS.
......
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