Unverified Commit ed0b8be0 authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

Eliminate script snapshot support (#21387)

Script snapshots were only every used in Dart 1 mode, which is no longer
supported.
parent 343b5703
......@@ -67,69 +67,6 @@ class GenSnapshot {
}
}
/// Dart snapshot builder.
///
/// Builds Dart snapshots in one of three modes:
/// * Script snapshot: architecture-independent snapshot of a Dart script
/// and core libraries.
/// * AOT snapshot: architecture-specific ahead-of-time compiled snapshot
/// suitable for loading with `mmap`.
/// * Assembly AOT snapshot: architecture-specific ahead-of-time compile to
/// assembly suitable for compilation as a static or dynamic library.
class ScriptSnapshotter {
/// Builds an architecture-independent snapshot of the specified script.
Future<int> build({
@required String mainPath,
@required String snapshotPath,
@required String depfilePath,
@required String packagesPath
}) async {
final SnapshotType snapshotType = new SnapshotType(null, BuildMode.debug);
final String vmSnapshotData = artifacts.getArtifactPath(Artifact.vmSnapshotData);
final String isolateSnapshotData = artifacts.getArtifactPath(Artifact.isolateSnapshotData);
final List<String> args = <String>[
'--snapshot_kind=script',
'--script_snapshot=$snapshotPath',
'--vm_snapshot_data=$vmSnapshotData',
'--isolate_snapshot_data=$isolateSnapshotData',
'--enable-mirrors=false',
mainPath,
];
final Fingerprinter fingerprinter = new Fingerprinter(
fingerprintPath: '$depfilePath.fingerprint',
paths: <String>[
mainPath,
snapshotPath,
vmSnapshotData,
isolateSnapshotData,
],
properties: <String, String>{
'buildMode': snapshotType.mode.toString(),
'targetPlatform': snapshotType.platform?.toString() ?? '',
'entryPoint': mainPath,
},
depfilePaths: <String>[depfilePath],
);
if (await fingerprinter.doesFingerprintMatch()) {
printTrace('Skipping script snapshot build. Fingerprints match.');
return 0;
}
// Build the snapshot.
final int exitCode = await genSnapshot.run(
snapshotType: snapshotType,
packagesPath: packagesPath,
additionalArgs: args,
);
if (exitCode != 0)
return exitCode;
await fingerprinter.writeFingerprint();
return exitCode;
}
}
class AOTSnapshotter {
/// Builds an architecture-specific ahead-of-time compiled snapshot of the specified script.
Future<int> build({
......
......@@ -24,7 +24,6 @@ String get defaultApplicationKernelPath => fs.path.join(getBuildDirectory(), 'ap
const String defaultPrivateKeyPath = 'privatekey.der';
const String _kKernelKey = 'kernel_blob.bin';
const String _kSnapshotKey = 'snapshot_blob.bin';
const String _kVMSnapshotData = 'vm_snapshot_data';
const String _kVMSnapshotInstr = 'vm_snapshot_instr';
const String _kIsolateSnapshotData = 'isolate_snapshot_data';
......@@ -43,7 +42,6 @@ Future<void> build({
String privateKeyPath = defaultPrivateKeyPath,
String assetDirPath,
String packagesPath,
bool previewDart2 = true,
bool precompiledSnapshot = false,
bool reportLicensedPackages = false,
bool trackWidgetCreation = false,
......@@ -58,27 +56,9 @@ Future<void> build({
assetDirPath ??= getAssetBuildDirectory();
packagesPath ??= fs.path.absolute(PackageMap.globalPackagesPath);
applicationKernelFilePath ??= defaultApplicationKernelPath;
File snapshotFile;
if (!precompiledSnapshot && !previewDart2) {
ensureDirectoryExists(snapshotPath);
// In a precompiled snapshot, the instruction buffer contains script
// content equivalents
final int result = await new ScriptSnapshotter().build(
mainPath: mainPath,
snapshotPath: snapshotPath,
depfilePath: depfilePath,
packagesPath: packagesPath,
);
if (result != 0)
throwToolExit('Failed to run the Flutter compiler. Exit code: $result', exitCode: result);
snapshotFile = fs.file(snapshotPath);
}
DevFSContent kernelContent;
if (!precompiledSnapshot && previewDart2) {
if (!precompiledSnapshot) {
if ((extraFrontEndOptions != null) && extraFrontEndOptions.isNotEmpty)
printTrace('Extra front-end options: $extraFrontEndOptions');
ensureDirectoryExists(applicationKernelFilePath);
......@@ -133,7 +113,6 @@ Future<void> build({
await assemble(
assetBundle: assets,
kernelContent: kernelContent,
snapshotFile: snapshotFile,
privateKeyPath: privateKeyPath,
assetDirPath: assetDirPath,
compilationTraceFilePath: compilationTraceFilePath,
......@@ -168,7 +147,6 @@ Future<AssetBundle> buildAssets({
Future<void> assemble({
AssetBundle assetBundle,
DevFSContent kernelContent,
File snapshotFile,
File dylibFile,
String privateKeyPath = defaultPrivateKeyPath,
String assetDirPath,
......@@ -198,13 +176,6 @@ Future<void> assemble({
assetEntries[_kIsolateSnapshotData] = new DevFSFileContent(fs.file(isolateSnapshotData));
}
}
if (snapshotFile != null) {
final String vmSnapshotData = artifacts.getArtifactPath(Artifact.vmSnapshotData);
final String isolateSnapshotData = artifacts.getArtifactPath(Artifact.isolateSnapshotData);
assetEntries[_kSnapshotKey] = new DevFSFileContent(snapshotFile);
assetEntries[_kVMSnapshotData] = new DevFSFileContent(fs.file(vmSnapshotData));
assetEntries[_kIsolateSnapshotData] = new DevFSFileContent(fs.file(isolateSnapshotData));
}
if (dylibFile != null)
assetEntries[_kDylibKey] = new DevFSFileContent(dylibFile);
......
......@@ -90,7 +90,6 @@ class BuildBundleCommand extends BuildSubCommand {
depfilePath: argResults['depfile'],
privateKeyPath: argResults['private-key'],
assetDirPath: argResults['asset-dir'],
previewDart2: true,
precompiledSnapshot: argResults['precompiled'],
reportLicensedPackages: argResults['report-licensed-packages'],
trackWidgetCreation: argResults['track-widget-creation'],
......
......@@ -386,12 +386,10 @@ class IOSSimulator extends Device {
}
Future<void> _sideloadUpdatedAssetsForInstalledApplicationBundle(ApplicationPackage app, BuildInfo buildInfo, String mainPath) {
// When running in previewDart2 mode, we still need to run compiler to
// produce kernel file for the application.
// Run compiler to produce kernel file for the application.
return bundle.build(
mainPath: mainPath,
precompiledSnapshot: !buildInfo.previewDart2,
previewDart2: buildInfo.previewDart2,
precompiledSnapshot: false,
trackWidgetCreation: buildInfo.trackWidgetCreation,
);
}
......
......@@ -133,8 +133,7 @@ class FlutterTesterDevice extends Device {
mainPath: mainPath,
assetDirPath: assetDirPath,
applicationKernelFilePath: applicationKernelFilePath,
precompiledSnapshot: !buildInfo.previewDart2,
previewDart2: buildInfo.previewDart2,
precompiledSnapshot: false,
trackWidgetCreation: buildInfo.trackWidgetCreation,
);
if (buildInfo.previewDart2) {
......
......@@ -3,7 +3,6 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert' show json;
import 'package:file/memory.dart';
import 'package:flutter_tools/src/android/android_sdk.dart';
......@@ -85,198 +84,6 @@ void main() {
});
});
group('Snapshotter - Script Snapshots', () {
const String kVersion = '123456abcdef';
const String kIsolateSnapshotData = 'isolate_snapshot.bin';
const String kVmSnapshotData = 'vm_isolate_snapshot.bin';
_FakeGenSnapshot genSnapshot;
MemoryFileSystem fs;
MockFlutterVersion mockVersion;
ScriptSnapshotter snapshotter;
MockArtifacts mockArtifacts;
setUp(() {
fs = new MemoryFileSystem();
fs.file(kIsolateSnapshotData).writeAsStringSync('snapshot data');
fs.file(kVmSnapshotData).writeAsStringSync('vm data');
genSnapshot = new _FakeGenSnapshot();
genSnapshot.outputs = <String, String>{
'output.snapshot': '',
'output.snapshot.d': 'output.snapshot.d : main.dart',
};
mockVersion = new MockFlutterVersion();
when(mockVersion.frameworkRevision).thenReturn(kVersion);
snapshotter = new ScriptSnapshotter();
mockArtifacts = new MockArtifacts();
when(mockArtifacts.getArtifactPath(Artifact.isolateSnapshotData)).thenReturn(kIsolateSnapshotData);
when(mockArtifacts.getArtifactPath(Artifact.vmSnapshotData)).thenReturn(kVmSnapshotData);
});
final Map<Type, Generator> contextOverrides = <Type, Generator>{
Artifacts: () => mockArtifacts,
FileSystem: () => fs,
FlutterVersion: () => mockVersion,
GenSnapshot: () => genSnapshot,
};
Future<void> writeFingerprint({ Map<String, String> files = const <String, String>{} }) {
return fs.file('output.snapshot.d.fingerprint').writeAsString(json.encode(<String, dynamic>{
'version': kVersion,
'properties': <String, String>{
'buildMode': BuildMode.debug.toString(),
'targetPlatform': '',
'entryPoint': 'main.dart',
},
'files': <String, dynamic>{
kVmSnapshotData: '2ec34912477a46c03ddef07e8b909b46',
kIsolateSnapshotData: '621b3844bb7d4d17d2cfc5edf9a91c4c',
}..addAll(files),
}));
}
void expectFingerprintHas({
String entryPoint = 'main.dart',
Map<String, String> checksums = const <String, String>{},
}) {
final Map<String, dynamic> jsonObject = json.decode(fs.file('output.snapshot.d.fingerprint').readAsStringSync());
expect(jsonObject['properties']['entryPoint'], entryPoint);
expect(jsonObject['files'], hasLength(checksums.length + 2));
checksums.forEach((String filePath, String checksum) {
expect(jsonObject['files'][filePath], checksum);
});
expect(jsonObject['files'][kVmSnapshotData], '2ec34912477a46c03ddef07e8b909b46');
expect(jsonObject['files'][kIsolateSnapshotData], '621b3844bb7d4d17d2cfc5edf9a91c4c');
}
testUsingContext('builds snapshot and fingerprint when no fingerprint is present', () async {
await fs.file('main.dart').writeAsString('void main() {}');
await fs.file('output.snapshot').create();
await fs.file('output.snapshot.d').writeAsString('snapshot : main.dart');
await snapshotter.build(
mainPath: 'main.dart',
snapshotPath: 'output.snapshot',
depfilePath: 'output.snapshot.d',
packagesPath: '.packages',
);
expect(genSnapshot.callCount, 1);
expect(genSnapshot.snapshotType.platform, isNull);
expect(genSnapshot.snapshotType.mode, BuildMode.debug);
expect(genSnapshot.packagesPath, '.packages');
expect(genSnapshot.additionalArgs, <String>[
'--snapshot_kind=script',
'--script_snapshot=output.snapshot',
'--vm_snapshot_data=vm_isolate_snapshot.bin',
'--isolate_snapshot_data=isolate_snapshot.bin',
'--enable-mirrors=false',
'main.dart',
]);
expectFingerprintHas(checksums: <String, String>{
'main.dart': '27f5ebf0f8c559b2af9419d190299a5e',
'output.snapshot': 'd41d8cd98f00b204e9800998ecf8427e',
});
}, overrides: contextOverrides);
testUsingContext('builds snapshot and fingerprint when fingerprints differ', () async {
await fs.file('main.dart').writeAsString('void main() {}');
await fs.file('output.snapshot').create();
await fs.file('output.snapshot.d').writeAsString('output.snapshot : main.dart');
await writeFingerprint(files: <String, String>{
'main.dart': '27f5ebf0f8c559b2af9419d190299a5e',
'output.snapshot': 'deadbeef000b204e9800998ecaaaaa',
});
await snapshotter.build(
mainPath: 'main.dart',
snapshotPath: 'output.snapshot',
depfilePath: 'output.snapshot.d',
packagesPath: '.packages',
);
expect(genSnapshot.callCount, 1);
expectFingerprintHas(checksums: <String, String>{
'main.dart': '27f5ebf0f8c559b2af9419d190299a5e',
'output.snapshot': 'd41d8cd98f00b204e9800998ecf8427e',
});
}, overrides: contextOverrides);
testUsingContext('builds snapshot and fingerprint when fingerprints match but previous snapshot not present', () async {
await fs.file('main.dart').writeAsString('void main() {}');
await fs.file('output.snapshot.d').writeAsString('output.snapshot : main.dart');
await writeFingerprint(files: <String, String>{
'main.dart': '27f5ebf0f8c559b2af9419d190299a5e',
'output.snapshot': 'd41d8cd98f00b204e9800998ecf8427e',
});
await snapshotter.build(
mainPath: 'main.dart',
snapshotPath: 'output.snapshot',
depfilePath: 'output.snapshot.d',
packagesPath: '.packages',
);
expect(genSnapshot.callCount, 1);
expectFingerprintHas(checksums: <String, String>{
'main.dart': '27f5ebf0f8c559b2af9419d190299a5e',
'output.snapshot': 'd41d8cd98f00b204e9800998ecf8427e',
});
}, overrides: contextOverrides);
testUsingContext('builds snapshot and fingerprint when main entry point changes to other dependency', () async {
await fs.file('main.dart').writeAsString('import "other.dart";\nvoid main() {}');
await fs.file('other.dart').writeAsString('import "main.dart";\nvoid main() {}');
await fs.file('output.snapshot').create();
await fs.file('output.snapshot.d').writeAsString('output.snapshot : main.dart');
await writeFingerprint(files: <String, String>{
'main.dart': 'bc096b33f14dde5e0ffaf93a1d03395c',
'other.dart': 'e0c35f083f0ad76b2d87100ec678b516',
'output.snapshot': 'd41d8cd98f00b204e9800998ecf8427e',
});
genSnapshot.outputs = <String, String>{
'output.snapshot': '',
'output.snapshot.d': 'output.snapshot : main.dart other.dart',
};
await snapshotter.build(
mainPath: 'other.dart',
snapshotPath: 'output.snapshot',
depfilePath: 'output.snapshot.d',
packagesPath: '.packages',
);
expect(genSnapshot.callCount, 1);
expectFingerprintHas(
entryPoint: 'other.dart',
checksums: <String, String>{
'main.dart': 'bc096b33f14dde5e0ffaf93a1d03395c',
'other.dart': 'e0c35f083f0ad76b2d87100ec678b516',
'output.snapshot': 'd41d8cd98f00b204e9800998ecf8427e',
},
);
}, overrides: contextOverrides);
testUsingContext('skips snapshot when fingerprints match and previous snapshot is present', () async {
await fs.file('main.dart').writeAsString('void main() {}');
await fs.file('output.snapshot').create();
await fs.file('output.snapshot.d').writeAsString('output.snapshot : main.dart');
await writeFingerprint(files: <String, String>{
'main.dart': '27f5ebf0f8c559b2af9419d190299a5e',
'output.snapshot': 'd41d8cd98f00b204e9800998ecf8427e',
});
await snapshotter.build(
mainPath: 'main.dart',
snapshotPath: 'output.snapshot',
depfilePath: 'output.snapshot.d',
packagesPath: '.packages',
);
expect(genSnapshot.callCount, 0);
expectFingerprintHas(checksums: <String, String>{
'main.dart': '27f5ebf0f8c559b2af9419d190299a5e',
'output.snapshot': 'd41d8cd98f00b204e9800998ecf8427e',
});
}, overrides: contextOverrides);
});
group('Snapshotter - iOS AOT', () {
const String kVmEntrypoints = 'dart_vm_entry_points.txt';
const String kIoEntries = 'dart_io_entries.txt';
......
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