From 9f4fdcb866484d22b339b2d001e31f1f05a66ac6 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Wed, 2 Mar 2016 11:40:10 -0800 Subject: [PATCH] iOS Simulator: Attempt 'sideloading' the updated Flutter application if the application runner is already up * This makes the turnaround times < 2 seconds on the iOS simulator. * Also bumps the engine to use the new engine required to support the flags. --- bin/cache/engine.version | 2 +- .../flutter_tools/lib/src/ios/simulators.dart | 88 ++++++++++++++----- 2 files changed, 65 insertions(+), 25 deletions(-) diff --git a/bin/cache/engine.version b/bin/cache/engine.version index 5bfdf957b8..81e7dc7a72 100644 --- a/bin/cache/engine.version +++ b/bin/cache/engine.version @@ -1 +1 @@ -3a48f9c90b6406b10d5a8a1897c147c71ccc59ba +d474e9d2b60a9cb111c09844c10081b68bde9252 diff --git a/packages/flutter_tools/lib/src/ios/simulators.dart b/packages/flutter_tools/lib/src/ios/simulators.dart index 2ee184665d..d8ea7b7143 100644 --- a/packages/flutter_tools/lib/src/ios/simulators.dart +++ b/packages/flutter_tools/lib/src/ios/simulators.dart @@ -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,12 +315,69 @@ class IOSSimulator extends Device { int debugPort: observatoryDefaultPort, Map platformArgs }) async { - // TODO(chinmaygarde): Use mainPath, route. printTrace('Building ${app.name} for $id.'); if (clearLogs) this.clearLogs(); + if(!(await _setupUpdatedApplicationBundle(app, toolchain))) + return false; + + // Prepare launch arguments. + List args = [ + "--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"); + + if (startPaused) + args.add("--start-paused"); + + if (debugPort != observatoryDefaultPort) + args.add("--observatory-port=$debugPort"); + + // Launch the updated application in the simulator. + try { + SimControl.instance.launch(id, app.id, args); + } catch (error) { + printError('$error'); + return false; + } + + printTrace('Successfully started ${app.name} on $id.'); + + 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 _setupUpdatedApplicationBundle(ApplicationPackage app, Toolchain toolchain) async { + if (_applicationIsInstalledAndRunning(app)) { + return _sideloadUpdatedAssetsForInstalledApplicationBundle(app, toolchain); + } else { + return _buildAndInstallApplicationBundle(app); + } + } + + Future _buildAndInstallApplicationBundle(ApplicationPackage app) async { // Step 1: Build the Xcode project. bool buildResult = await buildIOSXcodeProject(app, buildForDevice: false); if (!buildResult) { @@ -337,32 +395,14 @@ class IOSSimulator extends Device { // Step 3: Install the updated bundle to the simulator. SimControl.instance.install(id, path.absolute(bundle.path)); - - // Step 4: Prepare launch arguments. - List args = []; - - if (checked) - args.add("--enable-checked-mode"); - - if (startPaused) - args.add("--start-paused"); - - if (debugPort != observatoryDefaultPort) - args.add("--observatory-port=$debugPort"); - - // Step 5: Launch the updated application in the simulator. - try { - SimControl.instance.launch(id, app.id, args); - } catch (error) { - printError('$error'); - return false; - } - - printTrace('Successfully started ${app.name} on $id.'); - return true; } + Future _sideloadUpdatedAssetsForInstalledApplicationBundle( + ApplicationPackage app, Toolchain toolchain) async { + return (await flx.build(toolchain, precompiledSnapshot: true)) == 0; + } + @override Future stopApp(ApplicationPackage app) async { // Currently we don't have a way to stop an app running on iOS.