Skip to content

Commit

Permalink
Download Android AOT tools to the artifacts cache and build APKs usin…
Browse files Browse the repository at this point in the history
…g these tools (flutter#3649)

Also update the engine to a build where these tools have been uplaoded
  • Loading branch information
jason-simmons committed May 2, 2016
1 parent 21f1827 commit f161f23
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 35 deletions.
2 changes: 1 addition & 1 deletion bin/cache/engine.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6e3228cf81e6fcb6bfd2ad1983fb8949dd7cc88b
76d5cf230adb6a650022d87d8c76c3fe7fa97c09
5 changes: 5 additions & 0 deletions packages/flutter_tools/lib/src/build_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 18 additions & 10 deletions packages/flutter_tools/lib/src/cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class FlutterEngine {
List<String> _getEngineDirs() {
List<String> dirs = <String>[
'android-arm',
'android-arm-profile',
'android-arm-release',
'android-x64'
];
Expand All @@ -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() {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
}
Expand Down
37 changes: 24 additions & 13 deletions packages/flutter_tools/lib/src/commands/build_aot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -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)) {
Expand Down Expand Up @@ -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',
Expand Down
11 changes: 4 additions & 7 deletions packages/flutter_tools/lib/src/commands/build_apk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -494,21 +491,21 @@ 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;
}
}

if (aotPath != null) {
if (!_isAotBuildMode(buildMode)) {
if (!isAotBuildMode(buildMode)) {
printError('AOT snapshot can not be used in build mode $buildMode');
return 1;
}
Expand Down
1 change: 0 additions & 1 deletion packages/flutter_tools/lib/src/runner/flutter_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 2 additions & 3 deletions packages/flutter_tools/lib/src/toolchain.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f161f23

Please sign in to comment.