From c543db70dc1a9b7e1f30d351f83e717d924618ca Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Tue, 30 Jun 2020 15:49:31 -0700 Subject: [PATCH] [flutter_tools] add null-safety flags to dill cache location (#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. --- packages/flutter_tools/lib/src/bundle.dart | 2 ++ .../lib/src/resident_runner.dart | 3 ++ .../general.shard/resident_runner_test.dart | 36 ++++++++++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/bundle.dart b/packages/flutter_tools/lib/src/bundle.dart index 4b693e5b3a..b92ad68092 100644 --- a/packages/flutter_tools/lib/src/bundle.dart +++ b/packages/flutter_tools/lib/src/bundle.dart @@ -39,9 +39,11 @@ String getDefaultApplicationKernelPath({ @required bool trackWidgetCreation }) { String getDefaultCachedKernelPath({ @required bool trackWidgetCreation, @required List dartDefines, + @required List extraFrontEndOptions, }) { final StringBuffer buffer = StringBuffer(); buffer.writeAll(dartDefines); + buffer.writeAll(extraFrontEndOptions ?? []); String buildPrefix = ''; if (buffer.isNotEmpty) { final String output = buffer.toString(); diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart index 9e0f7d5b28..1efc91fc13 100644 --- a/packages/flutter_tools/lib/src/resident_runner.dart +++ b/packages/flutter_tools/lib/src/resident_runner.dart @@ -117,6 +117,7 @@ class FlutterDevice { initializeFromDill: getDefaultCachedKernelPath( trackWidgetCreation: buildInfo.trackWidgetCreation, dartDefines: buildInfo.dartDefines, + extraFrontEndOptions: extraFrontEndOptions ), targetModel: TargetModel.dartdevc, extraFrontEndOptions: extraFrontEndOptions, @@ -148,6 +149,7 @@ class FlutterDevice { initializeFromDill: getDefaultCachedKernelPath( trackWidgetCreation: buildInfo.trackWidgetCreation, dartDefines: buildInfo.dartDefines, + extraFrontEndOptions: buildInfo.extraFrontEndOptions, ), packagesPath: buildInfo.packagesPath, artifacts: globals.artifacts, @@ -1121,6 +1123,7 @@ abstract class ResidentRunner { final String copyPath = getDefaultCachedKernelPath( trackWidgetCreation: trackWidgetCreation, dartDefines: debuggingOptions.buildInfo.dartDefines, + extraFrontEndOptions: debuggingOptions.buildInfo.extraFrontEndOptions, ); globals.fs .file(copyPath) diff --git a/packages/flutter_tools/test/general.shard/resident_runner_test.dart b/packages/flutter_tools/test/general.shard/resident_runner_test.dart index 765c47e9b6..a4b4354377 100644 --- a/packages/flutter_tools/test/general.shard/resident_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_runner_test.dart @@ -1397,6 +1397,40 @@ void main() { 'build', '187ef4436122d1cc2f40dc2b92f0eba0.cache.dill')).readAsString(), 'ABC'); })); + testUsingContext('HotRunner copies compiled app.dill to cache during startup with null safety', () => testbed.run(() async { + fakeVmServiceHost = FakeVmServiceHost(requests: [ + listViews, + listViews, + ]); + setWsAddress(testUri, fakeVmServiceHost.vmService); + globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); + residentRunner = HotRunner( + [ + mockFlutterDevice, + ], + stayResident: false, + debuggingOptions: DebuggingOptions.enabled( + const BuildInfo( + BuildMode.debug, + '', + treeShakeIcons: false, + extraFrontEndOptions: ['--enable-experiment=non-nullable>'] + ) + ), + ); + residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC'); + when(mockFlutterDevice.runHot( + hotRunner: anyNamed('hotRunner'), + route: anyNamed('route'), + )).thenAnswer((Invocation invocation) async { + return 0; + }); + await residentRunner.run(); + + expect(await globals.fs.file(globals.fs.path.join( + 'build', '3416d3007730479552122f01c01e326d.cache.dill')).readAsString(), 'ABC'); + })); + testUsingContext('HotRunner does not copy app.dill if a dillOutputPath is given', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, @@ -1594,7 +1628,7 @@ void main() { )).generator as DefaultResidentCompiler; expect(residentCompiler.initializeFromDill, - globals.fs.path.join(getBuildDirectory(), 'cache.dill')); + globals.fs.path.join(getBuildDirectory(), '825b8f791aa86c5057fff6f064542c54.cache.dill')); expect(residentCompiler.librariesSpec, globals.fs.file(globals.artifacts.getArtifactPath(Artifact.flutterWebLibrariesJson)) .uri.toString());