diff --git a/packages/flutter_tools/lib/src/compile.dart b/packages/flutter_tools/lib/src/compile.dart index a65a876a94..2ee9cbe132 100644 --- a/packages/flutter_tools/lib/src/compile.dart +++ b/packages/flutter_tools/lib/src/compile.dart @@ -468,7 +468,6 @@ abstract class ResidentCompiler { List dartDefines, }) = DefaultResidentCompiler; - /// If invoked for the first time, it compiles Dart script identified by /// [mainPath], [invalidatedFiles] list is ignored. /// On successive runs [invalidatedFiles] indicates which files need to be diff --git a/packages/flutter_tools/lib/src/devfs.dart b/packages/flutter_tools/lib/src/devfs.dart index 129c09baa2..1616dfa399 100644 --- a/packages/flutter_tools/lib/src/devfs.dart +++ b/packages/flutter_tools/lib/src/devfs.dart @@ -487,6 +487,9 @@ class DevFS { if (fullRestart) { generator.reset(); } + // On a full restart, or on an initial compile for the attach based workflow, + // this will produce a full dill. Subsequent invocations will produce incremental + // dill files that depend on the invalidated files. printTrace('Compiling dart to kernel with ${invalidatedFiles.length} updated files'); final CompilerOutput compilerOutput = await generator.recompile( mainPath, diff --git a/packages/flutter_tools/lib/src/run_hot.dart b/packages/flutter_tools/lib/src/run_hot.dart index 649e3265e3..c369858931 100644 --- a/packages/flutter_tools/lib/src/run_hot.dart +++ b/packages/flutter_tools/lib/src/run_hot.dart @@ -18,6 +18,7 @@ import 'base/platform.dart'; import 'base/terminal.dart'; import 'base/utils.dart'; import 'build_info.dart'; +import 'bundle.dart'; import 'compile.dart'; import 'convert.dart'; import 'devfs.dart'; @@ -262,14 +263,31 @@ class HotRunner extends ResidentRunner { firstBuildTime = DateTime.now(); + final List> startupTasks = >[]; for (FlutterDevice device in flutterDevices) { - final int result = await device.runHot( + // Here we initialize the frontend_server conccurently with the gradle + // build, reducing initialization time. This is safe because the first + // invocation of the frontend server produces a full dill file that + // the subsequent invocation in devfs will not overwrite. + if (device.generator != null) { + startupTasks.add( + device.generator.recompile( + mainPath, + [], + outputPath: dillOutputPath ?? + getDefaultApplicationKernelPath(trackWidgetCreation: device.trackWidgetCreation), + packagesFilePath : packagesFilePath, + ).then((CompilerOutput output) => output?.errorCount == 0) + ); + } + startupTasks.add(device.runHot( hotRunner: this, route: route, - ); - if (result != 0) { - return result; - } + ).then((int result) => result == 0)); + } + final List results = await Future.wait(startupTasks); + if (!results.every((bool passed) => passed)) { + return 1; } return attach( diff --git a/packages/flutter_tools/test/integration.shard/hot_reload_test.dart b/packages/flutter_tools/test/integration.shard/hot_reload_test.dart index 2d7d3cd7aa..59ac90682f 100644 --- a/packages/flutter_tools/test/integration.shard/hot_reload_test.dart +++ b/packages/flutter_tools/test/integration.shard/hot_reload_test.dart @@ -108,13 +108,18 @@ void main() { }); test('hot reload doesn\'t reassemble if paused', () async { - await _flutter.run(withDebugger: true); + final Future setup = _flutter.run(withDebugger: true); + final Completer sawTick1 = Completer(); final Completer sawTick2 = Completer(); final Completer sawTick3 = Completer(); final Completer sawDebuggerPausedMessage1 = Completer(); final Completer sawDebuggerPausedMessage2 = Completer(); final StreamSubscription subscription = _flutter.stdout.listen( (String line) { + if (line.contains('((((TICK 1))))')) { + expect(sawTick1.isCompleted, isFalse); + sawTick1.complete(); + } if (line.contains('((((TICK 2))))')) { expect(sawTick2.isCompleted, isFalse); sawTick2.complete(); @@ -129,6 +134,8 @@ void main() { } }, ); + await setup; + await sawTick1.future; await _flutter.addBreakpoint( _project.buildBreakpointUri, _project.buildBreakpointLine,