Fix restart flow for preview-dart-2 mode. (#12496)

* Fix restart flow for preview-dart-2 mode.

Restart in preview-dart-2 needs to use kernel file and it has to be complete, rather than incremental kernel file.

* Add curly braces

* Do full compile on restart

* Roll engine to pick up changes to hot reload for preview-dart-2
This commit is contained in:
Alexander Aprelev 2017-10-12 14:48:37 -07:00 committed by GitHub
parent a4b29d6414
commit 85e4f0526b
5 changed files with 31 additions and 11 deletions

View file

@ -1 +1 @@
2a84f18c795d24ba95baed360fcb58b3dc66d661
248af2d5b6b5a4fd32c87bac68c624a62d8d9432

View file

@ -174,4 +174,11 @@ class ResidentCompiler {
void reject() {
_server.stdin.writeln('reject');
}
/// Should be invoked when frontend server compiler should forget what was
/// accepted previously so that next call to [recompile] produces complete
/// kernel file.
void reset() {
_server.stdin.writeln('reset');
}
}

View file

@ -5,6 +5,7 @@
import 'dart:async';
import 'dart:convert' show BASE64, UTF8;
import 'package:flutter_tools/src/artifacts.dart';
import 'package:json_rpc_2/json_rpc_2.dart' as rpc;
import 'asset.dart';
@ -369,6 +370,7 @@ class DevFS {
bool bundleDirty: false,
Set<String> fileFilter,
ResidentCompiler generator,
bool fullRestart: false,
}) async {
// Mark all entries as possibly deleted.
for (DevFSContent content in _entries.values) {
@ -441,7 +443,11 @@ class DevFS {
if (content is DevFSFileContent)
invalidatedFiles.add(content.file.uri.toString());
printTrace('Compiling dart to kernel with ${invalidatedFiles.length} updated files');
final String compiledBinary = await generator.recompile(mainPath, invalidatedFiles);
final String compiledBinary = fullRestart
? await compile(
sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
mainPath: mainPath)
: await generator.recompile(mainPath, invalidatedFiles);
if (compiledBinary != null && compiledBinary.isNotEmpty)
dirtyEntries.putIfAbsent(
Uri.parse(target + '.dill'),

View file

@ -331,7 +331,8 @@ class FlutterDevice {
String target,
AssetBundle bundle,
bool bundleDirty: false,
Set<String> fileFilter
Set<String> fileFilter,
bool fullRestart: false
}) async {
final Status devFSStatus = logger.startProgress(
'Syncing files to device ${device.name}...',
@ -345,7 +346,8 @@ class FlutterDevice {
bundle: bundle,
bundleDirty: bundleDirty,
fileFilter: fileFilter,
generator: generator
generator: generator,
fullRestart: fullRestart
);
} on DevFSException {
devFSStatus.cancel();

View file

@ -241,7 +241,7 @@ class HotRunner extends ResidentRunner {
return devFSUris;
}
Future<bool> _updateDevFS() async {
Future<bool> _updateDevFS({ bool fullRestart: false }) async {
if (!_refreshDartDependencies()) {
// Did not update DevFS because of a Dart source error.
return false;
@ -261,6 +261,7 @@ class HotRunner extends ResidentRunner {
bundle: assetBundle,
bundleDirty: rebuildBundle,
fileFilter: _dartDependencies,
fullRestart: fullRestart
);
if (!result)
return false;
@ -334,15 +335,19 @@ class HotRunner extends ResidentRunner {
}
final Stopwatch restartTimer = new Stopwatch()..start();
final bool updatedDevFS = await _updateDevFS();
if (previewDart2) {
for (FlutterDevice device in flutterDevices) {
// Reset generator so that full kernel file is produced for VM to
// restart from.
if (device.generator != null)
device.generator.reset();
}
}
final bool updatedDevFS = await _updateDevFS(fullRestart: true);
if (!updatedDevFS)
return new OperationResult(1, 'DevFS synchronization failed');
// Check if the isolate is paused and resume it.
for (FlutterDevice device in flutterDevices) {
// VM must have accepted the kernel binary, there will be no reload
// report, so we let incremental compiler know that source code was accepted.
if (device.generator != null)
device.generator.accept();
for (FlutterView view in device.views) {
if (view.uiIsolate != null) {
// Reload the isolate.
@ -357,7 +362,7 @@ class HotRunner extends ResidentRunner {
}
// We are now running from source.
_runningFromSnapshot = false;
await _launchFromDevFS(mainPath);
await _launchFromDevFS(previewDart2 ? mainPath + '.dill' : mainPath);
restartTimer.stop();
printTrace('Restart performed in '
'${getElapsedAsMilliseconds(restartTimer.elapsed)}.');