Commit 3d5afb5a authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Revert "Skip AOT snapshot build if inputs are unchanged" (#11463)

* Revert "Support space- and backslash-escaped dependencies (#11090)"

This reverts commit e6bafd0b.

* Revert "Skip AOT snapshot build if inputs are unchanged (#11084)"

This reverts commit b5e522e2.
parent d68caaaf
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async';
import 'dart:convert' show JSON; import 'dart:convert' show JSON;
import 'package:crypto/crypto.dart' show md5; import 'package:crypto/crypto.dart' show md5;
...@@ -43,28 +42,3 @@ class Checksum { ...@@ -43,28 +42,3 @@ class Checksum {
@override @override
int get hashCode => _checksums.hashCode; int get hashCode => _checksums.hashCode;
} }
final RegExp _separatorExpr = new RegExp(r'([^\\]) ');
final RegExp _escapeExpr = new RegExp(r'\\(.)');
/// Parses a VM snapshot dependency file.
///
/// Snapshot dependency files are a single line mapping the output snapshot to a
/// space-separated list of input files used to generate that output. Spaces and
/// backslashes are escaped with a backslash. e.g,
///
/// outfile : file1.dart fil\\e2.dart fil\ e3.dart
///
/// will return a set containing: 'file1.dart', 'fil\e2.dart', 'fil e3.dart'.
Future<Set<String>> readDepfile(String depfilePath) async {
// Depfile format:
// outfile1 outfile2 : file1.dart file2.dart file3.dart
final String contents = await fs.file(depfilePath).readAsString();
final String dependencies = contents.split(': ')[1];
return dependencies
.replaceAllMapped(_separatorExpr, (Match match) => '${match.group(1)}\n')
.split('\n')
.map((String path) => path.replaceAllMapped(_escapeExpr, (Match match) => match.group(1)).trim())
.where((String path) => path.isNotEmpty)
.toSet();
}
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
import 'dart:async'; import 'dart:async';
import '../artifacts.dart'; import '../artifacts.dart';
import '../base/build.dart';
import '../base/common.dart'; import '../base/common.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/logger.dart'; import '../base/logger.dart';
...@@ -150,15 +149,13 @@ Future<String> _buildAotSnapshot( ...@@ -150,15 +149,13 @@ Future<String> _buildAotSnapshot(
final String uiPath = fs.path.join(skyEnginePkg, 'lib', 'ui', 'ui.dart'); final String uiPath = fs.path.join(skyEnginePkg, 'lib', 'ui', 'ui.dart');
final String vmServicePath = fs.path.join(skyEnginePkg, 'sdk_ext', 'vmservice_io.dart'); final String vmServicePath = fs.path.join(skyEnginePkg, 'sdk_ext', 'vmservice_io.dart');
final List<String> inputPaths = <String>[ final List<String> filePaths = <String>[
vmEntryPoints, vmEntryPoints,
ioEntryPoints, ioEntryPoints,
uiPath, uiPath,
vmServicePath, vmServicePath,
]; ];
final Set<String> outputPaths = new Set<String>();
// These paths are used only on iOS. // These paths are used only on iOS.
String snapshotDartIOS; String snapshotDartIOS;
String assembly; String assembly;
...@@ -167,15 +164,13 @@ Future<String> _buildAotSnapshot( ...@@ -167,15 +164,13 @@ Future<String> _buildAotSnapshot(
case TargetPlatform.android_arm: case TargetPlatform.android_arm:
case TargetPlatform.android_x64: case TargetPlatform.android_x64:
case TargetPlatform.android_x86: case TargetPlatform.android_x86:
outputPaths.addAll(<String>[
vmSnapshotData,
isolateSnapshotData,
]);
break; break;
case TargetPlatform.ios: case TargetPlatform.ios:
snapshotDartIOS = artifacts.getArtifactPath(Artifact.snapshotDart, platform, buildMode); snapshotDartIOS = artifacts.getArtifactPath(Artifact.snapshotDart, platform, buildMode);
assembly = fs.path.join(outputDir.path, 'snapshot_assembly.S'); assembly = fs.path.join(outputDir.path, 'snapshot_assembly.S');
inputPaths.add(snapshotDartIOS); filePaths.addAll(<String>[
snapshotDartIOS,
]);
break; break;
case TargetPlatform.darwin_x64: case TargetPlatform.darwin_x64:
case TargetPlatform.linux_x64: case TargetPlatform.linux_x64:
...@@ -184,9 +179,9 @@ Future<String> _buildAotSnapshot( ...@@ -184,9 +179,9 @@ Future<String> _buildAotSnapshot(
assert(false); assert(false);
} }
final Iterable<String> missingInputs = inputPaths.where((String p) => !fs.isFileSync(p)); final List<String> missingFiles = filePaths.where((String p) => !fs.isFileSync(p)).toList();
if (missingInputs.isNotEmpty) { if (missingFiles.isNotEmpty) {
printError('Missing input files: $missingInputs'); printError('Missing files: $missingFiles');
return null; return null;
} }
if (!processManager.canRun(genSnapshot)) { if (!processManager.canRun(genSnapshot)) {
...@@ -212,17 +207,6 @@ Future<String> _buildAotSnapshot( ...@@ -212,17 +207,6 @@ Future<String> _buildAotSnapshot(
genSnapshotCmd.add('--embedder_entry_points_manifest=$ioEntryPoints'); genSnapshotCmd.add('--embedder_entry_points_manifest=$ioEntryPoints');
} }
// iOS symbols used to load snapshot data in the engine.
const String kVmSnapshotData = 'kDartVmSnapshotData';
const String kIsolateSnapshotData = 'kDartIsolateSnapshotData';
// iOS snapshot generated files, compiled object files.
final String kVmSnapshotDataC = fs.path.join(outputDir.path, '$kVmSnapshotData.c');
final String kIsolateSnapshotDataC = fs.path.join(outputDir.path, '$kIsolateSnapshotData.c');
final String kVmSnapshotDataO = fs.path.join(outputDir.path, '$kVmSnapshotData.o');
final String kIsolateSnapshotDataO = fs.path.join(outputDir.path, '$kIsolateSnapshotData.o');
final String assemblyO = fs.path.join(outputDir.path, 'snapshot_assembly.o');
switch (platform) { switch (platform) {
case TargetPlatform.android_arm: case TargetPlatform.android_arm:
case TargetPlatform.android_x64: case TargetPlatform.android_x64:
...@@ -239,14 +223,9 @@ Future<String> _buildAotSnapshot( ...@@ -239,14 +223,9 @@ Future<String> _buildAotSnapshot(
if (interpreter) { if (interpreter) {
genSnapshotCmd.add('--snapshot_kind=core'); genSnapshotCmd.add('--snapshot_kind=core');
genSnapshotCmd.add(snapshotDartIOS); genSnapshotCmd.add(snapshotDartIOS);
outputPaths.addAll(<String>[
kVmSnapshotDataO,
kIsolateSnapshotDataO,
]);
} else { } else {
genSnapshotCmd.add('--snapshot_kind=app-aot-assembly'); genSnapshotCmd.add('--snapshot_kind=app-aot-assembly');
genSnapshotCmd.add('--assembly=$assembly'); genSnapshotCmd.add('--assembly=$assembly');
outputPaths.add(assemblyO);
} }
break; break;
case TargetPlatform.darwin_x64: case TargetPlatform.darwin_x64:
...@@ -265,27 +244,6 @@ Future<String> _buildAotSnapshot( ...@@ -265,27 +244,6 @@ Future<String> _buildAotSnapshot(
genSnapshotCmd.add(mainPath); genSnapshotCmd.add(mainPath);
final File checksumFile = fs.file('$dependencies.checksum');
final List<File> checksumFiles = <File>[checksumFile, fs.file(dependencies)]
..addAll(inputPaths.map(fs.file))
..addAll(outputPaths.map(fs.file));
if (checksumFiles.every((File file) => file.existsSync())) {
try {
final String json = await checksumFile.readAsString();
final Checksum oldChecksum = new Checksum.fromJson(json);
final Set<String> snapshotInputPaths = await readDepfile(dependencies);
snapshotInputPaths.addAll(outputPaths);
final Checksum newChecksum = new Checksum.fromFiles(snapshotInputPaths);
if (oldChecksum == newChecksum) {
printTrace('Skipping AOT snapshot build. Checksums match.');
return outputPath;
}
} catch (e, s) {
// Log exception and continue, this step is a performance improvement only.
printTrace('Error during AOT snapshot checksum check: $e\n$s');
}
}
final RunResult results = await runAsync(genSnapshotCmd); final RunResult results = await runAsync(genSnapshotCmd);
if (results.exitCode != 0) { if (results.exitCode != 0) {
printError('Dart snapshot generator failed with exit code ${results.exitCode}'); printError('Dart snapshot generator failed with exit code ${results.exitCode}');
...@@ -302,6 +260,16 @@ Future<String> _buildAotSnapshot( ...@@ -302,6 +260,16 @@ Future<String> _buildAotSnapshot(
if (platform == TargetPlatform.ios) { if (platform == TargetPlatform.ios) {
printStatus('Building App.framework...'); printStatus('Building App.framework...');
// These names are known to from the engine.
const String kVmSnapshotData = 'kDartVmSnapshotData';
const String kIsolateSnapshotData = 'kDartIsolateSnapshotData';
final String kVmSnapshotDataC = fs.path.join(outputDir.path, '$kVmSnapshotData.c');
final String kIsolateSnapshotDataC = fs.path.join(outputDir.path, '$kIsolateSnapshotData.c');
final String kVmSnapshotDataO = fs.path.join(outputDir.path, '$kVmSnapshotData.o');
final String kIsolateSnapshotDataO = fs.path.join(outputDir.path, '$kIsolateSnapshotData.o');
final String assemblyO = fs.path.join(outputDir.path, 'snapshot_assembly.o');
final List<String> commonBuildOptions = <String>['-arch', 'arm64', '-miphoneos-version-min=8.0']; final List<String> commonBuildOptions = <String>['-arch', 'arm64', '-miphoneos-version-min=8.0'];
if (interpreter) { if (interpreter) {
...@@ -348,16 +316,5 @@ Future<String> _buildAotSnapshot( ...@@ -348,16 +316,5 @@ Future<String> _buildAotSnapshot(
await runCheckedAsync(linkCommand); await runCheckedAsync(linkCommand);
} }
// Compute and record checksums.
try {
final Set<String> snapshotInputPaths = await readDepfile(dependencies);
snapshotInputPaths..addAll(outputPaths);
final Checksum checksum = new Checksum.fromFiles(snapshotInputPaths);
await checksumFile.writeAsString(checksum.toJson());
} catch (e, s) {
// Log exception and continue, this step is a performance improvement only.
printTrace('Error during AOT snapshot checksum output: $e\n$s');
}
return outputPath; return outputPath;
} }
...@@ -65,7 +65,7 @@ Future<int> _createSnapshot({ ...@@ -65,7 +65,7 @@ Future<int> _createSnapshot({
try { try {
final String json = await checksumFile.readAsString(); final String json = await checksumFile.readAsString();
final Checksum oldChecksum = new Checksum.fromJson(json); final Checksum oldChecksum = new Checksum.fromJson(json);
final Set<String> inputPaths = await readDepfile(depfilePath); final Set<String> inputPaths = await _readDepfile(depfilePath);
inputPaths.add(snapshotPath); inputPaths.add(snapshotPath);
final Checksum newChecksum = new Checksum.fromFiles(inputPaths); final Checksum newChecksum = new Checksum.fromFiles(inputPaths);
if (oldChecksum == newChecksum) { if (oldChecksum == newChecksum) {
...@@ -85,7 +85,7 @@ Future<int> _createSnapshot({ ...@@ -85,7 +85,7 @@ Future<int> _createSnapshot({
// Compute and record input file checksums. // Compute and record input file checksums.
try { try {
final Set<String> inputPaths = await readDepfile(depfilePath); final Set<String> inputPaths = await _readDepfile(depfilePath);
inputPaths.add(snapshotPath); inputPaths.add(snapshotPath);
final Checksum checksum = new Checksum.fromFiles(inputPaths); final Checksum checksum = new Checksum.fromFiles(inputPaths);
await checksumFile.writeAsString(checksum.toJson()); await checksumFile.writeAsString(checksum.toJson());
...@@ -96,6 +96,24 @@ Future<int> _createSnapshot({ ...@@ -96,6 +96,24 @@ Future<int> _createSnapshot({
return 0; return 0;
} }
/// Parses a VM snapshot dependency file.
///
/// Snapshot dependency files are a single line mapping the output snapshot to a
/// space-separated list of input files used to generate that output. e.g,
///
/// outfile : file1.dart file2.dart file3.dart
Future<Set<String>> _readDepfile(String depfilePath) async {
// Depfile format:
// outfile : file1.dart file2.dart file3.dart
final String contents = await fs.file(depfilePath).readAsString();
final String dependencies = contents.split(': ')[1];
return dependencies
.split(' ')
.map((String path) => path.trim())
.where((String path) => path.isNotEmpty)
.toSet();
}
Future<Null> build({ Future<Null> build({
String mainPath: defaultMainPath, String mainPath: defaultMainPath,
String manifestPath: defaultManifestPath, String manifestPath: defaultManifestPath,
......
...@@ -64,43 +64,4 @@ void main() { ...@@ -64,43 +64,4 @@ void main() {
}); });
}); });
}); });
group('readDepfile', () {
MemoryFileSystem fs;
setUp(() {
fs = new MemoryFileSystem();
});
testUsingContext('returns one file if only one is listed', () async {
await fs.file('a.d').writeAsString('snapshot.d: /foo/a.dart');
expect(await readDepfile('a.d'), unorderedEquals(<String>['/foo/a.dart']));
}, overrides: <Type, Generator>{ FileSystem: () => fs});
testUsingContext('returns multiple files', () async {
await fs.file('a.d').writeAsString('snapshot.d: /foo/a.dart /foo/b.dart');
expect(await readDepfile('a.d'), unorderedEquals(<String>[
'/foo/a.dart',
'/foo/b.dart',
]));
}, overrides: <Type, Generator>{ FileSystem: () => fs});
testUsingContext('trims extra spaces between files', () async {
await fs.file('a.d').writeAsString('snapshot.d: /foo/a.dart /foo/b.dart /foo/c.dart');
expect(await readDepfile('a.d'), unorderedEquals(<String>[
'/foo/a.dart',
'/foo/b.dart',
'/foo/c.dart',
]));
}, overrides: <Type, Generator>{ FileSystem: () => fs});
testUsingContext('returns files with spaces and backslashes', () async {
await fs.file('a.d').writeAsString(r'snapshot.d: /foo/a\ a.dart /foo/b\\b.dart /foo/c\\ c.dart');
expect(await readDepfile('a.d'), unorderedEquals(<String>[
r'/foo/a a.dart',
r'/foo/b\b.dart',
r'/foo/c\ c.dart',
]));
}, overrides: <Type, Generator>{ FileSystem: () => fs});
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment