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