Commit cb7a6908 authored by Adam Barth's avatar Adam Barth

Let flutter build aot select a target platform (#4154)

Currently only android-arm and ios are supported target platforms.
parent 487234db
...@@ -69,6 +69,24 @@ String getNameForTargetPlatform(TargetPlatform platform) { ...@@ -69,6 +69,24 @@ String getNameForTargetPlatform(TargetPlatform platform) {
assert(false); assert(false);
} }
TargetPlatform getTargetPlatformForName(String platform) {
switch (platform) {
case 'android-arm':
return TargetPlatform.android_arm;
case 'android-x64':
return TargetPlatform.android_x64;
case 'android-x86':
return TargetPlatform.android_x86;
case 'ios':
return TargetPlatform.ios;
case 'darwin-x64':
return TargetPlatform.darwin_x64;
case 'linux-x64':
return TargetPlatform.linux_x64;
}
return null;
}
HostPlatform getCurrentHostPlatform() { HostPlatform getCurrentHostPlatform() {
if (Platform.isMacOS) if (Platform.isMacOS)
return HostPlatform.darwin_x64; return HostPlatform.darwin_x64;
......
...@@ -25,7 +25,12 @@ class BuildAotCommand extends FlutterCommand { ...@@ -25,7 +25,12 @@ class BuildAotCommand extends FlutterCommand {
usesTargetOption(); usesTargetOption();
addBuildModeFlags(); addBuildModeFlags();
usesPubOption(); usesPubOption();
argParser.addOption('output-dir', defaultsTo: _kDefaultAotOutputDir); argParser
..addOption('output-dir', defaultsTo: _kDefaultAotOutputDir)
..addOption('target-platform',
defaultsTo: 'android-arm',
allowed: <String>['android-arm', 'ios']
);
} }
@override @override
...@@ -36,9 +41,15 @@ class BuildAotCommand extends FlutterCommand { ...@@ -36,9 +41,15 @@ class BuildAotCommand extends FlutterCommand {
@override @override
Future<int> runInProject() async { Future<int> runInProject() async {
String targetPlatform = argResults['target-platform'];
TargetPlatform platform = getTargetPlatformForName(targetPlatform);
if (platform == null) {
printError('Unknown platform: $targetPlatform');
return 1;
}
String outputPath = buildAotSnapshot( String outputPath = buildAotSnapshot(
findMainDartFile(argResults['target']), findMainDartFile(argResults['target']),
TargetPlatform.android_arm, platform,
getBuildMode(), getBuildMode(),
outputPath: argResults['output-dir'] outputPath: argResults['output-dir']
); );
...@@ -66,6 +77,11 @@ String buildAotSnapshot( ...@@ -66,6 +77,11 @@ String buildAotSnapshot(
return null; return null;
} }
if (platform != TargetPlatform.android_arm && platform != TargetPlatform.ios) {
printError('${getNameForTargetPlatform(platform)} does not support AOT compilation.');
return null;
}
String entryPointsDir, genSnapshot; String entryPointsDir, genSnapshot;
String engineSrc = tools.engineSrcPath; String engineSrc = tools.engineSrcPath;
......
...@@ -22,7 +22,7 @@ class BuildIOSCommand extends FlutterCommand { ...@@ -22,7 +22,7 @@ class BuildIOSCommand extends FlutterCommand {
final String name = 'ios'; final String name = 'ios';
@override @override
final String description = 'Build an iOS application bundle (Mac OSX host only).'; final String description = 'Build an iOS application bundle (Mac OS X host only).';
@override @override
Future<int> runInProject() async { Future<int> runInProject() async {
...@@ -46,7 +46,7 @@ class BuildIOSCommand extends FlutterCommand { ...@@ -46,7 +46,7 @@ class BuildIOSCommand extends FlutterCommand {
printStatus('You will have to manually codesign before deploying to device.'); printStatus('You will have to manually codesign before deploying to device.');
} }
String logTarget = forSimulator ? "simulator" : "device"; String logTarget = forSimulator ? 'simulator' : 'device';
printStatus('Building $app for $logTarget...'); printStatus('Building $app for $logTarget...');
......
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