[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.
This commit is contained in:
@@ -39,9 +39,11 @@ String getDefaultApplicationKernelPath({ @required bool trackWidgetCreation }) {
|
||||
String getDefaultCachedKernelPath({
|
||||
@required bool trackWidgetCreation,
|
||||
@required List<String> dartDefines,
|
||||
@required List<String> extraFrontEndOptions,
|
||||
}) {
|
||||
final StringBuffer buffer = StringBuffer();
|
||||
buffer.writeAll(dartDefines);
|
||||
buffer.writeAll(extraFrontEndOptions ?? <String>[]);
|
||||
String buildPrefix = '';
|
||||
if (buffer.isNotEmpty) {
|
||||
final String output = buffer.toString();
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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: <VmServiceExpectation>[
|
||||
listViews,
|
||||
listViews,
|
||||
]);
|
||||
setWsAddress(testUri, fakeVmServiceHost.vmService);
|
||||
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
|
||||
residentRunner = HotRunner(
|
||||
<FlutterDevice>[
|
||||
mockFlutterDevice,
|
||||
],
|
||||
stayResident: false,
|
||||
debuggingOptions: DebuggingOptions.enabled(
|
||||
const BuildInfo(
|
||||
BuildMode.debug,
|
||||
'',
|
||||
treeShakeIcons: false,
|
||||
extraFrontEndOptions: <String>['--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: <VmServiceExpectation>[
|
||||
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());
|
||||
|
||||
Reference in New Issue
Block a user