| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 | 7 |
| 8 import 'package:path/path.dart' as path; | 8 import 'package:path/path.dart' as path; |
| 9 | 9 |
| 10 import '../base/common.dart'; | 10 import '../base/common.dart'; |
| 11 import '../base/logger.dart'; | 11 import '../base/logger.dart'; |
| 12 import '../base/process.dart'; | 12 import '../base/process.dart'; |
| 13 import '../base/utils.dart'; | 13 import '../base/utils.dart'; |
| 14 import '../build_info.dart'; | 14 import '../build_info.dart'; |
| 15 import '../dart/package_map.dart'; | 15 import '../dart/package_map.dart'; |
| 16 import '../globals.dart'; | 16 import '../globals.dart'; |
| 17 import '../resident_runner.dart'; | 17 import '../resident_runner.dart'; |
| 18 import '../toolchain.dart'; |
| 18 import 'build.dart'; | 19 import 'build.dart'; |
| 19 | 20 |
| 20 // Files generated by the ahead-of-time snapshot builder. | 21 // Files generated by the ahead-of-time snapshot builder. |
| 21 const List<String> kAotSnapshotFiles = const <String>[ | 22 const List<String> kAotSnapshotFiles = const <String>[ |
| 22 'snapshot_aot_instr', 'snapshot_aot_isolate', 'snapshot_aot_rodata', 'snapshot
_aot_vmisolate', | 23 'snapshot_aot_instr', 'snapshot_aot_isolate', 'snapshot_aot_rodata', 'snapshot
_aot_vmisolate', |
| 23 ]; | 24 ]; |
| 24 | 25 |
| 25 class BuildAotCommand extends BuildSubCommand { | 26 class BuildAotCommand extends BuildSubCommand { |
| 26 BuildAotCommand() { | 27 BuildAotCommand() { |
| 27 usesTargetOption(); | 28 usesTargetOption(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 45 @override | 46 @override |
| 46 Future<Null> runCommand() async { | 47 Future<Null> runCommand() async { |
| 47 await super.runCommand(); | 48 await super.runCommand(); |
| 48 String targetPlatform = argResults['target-platform']; | 49 String targetPlatform = argResults['target-platform']; |
| 49 TargetPlatform platform = getTargetPlatformForName(targetPlatform); | 50 TargetPlatform platform = getTargetPlatformForName(targetPlatform); |
| 50 if (platform == null) | 51 if (platform == null) |
| 51 throwToolExit('Unknown platform: $targetPlatform'); | 52 throwToolExit('Unknown platform: $targetPlatform'); |
| 52 | 53 |
| 53 String typeName = path.basename(tools.getEngineArtifactsDirectory(platform,
getBuildMode()).path); | 54 String typeName = path.basename(tools.getEngineArtifactsDirectory(platform,
getBuildMode()).path); |
| 54 Status status = logger.startProgress('Building AOT snapshot in ${getModeName
(getBuildMode())} mode ($typeName)...'); | 55 Status status = logger.startProgress('Building AOT snapshot in ${getModeName
(getBuildMode())} mode ($typeName)...'); |
| 55 String outputPath = await buildAotSnapshot( | 56 String dartFile = findMainDartFile(targetFile); |
| 56 findMainDartFile(targetFile), | 57 String dillFile = await buildDilFile(dartFile); |
| 58 String outputPath = await buildAotSnapshot( |
| 59 dillFile != null ? dillFile : dartFile, |
| 57 platform, | 60 platform, |
| 58 getBuildMode(), | 61 getBuildMode(), |
| 59 outputPath: argResults['output-dir'], | 62 outputPath: argResults['output-dir'], |
| 60 interpreter: argResults['interpreter'] | 63 interpreter: argResults['interpreter'] |
| 61 ); | 64 ); |
| 62 status.stop(); | 65 status.stop(); |
| 63 | 66 |
| 64 if (outputPath == null) | 67 if (outputPath == null) |
| 65 throwToolExit(null); | 68 throwToolExit(null); |
| 66 | 69 |
| 67 printStatus('Built to $outputPath${Platform.pathSeparator}.'); | 70 printStatus('Built to $outputPath${Platform.pathSeparator}.'); |
| 68 } | 71 } |
| 69 } | 72 } |
| 70 | 73 |
| 71 String _getSdkExtensionPath(PackageMap packageMap, String package) { | 74 String _getSdkExtensionPath(PackageMap packageMap, String package) { |
| 72 return path.dirname(packageMap.map[package].toFilePath()); | 75 return path.dirname(packageMap.map[package].toFilePath()); |
| 73 } | 76 } |
| 74 | 77 |
| 78 |
| 79 Future<String> buildDilFile(String dartFile) async { |
| 80 String engineSourcePath = ToolConfiguration.instance.engineSrcPath; |
| 81 String engineBuildPath = ToolConfiguration.instance.engineBuildPath; |
| 82 if (engineSourcePath == null) { |
| 83 throw new Exception('Engine source path not found!'); |
| 84 } |
| 85 if (engineBuildPath == null) { |
| 86 throw new Exception('Engine build path path not found!'); |
| 87 } |
| 88 String buildScript = path.join( |
| 89 engineSourcePath, 'dart/pkg/kernel/bin/dartk.dart'); |
| 90 String transformScript = path.join( |
| 91 engineSourcePath, 'dart/pkg/kernel/bin/transform.dart'); |
| 92 String patchedSdk = path.join( |
| 93 engineBuildPath, 'patched_sdk'); |
| 94 |
| 95 PackageMap packageMap = new PackageMap(PackageMap.globalPackagesPath); |
| 96 String packageMapError = packageMap.checkValid(); |
| 97 if (packageMapError != null) { |
| 98 printError(packageMapError); |
| 99 return null; |
| 100 } |
| 101 |
| 102 String skyEnginePkg = _getSdkExtensionPath(packageMap, 'sky_engine'); |
| 103 String uiPath = path.join(skyEnginePkg, 'dart_ui', 'ui.dart'); |
| 104 String jniPath = path.join(skyEnginePkg, 'dart_jni', 'jni.dart'); |
| 105 String vmServicePath = path.join(skyEnginePkg, 'sdk_ext', 'vmservice_io.dart')
; |
| 106 |
| 107 String dillFile = dartFile.replaceAll('.dart', '.dill'); |
| 108 String transformedDillFile = dartFile.replaceAll('.dart', '.transformed.dill')
; |
| 109 String inferredDillFile = dartFile.replaceAll('.dart', '.transformed.inferred.
dill'); |
| 110 RunResult results = await runAsync(<String>[ |
| 111 'dart', |
| 112 '-c', |
| 113 buildScript, |
| 114 dartFile, |
| 115 '--target=flutter', |
| 116 '--link', |
| 117 '--sdk=$patchedSdk', |
| 118 '-o', |
| 119 dillFile, |
| 120 '--url-mapping=dart:ui::$uiPath', |
| 121 '--url-mapping=dart:jni::$jniPath', |
| 122 '--url-mapping=dart:vmservice_sky::$vmServicePath', |
| 123 ]); |
| 124 if (results.exitCode != 0) { |
| 125 printStatus(results.toString()); |
| 126 return null; |
| 127 } |
| 128 results = await runAsync(<String>[ |
| 129 transformScript, |
| 130 '-o', |
| 131 transformedDillFile, |
| 132 dillFile, |
| 133 ]); |
| 134 if (results.exitCode != 0) { |
| 135 printStatus(results.toString()); |
| 136 return null; |
| 137 } |
| 138 |
| 139 bool disableInference = false; |
| 140 //bool disableInference = true; |
| 141 if (disableInference) return transformedDillFile; |
| 142 |
| 143 results = await runAsync(<String>[ |
| 144 transformScript, |
| 145 '-t', |
| 146 'infervalues', |
| 147 '-o', |
| 148 inferredDillFile, |
| 149 transformedDillFile, |
| 150 ]); |
| 151 if (results.exitCode != 0) { |
| 152 printStatus(results.toString()); |
| 153 return null; |
| 154 } |
| 155 |
| 156 return inferredDillFile; |
| 157 } |
| 158 |
| 75 /// Build an AOT snapshot. Return `null` (and log to `printError`) if the method | 159 /// Build an AOT snapshot. Return `null` (and log to `printError`) if the method |
| 76 /// fails. | 160 /// fails. |
| 77 Future<String> buildAotSnapshot( | 161 Future<String> buildAotSnapshot( |
| 78 String mainPath, | 162 String mainPath, |
| 79 TargetPlatform platform, | 163 TargetPlatform platform, |
| 80 BuildMode buildMode, { | 164 BuildMode buildMode, { |
| 81 String outputPath, | 165 String outputPath, |
| 82 bool interpreter: false | 166 bool interpreter: false |
| 83 }) async { | 167 }) async { |
| 84 outputPath ??= getAotBuildDirectory(); | 168 outputPath ??= getAotBuildDirectory(); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 linkCommand.add(kVmIsolateSnapshotO); | 397 linkCommand.add(kVmIsolateSnapshotO); |
| 314 linkCommand.add(kIsolateSnapshotO); | 398 linkCommand.add(kIsolateSnapshotO); |
| 315 } else { | 399 } else { |
| 316 linkCommand.add(assemblyO); | 400 linkCommand.add(assemblyO); |
| 317 } | 401 } |
| 318 runCheckedSync(linkCommand); | 402 runCheckedSync(linkCommand); |
| 319 } | 403 } |
| 320 | 404 |
| 321 return outputPath; | 405 return outputPath; |
| 322 } | 406 } |
| OLD | NEW |