From ed0b8be0413805d1cb80ca6fcff5c5c051a2ac47 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 4 Sep 2018 10:05:26 -0700 Subject: [PATCH] Eliminate script snapshot support (#21387) Script snapshots were only every used in Dart 1 mode, which is no longer supported. --- .../flutter_tools/lib/src/base/build.dart | 63 ------ packages/flutter_tools/lib/src/bundle.dart | 31 +-- .../lib/src/commands/build_bundle.dart | 1 - .../flutter_tools/lib/src/ios/simulators.dart | 6 +- .../lib/src/tester/flutter_tester.dart | 3 +- .../flutter_tools/test/base/build_test.dart | 193 ------------------ 6 files changed, 4 insertions(+), 293 deletions(-) diff --git a/packages/flutter_tools/lib/src/base/build.dart b/packages/flutter_tools/lib/src/base/build.dart index 95aee4ffcd..eb031f32b6 100644 --- a/packages/flutter_tools/lib/src/base/build.dart +++ b/packages/flutter_tools/lib/src/base/build.dart @@ -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 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 args = [ - '--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: [ - mainPath, - snapshotPath, - vmSnapshotData, - isolateSnapshotData, - ], - properties: { - 'buildMode': snapshotType.mode.toString(), - 'targetPlatform': snapshotType.platform?.toString() ?? '', - 'entryPoint': mainPath, - }, - depfilePaths: [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 build({ diff --git a/packages/flutter_tools/lib/src/bundle.dart b/packages/flutter_tools/lib/src/bundle.dart index 69f559fa78..8f3fe07e43 100644 --- a/packages/flutter_tools/lib/src/bundle.dart +++ b/packages/flutter_tools/lib/src/bundle.dart @@ -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 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 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 build({ await assemble( assetBundle: assets, kernelContent: kernelContent, - snapshotFile: snapshotFile, privateKeyPath: privateKeyPath, assetDirPath: assetDirPath, compilationTraceFilePath: compilationTraceFilePath, @@ -168,7 +147,6 @@ Future buildAssets({ Future assemble({ AssetBundle assetBundle, DevFSContent kernelContent, - File snapshotFile, File dylibFile, String privateKeyPath = defaultPrivateKeyPath, String assetDirPath, @@ -198,13 +176,6 @@ Future 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); diff --git a/packages/flutter_tools/lib/src/commands/build_bundle.dart b/packages/flutter_tools/lib/src/commands/build_bundle.dart index f19b79dda4..3958e378a3 100644 --- a/packages/flutter_tools/lib/src/commands/build_bundle.dart +++ b/packages/flutter_tools/lib/src/commands/build_bundle.dart @@ -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'], diff --git a/packages/flutter_tools/lib/src/ios/simulators.dart b/packages/flutter_tools/lib/src/ios/simulators.dart index 7e2de4e73d..54e795e018 100644 --- a/packages/flutter_tools/lib/src/ios/simulators.dart +++ b/packages/flutter_tools/lib/src/ios/simulators.dart @@ -386,12 +386,10 @@ class IOSSimulator extends Device { } Future _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, ); } diff --git a/packages/flutter_tools/lib/src/tester/flutter_tester.dart b/packages/flutter_tools/lib/src/tester/flutter_tester.dart index e6c2b24aab..b3f726a0d1 100644 --- a/packages/flutter_tools/lib/src/tester/flutter_tester.dart +++ b/packages/flutter_tools/lib/src/tester/flutter_tester.dart @@ -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) { diff --git a/packages/flutter_tools/test/base/build_test.dart b/packages/flutter_tools/test/base/build_test.dart index 9fb3bfd088..48435268dd 100644 --- a/packages/flutter_tools/test/base/build_test.dart +++ b/packages/flutter_tools/test/base/build_test.dart @@ -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 = { - '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 contextOverrides = { - Artifacts: () => mockArtifacts, - FileSystem: () => fs, - FlutterVersion: () => mockVersion, - GenSnapshot: () => genSnapshot, - }; - - Future writeFingerprint({ Map files = const {} }) { - return fs.file('output.snapshot.d.fingerprint').writeAsString(json.encode({ - 'version': kVersion, - 'properties': { - 'buildMode': BuildMode.debug.toString(), - 'targetPlatform': '', - 'entryPoint': 'main.dart', - }, - 'files': { - kVmSnapshotData: '2ec34912477a46c03ddef07e8b909b46', - kIsolateSnapshotData: '621b3844bb7d4d17d2cfc5edf9a91c4c', - }..addAll(files), - })); - } - - void expectFingerprintHas({ - String entryPoint = 'main.dart', - Map checksums = const {}, - }) { - final Map 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, [ - '--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: { - '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: { - '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: { - '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: { - '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: { - '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: { - 'main.dart': 'bc096b33f14dde5e0ffaf93a1d03395c', - 'other.dart': 'e0c35f083f0ad76b2d87100ec678b516', - 'output.snapshot': 'd41d8cd98f00b204e9800998ecf8427e', - }); - genSnapshot.outputs = { - '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: { - '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: { - '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: { - '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';