Skip to content

Commit 6d8ec35

Browse files
Revert "Revert "[flutter_tools] always initialize the resident runner from di…" (flutter#58208)
1 parent cd593da commit 6d8ec35

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

packages/flutter_tools/lib/src/resident_runner.dart

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import 'base/utils.dart';
2323
import 'build_info.dart';
2424
import 'build_system/build_system.dart';
2525
import 'build_system/targets/localizations.dart';
26+
import 'bundle.dart';
2627
import 'cache.dart';
2728
import 'codegen.dart';
2829
import 'compile.dart';
@@ -83,6 +84,12 @@ class FlutterDevice {
8384
if (device.platformType == PlatformType.fuchsia) {
8485
targetModel = TargetModel.flutterRunner;
8586
}
87+
// For both web and non-web platforms we initialize dill to/from
88+
// a shared location for faster bootstrapping. If the compiler fails
89+
// due to a kernel target or version mismatch, no error is reported
90+
// and the compiler starts up as normal. Unexpected errors will print
91+
// a warning message and dump some debug information which can be
92+
// used to file a bug, but the compiler will still start up correctly.
8693
if (targetPlatform == TargetPlatform.web_javascript) {
8794
generator = ResidentCompiler(
8895
globals.artifacts.getArtifactPath(Artifact.flutterWebSdk, mode: buildInfo.mode),
@@ -95,6 +102,9 @@ class FlutterDevice {
95102
compilerMessageConsumer:
96103
(String message, {bool emphasis, TerminalColor color, }) =>
97104
globals.printTrace(message),
105+
initializeFromDill: getDefaultCachedKernelPath(
106+
trackWidgetCreation: buildInfo.trackWidgetCreation,
107+
),
98108
targetModel: TargetModel.dartdevc,
99109
experimentalFlags: experimentalFlags,
100110
platformDill: globals.fs.file(globals.artifacts
@@ -119,6 +129,9 @@ class FlutterDevice {
119129
targetModel: targetModel,
120130
experimentalFlags: experimentalFlags,
121131
dartDefines: buildInfo.dartDefines,
132+
initializeFromDill: getDefaultCachedKernelPath(
133+
trackWidgetCreation: buildInfo.trackWidgetCreation,
134+
),
122135
packagesPath: globalPackagesPath,
123136
);
124137
}
@@ -691,7 +704,6 @@ abstract class ResidentRunner {
691704
final bool ipv6;
692705
final String _dillOutputPath;
693706
/// The parent location of the incremental artifacts.
694-
@visibleForTesting
695707
final Directory artifactDirectory;
696708
final String packagesFilePath;
697709
final String projectRootPath;
@@ -1196,6 +1208,12 @@ abstract class ResidentRunner {
11961208
Future<void> preExit() async {
11971209
// If _dillOutputPath is null, we created a temporary directory for the dill.
11981210
if (_dillOutputPath == null && artifactDirectory.existsSync()) {
1211+
final File outputDill = globals.fs.file(dillOutputPath);
1212+
if (outputDill.existsSync()) {
1213+
outputDill.copySync(getDefaultCachedKernelPath(
1214+
trackWidgetCreation: trackWidgetCreation,
1215+
));
1216+
}
11991217
artifactDirectory.deleteSync(recursive: true);
12001218
}
12011219
}

packages/flutter_tools/test/general.shard/resident_runner_test.dart

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
import 'dart:async';
66

7-
import 'package:file_testing/file_testing.dart';
87
import 'package:flutter_tools/src/cache.dart';
98
import 'package:vm_service/vm_service.dart' as vm_service;
109
import 'package:file/memory.dart';
10+
import 'package:file_testing/file_testing.dart';
1111
import 'package:flutter_tools/src/artifacts.dart';
1212
import 'package:flutter_tools/src/base/command_help.dart';
1313
import 'package:flutter_tools/src/base/common.dart';
@@ -521,6 +521,24 @@ void main() {
521521
expect(otherRunner.artifactDirectory.path, contains('foobar'));
522522
}));
523523

524+
test('ResidentRunner copies output dill to cache location during preExit', () => testbed.run(() async {
525+
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
526+
residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('hello');
527+
await residentRunner.preExit();
528+
final File cacheDill = globals.fs.file(globals.fs.path.join(getBuildDirectory(), 'cache.dill'));
529+
530+
expect(cacheDill, exists);
531+
expect(cacheDill.readAsStringSync(), 'hello');
532+
}));
533+
534+
test('ResidentRunner handles output dill missing during preExit', () => testbed.run(() async {
535+
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
536+
await residentRunner.preExit();
537+
final File cacheDill = globals.fs.file(globals.fs.path.join(getBuildDirectory(), 'cache.dill'));
538+
539+
expect(cacheDill, isNot(exists));
540+
}));
541+
524542
test('ResidentRunner can run source generation', () => testbed.run(() async {
525543
final FakeProcessManager processManager = globals.processManager as FakeProcessManager;
526544
final Directory dependencies = globals.fs.directory(
@@ -1140,6 +1158,8 @@ void main() {
11401158
target: null,
11411159
)).generator as DefaultResidentCompiler;
11421160

1161+
expect(residentCompiler.initializeFromDill,
1162+
globals.fs.path.join(getBuildDirectory(), 'cache.dill'));
11431163
expect(residentCompiler.librariesSpec,
11441164
globals.fs.file(globals.artifacts.getArtifactPath(Artifact.flutterWebLibrariesJson))
11451165
.uri.toString());

0 commit comments

Comments
 (0)