From d19bdc4339024d274d822d047ee6557175f52c53 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 30 Apr 2018 17:34:36 -0700 Subject: [PATCH] Revert "Improve AOT snapshot input verification + cleanup (#17136)" (#17142) This reverts commit 100be23a341a4206a76e19087bd899a1b1fe2b5e. --- .../flutter_tools/lib/src/base/build.dart | 109 +++++++++--------- .../flutter_tools/test/base/build_test.dart | 20 ++-- 2 files changed, 67 insertions(+), 62 deletions(-) diff --git a/packages/flutter_tools/lib/src/base/build.dart b/packages/flutter_tools/lib/src/base/build.dart index d28e6f6a3a7..0f3283965fb 100644 --- a/packages/flutter_tools/lib/src/base/build.dart +++ b/packages/flutter_tools/lib/src/base/build.dart @@ -264,16 +264,36 @@ class Snapshotter { @required bool preferSharedLibrary, List extraGenSnapshotOptions: const [], }) async { - if (!_isValidAotPlatform(platform)) { + if (!(platform == TargetPlatform.android_arm || + platform == TargetPlatform.android_arm64 || + platform == TargetPlatform.ios)) { printError('${getNameForTargetPlatform(platform)} does not support AOT compilation.'); return -2; } - final bool compileToSharedLibrary = preferSharedLibrary && androidSdk.ndkCompiler != null; + final Directory outputDir = fs.directory(outputPath); + outputDir.createSync(recursive: true); + + final String vmSnapshotData = fs.path.join(outputDir.path, 'vm_snapshot_data'); + final String isolateSnapshotData = fs.path.join(outputDir.path, 'isolate_snapshot_data'); + final String depfilePath = fs.path.join(outputDir.path, 'snapshot.d'); + final String assembly = fs.path.join(outputDir.path, 'snapshot_assembly.S'); + final String assemblyO = fs.path.join(outputDir.path, 'snapshot_assembly.o'); + final String assemblySo = fs.path.join(outputDir.path, 'app.so'); + final bool compileToSharedLibrary = + preferSharedLibrary && androidSdk.ndkCompiler != null; + if (preferSharedLibrary && !compileToSharedLibrary) { - printStatus('Could not find NDK compiler. Not building in shared library mode.'); + printStatus( + 'Could not find NDK compiler. Not building in shared library mode'); } + final String vmEntryPoints = artifacts.getArtifactPath(Artifact.dartVmEntryPointsTxt, platform, buildMode); + assert(vmEntryPoints != null); + + final String ioEntryPoints = artifacts.getArtifactPath(Artifact.dartIoEntriesTxt, platform, buildMode); + assert(ioEntryPoints != null); + final PackageMap packageMap = new PackageMap(packagesPath); final String packageMapError = packageMap.checkValid(); if (packageMapError != null) { @@ -281,19 +301,19 @@ class Snapshotter { return -3; } - final Directory outputDir = fs.directory(outputPath); - outputDir.createSync(recursive: true); - final String skyEnginePkg = _getPackagePath(packageMap, 'sky_engine'); final String uiPath = fs.path.join(skyEnginePkg, 'lib', 'ui', 'ui.dart'); final String vmServicePath = fs.path.join(skyEnginePkg, 'sdk_ext', 'vmservice_io.dart'); - final List inputPaths = [uiPath, vmServicePath, mainPath]; + final List inputPaths = [vmEntryPoints, ioEntryPoints, uiPath, vmServicePath, mainPath]; final Set outputPaths = new Set(); - final String vmSnapshotData = fs.path.join(outputDir.path, 'vm_snapshot_data'); - final String isolateSnapshotData = fs.path.join(outputDir.path, 'isolate_snapshot_data'); - final String depfilePath = fs.path.join(outputDir.path, 'snapshot.d'); + final Iterable missingInputs = inputPaths.where((String p) => !fs.isFileSync(p)); + if (missingInputs.isNotEmpty) { + printError('Missing input files: $missingInputs'); + return -4; + } + final List genSnapshotArgs = [ '--vm_snapshot_data=$vmSnapshotData', '--isolate_snapshot_data=$isolateSnapshotData', @@ -301,56 +321,42 @@ class Snapshotter { '--url_mapping=dart:vmservice_io,$vmServicePath', '--dependencies=$depfilePath', ]; - if (previewDart2) { - genSnapshotArgs.addAll([ - '--reify-generic-functions', - '--strong', - ]); - } - if (buildMode != BuildMode.release) { - genSnapshotArgs.addAll([ - '--no-checked', - '--conditional_directives', - ]); - } - if (extraGenSnapshotOptions != null && extraGenSnapshotOptions.isNotEmpty) { - printTrace('Extra gen_snapshot options: $extraGenSnapshotOptions'); + + if ((extraGenSnapshotOptions != null) && extraGenSnapshotOptions.isNotEmpty) { + printTrace('Extra gen-snapshot options: $extraGenSnapshotOptions'); genSnapshotArgs.addAll(extraGenSnapshotOptions); } final bool interpreter = _isInterpreted(platform, buildMode); if (!interpreter) { - final String vmEntryPoints = artifacts.getArtifactPath(Artifact.dartVmEntryPointsTxt, platform, buildMode); - final String ioEntryPoints = artifacts.getArtifactPath(Artifact.dartIoEntriesTxt, platform, buildMode); genSnapshotArgs.add('--embedder_entry_points_manifest=$vmEntryPoints'); genSnapshotArgs.add('--embedder_entry_points_manifest=$ioEntryPoints'); - inputPaths..addAll([vmEntryPoints, ioEntryPoints]); } - // iOS snapshot generated files, compiled object files. + // 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 kVmSnapshotDataO = fs.path.join(outputDir.path, '$kVmSnapshotData.o'); final String kIsolateSnapshotDataO = fs.path.join(outputDir.path, '$kIsolateSnapshotData.o'); - // Compile-to-assembly outputs. - final String assembly = fs.path.join(outputDir.path, 'snapshot_assembly.S'); - final String assemblyO = fs.path.join(outputDir.path, 'snapshot_assembly.o'); - final String assemblySo = fs.path.join(outputDir.path, 'app.so'); - switch (platform) { case TargetPlatform.android_arm: case TargetPlatform.android_arm64: case TargetPlatform.android_x64: case TargetPlatform.android_x86: + final String vmSnapshotInstructions = fs.path.join(outputDir.path, 'vm_snapshot_instr'); + final String isolateSnapshotInstructions = fs.path.join(outputDir.path, 'isolate_snapshot_instr'); if (compileToSharedLibrary) { outputPaths.add(assemblySo); genSnapshotArgs.add('--snapshot_kind=app-aot-assembly'); genSnapshotArgs.add('--assembly=$assembly'); } else { - final String vmSnapshotInstructions = fs.path.join(outputDir.path, 'vm_snapshot_instr'); - final String isolateSnapshotInstructions = fs.path.join(outputDir.path, 'isolate_snapshot_instr'); - outputPaths.addAll([vmSnapshotData, isolateSnapshotData]); + outputPaths.addAll([ + vmSnapshotData, + isolateSnapshotData, + ]); genSnapshotArgs.addAll([ '--snapshot_kind=app-aot-blobs', '--vm_snapshot_instructions=$vmSnapshotInstructions', @@ -388,14 +394,13 @@ class Snapshotter { assert(false); } - // Verify that all required inputs exist. - final Iterable missingInputs = inputPaths.where((String p) => !fs.isFileSync(p)); - if (missingInputs.isNotEmpty) { - printError('Missing input files: $missingInputs from $inputPaths'); - return -4; + if (buildMode != BuildMode.release) { + genSnapshotArgs.addAll([ + '--no-checked', + '--conditional_directives', + ]); } - // If inputs and outputs have not changed since last run, skip the build. final String fingerprintPath = '$depfilePath.fingerprint'; final SnapshotType snapshotType = new SnapshotType(platform, buildMode); if (!await _isBuildRequired(snapshotType, outputPaths, depfilePath, mainPath, fingerprintPath)) { @@ -403,6 +408,12 @@ class Snapshotter { return 0; } + if (previewDart2) { + genSnapshotArgs.addAll([ + '--reify-generic-functions', + '--strong', + ]); + } genSnapshotArgs.add(mainPath); final int genSnapshotExitCode = await genSnapshot.run( @@ -425,10 +436,12 @@ class Snapshotter { if (platform == TargetPlatform.ios) { printStatus('Building App.framework...'); + final String kVmSnapshotDataC = fs.path.join(outputDir.path, '$kVmSnapshotData.c'); + final String kIsolateSnapshotDataC = fs.path.join(outputDir.path, '$kIsolateSnapshotData.c'); + const List commonBuildOptions = const ['-arch', 'arm64', '-miphoneos-version-min=8.0']; + if (interpreter) { - final String kVmSnapshotDataC = fs.path.join(outputDir.path, '$kVmSnapshotData.c'); - final String kIsolateSnapshotDataC = fs.path.join(outputDir.path, '$kIsolateSnapshotData.c'); await fs.file(vmSnapshotData).rename(fs.path.join(outputDir.path, kVmSnapshotData)); await fs.file(isolateSnapshotData).rename(fs.path.join(outputDir.path, kIsolateSnapshotData)); @@ -484,14 +497,6 @@ class Snapshotter { return 0; } - bool _isValidAotPlatform(TargetPlatform platform) { - return const [ - TargetPlatform.android_arm, - TargetPlatform.android_arm64, - TargetPlatform.ios, - ].contains(platform); - } - /// Returns true if the specified platform and build mode require running in interpreted mode. bool _isInterpreted(TargetPlatform platform, BuildMode buildMode) { return platform == TargetPlatform.ios && buildMode == BuildMode.debug; diff --git a/packages/flutter_tools/test/base/build_test.dart b/packages/flutter_tools/test/base/build_test.dart index d5402d6eab0..ca5e76418ca 100644 --- a/packages/flutter_tools/test/base/build_test.dart +++ b/packages/flutter_tools/test/base/build_test.dart @@ -662,12 +662,12 @@ void main() { '--url_mapping=dart:ui,${fs.path.join(skyEnginePath, 'lib', 'ui', 'ui.dart')}', '--url_mapping=dart:vmservice_io,${fs.path.join(skyEnginePath, 'sdk_ext', 'vmservice_io.dart')}', '--dependencies=${fs.path.join(outputPath, 'snapshot.d')}', - '--reify-generic-functions', - '--strong', - '--no-checked', - '--conditional_directives', '--snapshot_kind=core', 'snapshot.dart', + '--no-checked', + '--conditional_directives', + '--reify-generic-functions', + '--strong', 'main.dill', ]); }, overrides: contextOverrides); @@ -704,14 +704,14 @@ void main() { '--url_mapping=dart:ui,${fs.path.join(skyEnginePath, 'lib', 'ui', 'ui.dart')}', '--url_mapping=dart:vmservice_io,${fs.path.join(skyEnginePath, 'sdk_ext', 'vmservice_io.dart')}', '--dependencies=${fs.path.join(outputPath, 'snapshot.d')}', - '--reify-generic-functions', - '--strong', - '--no-checked', - '--conditional_directives', '--embedder_entry_points_manifest=$kVmEntrypoints', '--embedder_entry_points_manifest=$kIoEntries', '--snapshot_kind=app-aot-assembly', '--assembly=${fs.path.join(outputPath, 'snapshot_assembly.S')}', + '--no-checked', + '--conditional_directives', + '--reify-generic-functions', + '--strong', 'main.dill', ]); }, overrides: contextOverrides); @@ -748,12 +748,12 @@ void main() { '--url_mapping=dart:ui,${fs.path.join(skyEnginePath, 'lib', 'ui', 'ui.dart')}', '--url_mapping=dart:vmservice_io,${fs.path.join(skyEnginePath, 'sdk_ext', 'vmservice_io.dart')}', '--dependencies=${fs.path.join(outputPath, 'snapshot.d')}', - '--reify-generic-functions', - '--strong', '--embedder_entry_points_manifest=$kVmEntrypoints', '--embedder_entry_points_manifest=$kIoEntries', '--snapshot_kind=app-aot-assembly', '--assembly=${fs.path.join(outputPath, 'snapshot_assembly.S')}', + '--reify-generic-functions', + '--strong', 'main.dill', ]); }, overrides: contextOverrides);