Skip to content

Commit 1f6b947

Browse files
authored
Fix snapshot fingerprinting in --preview-dart-2 mode. (flutter#14843)
* Fix snapshot fingerprinting in --preview-dart-2 mode. This is a follow up to PR flutter#14775 - instead of treating dill file as an input treat as intermediate file and don't fingerprint it. Make sure to always use original main Dart file as an entry point for fingerprint calculation. This fixes an issue that AOT snapshot would not be recompiled in the preview-dart-2 mode if entry point changes, e.g. $ flutter build aot -t t/x.dart --preview-dart-2 $ flutter build aot -t t/y.dart --preview-dart-2 The second invocation would not build AOT snapshot. (This issue is visible on the microbencmarks bot)
1 parent 3ee85e0 commit 1f6b947

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

packages/flutter_tools/lib/src/commands/build_aot.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,15 @@ Future<String> _buildAotSnapshot(
335335
]);
336336
}
337337

338-
final String genSnapshotInputFile = previewDart2 ? kApplicationKernelPath : mainPath;
338+
final String entryPoint = mainPath;
339339
final SnapshotType snapshotType = new SnapshotType(platform, buildMode);
340+
Future<Fingerprint> makeFingerprint() async {
341+
final Set<String> snapshotInputPaths = await readDepfile(dependencies)
342+
..add(entryPoint)
343+
..addAll(outputPaths);
344+
return Snapshotter.createFingerprint(snapshotType, entryPoint, snapshotInputPaths);
345+
}
346+
340347
final File fingerprintFile = fs.file('$dependencies.fingerprint');
341348
final List<File> fingerprintFiles = <File>[fingerprintFile, fs.file(dependencies)]
342349
..addAll(inputPaths.map(fs.file))
@@ -345,11 +352,7 @@ Future<String> _buildAotSnapshot(
345352
try {
346353
final String json = await fingerprintFile.readAsString();
347354
final Fingerprint oldFingerprint = new Fingerprint.fromJson(json);
348-
final Set<String> snapshotInputPaths = await readDepfile(dependencies)
349-
..add(genSnapshotInputFile)
350-
..addAll(outputPaths);
351-
final Fingerprint newFingerprint = Snapshotter.createFingerprint(snapshotType, genSnapshotInputFile, snapshotInputPaths);
352-
if (oldFingerprint == newFingerprint) {
355+
if (oldFingerprint == await makeFingerprint()) {
353356
printStatus('Skipping AOT snapshot build. Fingerprint match.');
354357
return outputPath;
355358
}
@@ -459,10 +462,7 @@ Future<String> _buildAotSnapshot(
459462

460463
// Compute and record build fingerprint.
461464
try {
462-
final Set<String> snapshotInputPaths = await readDepfile(dependencies)
463-
..add(mainPath)
464-
..addAll(outputPaths);
465-
final Fingerprint fingerprint = Snapshotter.createFingerprint(snapshotType, mainPath, snapshotInputPaths);
465+
final Fingerprint fingerprint = await makeFingerprint();
466466
await fingerprintFile.writeAsString(fingerprint.toJson());
467467
} catch (e, s) {
468468
// Log exception and continue, this step is a performance improvement only.

0 commit comments

Comments
 (0)