Let flutter build aot select a target platform (#4154)
Currently only android-arm and ios are supported target platforms.
This commit is contained in:
@@ -69,6 +69,24 @@ String getNameForTargetPlatform(TargetPlatform platform) {
|
||||
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() {
|
||||
if (Platform.isMacOS)
|
||||
return HostPlatform.darwin_x64;
|
||||
|
||||
@@ -25,7 +25,12 @@ class BuildAotCommand extends FlutterCommand {
|
||||
usesTargetOption();
|
||||
addBuildModeFlags();
|
||||
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
|
||||
@@ -36,9 +41,15 @@ class BuildAotCommand extends FlutterCommand {
|
||||
|
||||
@override
|
||||
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(
|
||||
findMainDartFile(argResults['target']),
|
||||
TargetPlatform.android_arm,
|
||||
platform,
|
||||
getBuildMode(),
|
||||
outputPath: argResults['output-dir']
|
||||
);
|
||||
@@ -66,6 +77,11 @@ String buildAotSnapshot(
|
||||
return null;
|
||||
}
|
||||
|
||||
if (platform != TargetPlatform.android_arm && platform != TargetPlatform.ios) {
|
||||
printError('${getNameForTargetPlatform(platform)} does not support AOT compilation.');
|
||||
return null;
|
||||
}
|
||||
|
||||
String entryPointsDir, genSnapshot;
|
||||
|
||||
String engineSrc = tools.engineSrcPath;
|
||||
|
||||
@@ -22,7 +22,7 @@ class BuildIOSCommand extends FlutterCommand {
|
||||
final String name = 'ios';
|
||||
|
||||
@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
|
||||
Future<int> runInProject() async {
|
||||
@@ -46,7 +46,7 @@ class BuildIOSCommand extends FlutterCommand {
|
||||
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...');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user