Commit 612a097d authored by Adam Barth's avatar Adam Barth

Add --target support to flutter build ios (#4318)

Fixes #4298
parent bc5d4074
...@@ -49,6 +49,7 @@ BuildApp() { ...@@ -49,6 +49,7 @@ BuildApp() {
RunCommand ${FLUTTER_ROOT}/bin/flutter --suppress-analytics build aot \ RunCommand ${FLUTTER_ROOT}/bin/flutter --suppress-analytics build aot \
--target-platform=ios \ --target-platform=ios \
--target=${FLUTTER_TARGET} \
--release \ --release \
${interpreter_flag} \ ${interpreter_flag} \
${local_engine_flag} ${local_engine_flag}
...@@ -69,6 +70,7 @@ BuildApp() { ...@@ -69,6 +70,7 @@ BuildApp() {
fi fi
RunCommand ${FLUTTER_ROOT}/bin/flutter --suppress-analytics build flx \ RunCommand ${FLUTTER_ROOT}/bin/flutter --suppress-analytics build flx \
--target=${FLUTTER_TARGET} \
--output-file=${derived_dir}/app.flx \ --output-file=${derived_dir}/app.flx \
${precompilation_flag} \ ${precompilation_flag} \
${local_engine_flag} \ ${local_engine_flag} \
......
...@@ -15,6 +15,7 @@ import '../runner/flutter_command.dart'; ...@@ -15,6 +15,7 @@ import '../runner/flutter_command.dart';
class BuildIOSCommand extends FlutterCommand { class BuildIOSCommand extends FlutterCommand {
BuildIOSCommand() { BuildIOSCommand() {
usesTargetOption();
addBuildModeFlags(); addBuildModeFlags();
argParser.addFlag('simulator', help: 'Build for the iOS simulator instead of the device.'); argParser.addFlag('simulator', help: 'Build for the iOS simulator instead of the device.');
argParser.addFlag('codesign', negatable: true, defaultsTo: true, argParser.addFlag('codesign', negatable: true, defaultsTo: true,
...@@ -53,9 +54,13 @@ class BuildIOSCommand extends FlutterCommand { ...@@ -53,9 +54,13 @@ class BuildIOSCommand extends FlutterCommand {
String typeName = path.basename(tools.getEngineArtifactsDirectory(TargetPlatform.ios, getBuildMode()).path); String typeName = path.basename(tools.getEngineArtifactsDirectory(TargetPlatform.ios, getBuildMode()).path);
Status status = logger.startProgress('Building $app for $logTarget ($typeName)...'); Status status = logger.startProgress('Building $app for $logTarget ($typeName)...');
XcodeBuildResult result = await buildXcodeProject(app, getBuildMode(), XcodeBuildResult result = await buildXcodeProject(
buildForDevice: !forSimulator, app: app,
codesign: shouldCodesign); mode: getBuildMode(),
target: argResults['target'],
buildForDevice: !forSimulator,
codesign: shouldCodesign
);
status.stop(showElapsedTime: true); status.stop(showElapsedTime: true);
if (!result.success) { if (!result.success) {
......
...@@ -180,7 +180,7 @@ class IOSDevice extends Device { ...@@ -180,7 +180,7 @@ class IOSDevice extends Device {
printTrace('Building ${app.name} for $id'); printTrace('Building ${app.name} for $id');
// Step 1: Install the precompiled/DBC application if necessary. // Step 1: Install the precompiled/DBC application if necessary.
XcodeBuildResult buildResult = await buildXcodeProject(app, mode, buildForDevice: true); XcodeBuildResult buildResult = await buildXcodeProject(app: app, mode: mode, buildForDevice: true);
if (!buildResult.success) { if (!buildResult.success) {
printError('Could not build the precompiled application for the device.'); printError('Could not build the precompiled application for the device.');
return new LaunchResult.failed(); return new LaunchResult.failed();
......
...@@ -13,6 +13,7 @@ import '../base/context.dart'; ...@@ -13,6 +13,7 @@ import '../base/context.dart';
import '../base/process.dart'; import '../base/process.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../cache.dart'; import '../cache.dart';
import '../flx.dart' as flx;
import '../globals.dart'; import '../globals.dart';
import '../services.dart'; import '../services.dart';
import 'setup_xcodeproj.dart'; import 'setup_xcodeproj.dart';
...@@ -97,18 +98,23 @@ bool _xcodeVersionCheckValid(int major, int minor) { ...@@ -97,18 +98,23 @@ bool _xcodeVersionCheckValid(int major, int minor) {
return false; return false;
} }
Future<XcodeBuildResult> buildXcodeProject(ApplicationPackage app, BuildMode mode, Future<XcodeBuildResult> buildXcodeProject({
{ bool buildForDevice, bool codesign: true }) async { ApplicationPackage app,
BuildMode mode,
String target: flx.defaultMainPath,
bool buildForDevice,
bool codesign: true
}) async {
String flutterProjectPath = Directory.current.path; String flutterProjectPath = Directory.current.path;
if (xcodeProjectRequiresUpdate(mode)) { if (xcodeProjectRequiresUpdate(mode)) {
printTrace('Initializing the Xcode project.'); printTrace('Initializing the Xcode project.');
if ((await setupXcodeProjectHarness(flutterProjectPath, mode)) != 0) { if ((await setupXcodeProjectHarness(flutterProjectPath, mode, target)) != 0) {
printError('Could not initialize the Xcode project.'); printError('Could not initialize the Xcode project.');
return new XcodeBuildResult(false); return new XcodeBuildResult(false);
} }
} else { } else {
updateXcodeGeneratedProperties(flutterProjectPath, mode); updateXcodeGeneratedProperties(flutterProjectPath, mode, target);
} }
if (!_validateEngineRevision(app)) if (!_validateEngineRevision(app))
......
...@@ -54,7 +54,7 @@ bool _inflateXcodeArchive(String directory, List<int> archiveBytes) { ...@@ -54,7 +54,7 @@ bool _inflateXcodeArchive(String directory, List<int> archiveBytes) {
return true; return true;
} }
void updateXcodeGeneratedProperties(String projectPath, BuildMode mode) { void updateXcodeGeneratedProperties(String projectPath, BuildMode mode, String target) {
StringBuffer localsBuffer = new StringBuffer(); StringBuffer localsBuffer = new StringBuffer();
localsBuffer.writeln('// This is a generated file; do not edit or check into version control.'); localsBuffer.writeln('// This is a generated file; do not edit or check into version control.');
...@@ -66,6 +66,9 @@ void updateXcodeGeneratedProperties(String projectPath, BuildMode mode) { ...@@ -66,6 +66,9 @@ void updateXcodeGeneratedProperties(String projectPath, BuildMode mode) {
String applicationRoot = path.normalize(Directory.current.path); String applicationRoot = path.normalize(Directory.current.path);
localsBuffer.writeln('FLUTTER_APPLICATION_PATH=$applicationRoot'); localsBuffer.writeln('FLUTTER_APPLICATION_PATH=$applicationRoot');
// Relative to FLUTTER_APPLICATION_PATH, which is [Directory.current].
localsBuffer.writeln('FLUTTER_TARGET=$target');
String flutterFrameworkDir = path.normalize(tools.getEngineArtifactsDirectory(TargetPlatform.ios, mode).path); String flutterFrameworkDir = path.normalize(tools.getEngineArtifactsDirectory(TargetPlatform.ios, mode).path);
localsBuffer.writeln('FLUTTER_FRAMEWORK_DIR=$flutterFrameworkDir'); localsBuffer.writeln('FLUTTER_FRAMEWORK_DIR=$flutterFrameworkDir');
...@@ -97,7 +100,7 @@ bool xcodeProjectRequiresUpdate(BuildMode mode) { ...@@ -97,7 +100,7 @@ bool xcodeProjectRequiresUpdate(BuildMode mode) {
return false; return false;
} }
Future<int> setupXcodeProjectHarness(String flutterProjectPath, BuildMode mode) async { Future<int> setupXcodeProjectHarness(String flutterProjectPath, BuildMode mode, String target) async {
// Step 1: Fetch the archive from the cloud // Step 1: Fetch the archive from the cloud
String iosFilesPath = path.join(flutterProjectPath, 'ios'); String iosFilesPath = path.join(flutterProjectPath, 'ios');
String xcodeprojPath = path.join(iosFilesPath, '.generated'); String xcodeprojPath = path.join(iosFilesPath, '.generated');
...@@ -119,7 +122,7 @@ Future<int> setupXcodeProjectHarness(String flutterProjectPath, BuildMode mode) ...@@ -119,7 +122,7 @@ Future<int> setupXcodeProjectHarness(String flutterProjectPath, BuildMode mode)
} }
// Step 3: Populate the Generated.xcconfig with project specific paths // Step 3: Populate the Generated.xcconfig with project specific paths
updateXcodeGeneratedProperties(flutterProjectPath, mode); updateXcodeGeneratedProperties(flutterProjectPath, mode, target);
// Step 4: Write the REVISION file // Step 4: Write the REVISION file
File revisionFile = new File(path.join(xcodeprojPath, 'REVISION')); File revisionFile = new File(path.join(xcodeprojPath, 'REVISION'));
......
...@@ -548,7 +548,7 @@ class IOSSimulator extends Device { ...@@ -548,7 +548,7 @@ class IOSSimulator extends Device {
Future<bool> _buildAndInstallApplicationBundle(ApplicationPackage app) async { Future<bool> _buildAndInstallApplicationBundle(ApplicationPackage app) async {
// Step 1: Build the Xcode project. // Step 1: Build the Xcode project.
// The build mode for the simulator is always debug. // The build mode for the simulator is always debug.
XcodeBuildResult buildResult = await buildXcodeProject(app, BuildMode.debug, buildForDevice: false); XcodeBuildResult buildResult = await buildXcodeProject(app: app, mode: BuildMode.debug, buildForDevice: false);
if (!buildResult.success) { if (!buildResult.success) {
printError('Could not build the application for the simulator.'); printError('Could not build the application for the simulator.');
return false; return false;
......
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