Skip to content

Commit 39ddeb5

Browse files
authored
Fix snapshot fingerprint check for --preview-dart-2. (flutter#14775)
* Fix snapshot fingerprint check for --preview-dart-2. * Remove printTraces
1 parent 494270f commit 39ddeb5

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

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

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

338+
final String genSnapshotInputFile = previewDart2 ? kApplicationKernelPath : mainPath;
339+
final SnapshotType snapshotType = new SnapshotType(platform, buildMode);
340+
final File fingerprintFile = fs.file('$dependencies.fingerprint');
341+
final List<File> fingerprintFiles = <File>[fingerprintFile, fs.file(dependencies)]
342+
..addAll(inputPaths.map(fs.file))
343+
..addAll(outputPaths.map(fs.file));
344+
if (fingerprintFiles.every((File file) => file.existsSync())) {
345+
try {
346+
final String json = await fingerprintFile.readAsString();
347+
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) {
353+
printStatus('Skipping AOT snapshot build. Fingerprint match.');
354+
return outputPath;
355+
}
356+
} catch (e) {
357+
// Log exception and continue, this step is a performance improvement only.
358+
printTrace('Rebuilding snapshot due to fingerprint check error: $e');
359+
}
360+
}
361+
338362
if (previewDart2) {
339363
mainPath = await compile(
340364
sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
@@ -358,29 +382,6 @@ Future<String> _buildAotSnapshot(
358382

359383
genSnapshotCmd.add(mainPath);
360384

361-
final SnapshotType snapshotType = new SnapshotType(platform, buildMode);
362-
final File fingerprintFile = fs.file('$dependencies.fingerprint');
363-
final List<File> fingerprintFiles = <File>[fingerprintFile, fs.file(dependencies)]
364-
..addAll(inputPaths.map(fs.file))
365-
..addAll(outputPaths.map(fs.file));
366-
if (fingerprintFiles.every((File file) => file.existsSync())) {
367-
try {
368-
final String json = await fingerprintFile.readAsString();
369-
final Fingerprint oldFingerprint = new Fingerprint.fromJson(json);
370-
final Set<String> snapshotInputPaths = await readDepfile(dependencies)
371-
..add(mainPath)
372-
..addAll(outputPaths);
373-
final Fingerprint newFingerprint = Snapshotter.createFingerprint(snapshotType, mainPath, snapshotInputPaths);
374-
if (oldFingerprint == newFingerprint) {
375-
printStatus('Skipping AOT snapshot build. Fingerprint match.');
376-
return outputPath;
377-
}
378-
} catch (e) {
379-
// Log exception and continue, this step is a performance improvement only.
380-
printTrace('Rebuilding snapshot due to fingerprint check error: $e');
381-
}
382-
}
383-
384385
final RunResult results = await runAsync(genSnapshotCmd);
385386
if (results.exitCode != 0) {
386387
printError('Dart snapshot generator failed with exit code ${results.exitCode}');

0 commit comments

Comments
 (0)