Skip to content

Commit c543db7

Browse files
author
Jonah Williams
authored
[flutter_tools] add null-safety flags to dill cache location (flutter#60633)
initialize from dill does not handle changing null-safety flags and will incorrectly use the nullability mode of the last compile. Add all extra frontend options to the unique name prefix for the flutter run dill cache to avoid this situation.
1 parent 79a2d77 commit c543db7

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

packages/flutter_tools/lib/src/bundle.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ String getDefaultApplicationKernelPath({ @required bool trackWidgetCreation }) {
3939
String getDefaultCachedKernelPath({
4040
@required bool trackWidgetCreation,
4141
@required List<String> dartDefines,
42+
@required List<String> extraFrontEndOptions,
4243
}) {
4344
final StringBuffer buffer = StringBuffer();
4445
buffer.writeAll(dartDefines);
46+
buffer.writeAll(extraFrontEndOptions ?? <String>[]);
4547
String buildPrefix = '';
4648
if (buffer.isNotEmpty) {
4749
final String output = buffer.toString();

packages/flutter_tools/lib/src/resident_runner.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class FlutterDevice {
117117
initializeFromDill: getDefaultCachedKernelPath(
118118
trackWidgetCreation: buildInfo.trackWidgetCreation,
119119
dartDefines: buildInfo.dartDefines,
120+
extraFrontEndOptions: extraFrontEndOptions
120121
),
121122
targetModel: TargetModel.dartdevc,
122123
extraFrontEndOptions: extraFrontEndOptions,
@@ -148,6 +149,7 @@ class FlutterDevice {
148149
initializeFromDill: getDefaultCachedKernelPath(
149150
trackWidgetCreation: buildInfo.trackWidgetCreation,
150151
dartDefines: buildInfo.dartDefines,
152+
extraFrontEndOptions: buildInfo.extraFrontEndOptions,
151153
),
152154
packagesPath: buildInfo.packagesPath,
153155
artifacts: globals.artifacts,
@@ -1121,6 +1123,7 @@ abstract class ResidentRunner {
11211123
final String copyPath = getDefaultCachedKernelPath(
11221124
trackWidgetCreation: trackWidgetCreation,
11231125
dartDefines: debuggingOptions.buildInfo.dartDefines,
1126+
extraFrontEndOptions: debuggingOptions.buildInfo.extraFrontEndOptions,
11241127
);
11251128
globals.fs
11261129
.file(copyPath)

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,40 @@ void main() {
13971397
'build', '187ef4436122d1cc2f40dc2b92f0eba0.cache.dill')).readAsString(), 'ABC');
13981398
}));
13991399

1400+
testUsingContext('HotRunner copies compiled app.dill to cache during startup with null safety', () => testbed.run(() async {
1401+
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
1402+
listViews,
1403+
listViews,
1404+
]);
1405+
setWsAddress(testUri, fakeVmServiceHost.vmService);
1406+
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
1407+
residentRunner = HotRunner(
1408+
<FlutterDevice>[
1409+
mockFlutterDevice,
1410+
],
1411+
stayResident: false,
1412+
debuggingOptions: DebuggingOptions.enabled(
1413+
const BuildInfo(
1414+
BuildMode.debug,
1415+
'',
1416+
treeShakeIcons: false,
1417+
extraFrontEndOptions: <String>['--enable-experiment=non-nullable>']
1418+
)
1419+
),
1420+
);
1421+
residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
1422+
when(mockFlutterDevice.runHot(
1423+
hotRunner: anyNamed('hotRunner'),
1424+
route: anyNamed('route'),
1425+
)).thenAnswer((Invocation invocation) async {
1426+
return 0;
1427+
});
1428+
await residentRunner.run();
1429+
1430+
expect(await globals.fs.file(globals.fs.path.join(
1431+
'build', '3416d3007730479552122f01c01e326d.cache.dill')).readAsString(), 'ABC');
1432+
}));
1433+
14001434
testUsingContext('HotRunner does not copy app.dill if a dillOutputPath is given', () => testbed.run(() async {
14011435
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
14021436
listViews,
@@ -1594,7 +1628,7 @@ void main() {
15941628
)).generator as DefaultResidentCompiler;
15951629

15961630
expect(residentCompiler.initializeFromDill,
1597-
globals.fs.path.join(getBuildDirectory(), 'cache.dill'));
1631+
globals.fs.path.join(getBuildDirectory(), '825b8f791aa86c5057fff6f064542c54.cache.dill'));
15981632
expect(residentCompiler.librariesSpec,
15991633
globals.fs.file(globals.artifacts.getArtifactPath(Artifact.flutterWebLibrariesJson))
16001634
.uri.toString());

0 commit comments

Comments
 (0)