Commit f161f239 authored by Jason Simmons's avatar Jason Simmons

Download Android AOT tools to the artifacts cache and build APKs using these tools (#3649)

Also update the engine to a build where these tools have been uplaoded
parent 21f1827b
6e3228cf81e6fcb6bfd2ad1983fb8949dd7cc88b 76d5cf230adb6a650022d87d8c76c3fe7fa97c09
...@@ -24,6 +24,11 @@ enum BuildMode { ...@@ -24,6 +24,11 @@ enum BuildMode {
String getModeName(BuildMode mode) => getEnumName(mode); String getModeName(BuildMode mode) => getEnumName(mode);
// Returns true if the selected build mode uses ahead-of-time compilation.
bool isAotBuildMode(BuildMode mode) {
return mode == BuildMode.profile || mode == BuildMode.release;
}
enum HostPlatform { enum HostPlatform {
darwin_x64, darwin_x64,
linux_x64, linux_x64,
......
...@@ -190,6 +190,7 @@ class FlutterEngine { ...@@ -190,6 +190,7 @@ class FlutterEngine {
List<String> _getEngineDirs() { List<String> _getEngineDirs() {
List<String> dirs = <String>[ List<String> dirs = <String>[
'android-arm', 'android-arm',
'android-arm-profile',
'android-arm-release', 'android-arm-release',
'android-x64' 'android-x64'
]; ];
...@@ -202,13 +203,18 @@ class FlutterEngine { ...@@ -202,13 +203,18 @@ class FlutterEngine {
return dirs; return dirs;
} }
List<String> _getToolsDirs() { // Return a list of (cache directory path, download URL path) tuples.
List<List<String>> _getToolsDirs() {
if (Platform.isMacOS) if (Platform.isMacOS)
return <String>['darwin-x64']; return <List<String>>[['darwin-x64', 'darwin-x64/artifacts.zip']];
else if (Platform.isLinux) else if (Platform.isLinux)
return <String>['linux-x64']; return <List<String>>[
['linux-x64', 'linux-x64/artifacts.zip'],
['android-arm-profile/linux-x64', 'android-arm-profile/linux-x64.zip'],
['android-arm-release/linux-x64', 'android-arm-release/linux-x64.zip'],
];
else else
return <String>[]; return <List<String>>[];
} }
bool isUpToDate() { bool isUpToDate() {
...@@ -226,8 +232,8 @@ class FlutterEngine { ...@@ -226,8 +232,8 @@ class FlutterEngine {
return false; return false;
} }
for (String dirName in _getToolsDirs()) { for (List<String> toolsDir in _getToolsDirs()) {
Directory dir = new Directory(path.join(engineDir.path, dirName)); Directory dir = new Directory(path.join(engineDir.path, toolsDir[0]));
if (!dir.existsSync()) if (!dir.existsSync())
return false; return false;
} }
...@@ -259,11 +265,13 @@ class FlutterEngine { ...@@ -259,11 +265,13 @@ class FlutterEngine {
} }
} }
for (String dirName in _getToolsDirs()) { for (List<String> toolsDir in _getToolsDirs()) {
Directory dir = new Directory(path.join(engineDir.path, dirName)); String cacheDir = toolsDir[0];
String urlPath = toolsDir[1];
Directory dir = new Directory(path.join(engineDir.path, cacheDir));
if (!dir.existsSync() || allDirty) { if (!dir.existsSync() || allDirty) {
await _downloadItem('Downloading engine tools $dirName...', await _downloadItem('Downloading engine tools $cacheDir...',
url + dirName + '/artifacts.zip', dir); url + urlPath, dir);
_makeFilesExecutable(dir); _makeFilesExecutable(dir);
} }
} }
......
...@@ -32,13 +32,13 @@ class BuildAotCommand extends FlutterCommand { ...@@ -32,13 +32,13 @@ class BuildAotCommand extends FlutterCommand {
final String name = 'aot'; final String name = 'aot';
@override @override
final String description = "Build an ahead-of-time compiled snapshot of your app's Dart code. " final String description = "Build an ahead-of-time compiled snapshot of your app's Dart code.";
"(local engine builds only)";
@override @override
Future<int> runInProject() async { Future<int> runInProject() async {
String outputPath = buildAotSnapshot( String outputPath = buildAotSnapshot(
findMainDartFile(argResults['target']), findMainDartFile(argResults['target']),
getBuildMode(),
outputPath: argResults['output-dir'] outputPath: argResults['output-dir']
); );
if (outputPath == null) if (outputPath == null)
...@@ -55,18 +55,30 @@ String _getSdkExtensionPath(String packagesPath, String package) { ...@@ -55,18 +55,30 @@ String _getSdkExtensionPath(String packagesPath, String package) {
} }
String buildAotSnapshot( String buildAotSnapshot(
String mainPath, { String mainPath,
BuildMode buildMode, {
String outputPath: _kDefaultAotOutputDir String outputPath: _kDefaultAotOutputDir
}) { }) {
String engineSrc = tools.engineSrcPath; if (!isAotBuildMode(buildMode)) {
if (engineSrc == null) { printError('${getModeName(buildMode)} mode does not support AOT compilation.');
printError('AOT compilation requires --engine-src-path');
return null; return null;
} }
String engineOut = tools.getEngineArtifactsDirectory( String entryPointsDir, genSnapshot;
TargetPlatform.android_arm, BuildMode.profile).path;
String genSnapshot = path.join(engineOut, 'clang_x86', 'gen_snapshot'); String engineSrc = tools.engineSrcPath;
if (engineSrc != null) {
entryPointsDir = path.join(engineSrc, 'sky', 'engine', 'bindings');
String engineOut = tools.getEngineArtifactsDirectory(
TargetPlatform.android_arm, buildMode).path;
genSnapshot = path.join(engineOut, 'clang_x86', 'gen_snapshot');
} else {
String artifactsDir = tools.getEngineArtifactsDirectory(
TargetPlatform.android_arm, buildMode).path;
entryPointsDir = artifactsDir;
String hostToolsDir = path.join(artifactsDir, getNameForHostPlatform(getCurrentHostPlatform()));
genSnapshot = path.join(hostToolsDir, 'gen_snapshot');
}
Directory outputDir = new Directory(outputPath); Directory outputDir = new Directory(outputPath);
outputDir.createSync(recursive: true); outputDir.createSync(recursive: true);
...@@ -75,9 +87,8 @@ String buildAotSnapshot( ...@@ -75,9 +87,8 @@ String buildAotSnapshot(
String instructionsBlob = path.join(outputDir.path, 'snapshot_aot_instr'); String instructionsBlob = path.join(outputDir.path, 'snapshot_aot_instr');
String rodataBlob = path.join(outputDir.path, 'snapshot_aot_rodata'); String rodataBlob = path.join(outputDir.path, 'snapshot_aot_rodata');
String bindingsSrc = path.join(engineSrc, 'sky', 'engine', 'bindings'); String vmEntryPoints = path.join(entryPointsDir, 'dart_vm_entry_points.txt');
String vmEntryPoints = path.join(bindingsSrc, 'dart_vm_entry_points.txt'); String vmEntryPointsAndroid = path.join(entryPointsDir, 'dart_vm_entry_points_android.txt');
String vmEntryPointsAndroid = path.join(bindingsSrc, 'dart_vm_entry_points_android.txt');
String packagesPath = path.absolute(Directory.current.path, 'packages'); String packagesPath = path.absolute(Directory.current.path, 'packages');
if (!FileSystemEntity.isDirectorySync(packagesPath)) { if (!FileSystemEntity.isDirectorySync(packagesPath)) {
...@@ -119,7 +130,7 @@ String buildAotSnapshot( ...@@ -119,7 +130,7 @@ String buildAotSnapshot(
'--no-sim-use-hardfp', '--no-sim-use-hardfp',
]; ];
if (!tools.engineRelease) { if (!(tools.engineRelease || buildMode == BuildMode.release)) {
genSnapshotCmd.addAll([ genSnapshotCmd.addAll([
'--no-checked', '--no-checked',
'--conditional_directives', '--conditional_directives',
......
...@@ -428,9 +428,6 @@ bool _needsRebuild(String apkPath, String manifest) { ...@@ -428,9 +428,6 @@ bool _needsRebuild(String apkPath, String manifest) {
return false; return false;
} }
// Returns true if the selected build mode uses ahead-of-time compilation.
bool _isAotBuildMode(BuildMode mode) => mode == BuildMode.profile;
Future<int> buildAndroid( Future<int> buildAndroid(
TargetPlatform platform, TargetPlatform platform,
BuildMode buildMode, { BuildMode buildMode, {
...@@ -494,13 +491,13 @@ Future<int> buildAndroid( ...@@ -494,13 +491,13 @@ Future<int> buildAndroid(
flxPath = await flx.buildFlx( flxPath = await flx.buildFlx(
toolchain, toolchain,
mainPath: findMainDartFile(target), mainPath: findMainDartFile(target),
precompiledSnapshot: _isAotBuildMode(buildMode), precompiledSnapshot: isAotBuildMode(buildMode),
includeRobotoFonts: false); includeRobotoFonts: false);
} }
// Build an AOT snapshot if needed. // Build an AOT snapshot if needed.
if (_isAotBuildMode(buildMode) && aotPath == null) { if (isAotBuildMode(buildMode) && aotPath == null) {
aotPath = buildAotSnapshot(findMainDartFile(target)); aotPath = buildAotSnapshot(findMainDartFile(target), buildMode);
if (aotPath == null) { if (aotPath == null) {
printError('Failed to build AOT snapshot'); printError('Failed to build AOT snapshot');
return 1; return 1;
...@@ -508,7 +505,7 @@ Future<int> buildAndroid( ...@@ -508,7 +505,7 @@ Future<int> buildAndroid(
} }
if (aotPath != null) { if (aotPath != null) {
if (!_isAotBuildMode(buildMode)) { if (!isAotBuildMode(buildMode)) {
printError('AOT snapshot can not be used in build mode $buildMode'); printError('AOT snapshot can not be used in build mode $buildMode');
return 1; return 1;
} }
......
...@@ -66,7 +66,6 @@ abstract class FlutterCommand extends Command { ...@@ -66,7 +66,6 @@ abstract class FlutterCommand extends Command {
negatable: false, negatable: false,
help: 'Build a debug version of your app (the default).'); help: 'Build a debug version of your app (the default).');
argParser.addFlag('profile', argParser.addFlag('profile',
hide: true,
negatable: false, negatable: false,
help: 'Build a profile (ahead of time compilation) version of your app.'); help: 'Build a profile (ahead of time compilation) version of your app.');
argParser.addFlag('release', argParser.addFlag('release',
......
...@@ -163,13 +163,12 @@ class ToolConfiguration { ...@@ -163,13 +163,12 @@ class ToolConfiguration {
// Return something like 'out/android_Release'. // Return something like 'out/android_Release'.
String buildOutputPath = 'out/${type}_$_modeStr'; String buildOutputPath = 'out/${type}_$_modeStr';
if (mode == BuildMode.profile) if (isAotBuildMode(mode))
buildOutputPath += '_Deploy'; buildOutputPath += '_Deploy';
return new Directory(path.join(engineSrcPath, buildOutputPath)); return new Directory(path.join(engineSrcPath, buildOutputPath));
} else { } else {
// For now, only suffix for deploy variants. String suffix = mode != BuildMode.debug ? '-${getModeName(mode)}' : '';
String suffix = mode == BuildMode.release ? '-${getModeName(mode)}' : '';
// Create something like `android-arm` or `android-arm-release`. // Create something like `android-arm` or `android-arm-release`.
String dirName = getNameForTargetPlatform(platform) + suffix; String dirName = getNameForTargetPlatform(platform) + suffix;
......
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