Commit be6501a9 authored by Simon Lightfoot's avatar Simon Lightfoot Committed by xster

Patch to fix builds with custom targets on iOS simulator. (#17734)

* Patch to fix builds with custom targets on iOS simulator. #16787

* Fix for unused import.

* Code review changes applied.
parent bb2f63f2
......@@ -82,7 +82,7 @@ class BuildIOSCommand extends BuildSubCommand {
final XcodeBuildResult result = await buildXcodeProject(
app: app,
buildInfo: buildInfo,
target: targetFile,
targetOverride: targetFile,
buildForDevice: !forSimulator,
codesign: shouldCodesign,
);
......
......@@ -167,7 +167,7 @@ class IOSDevice extends Device {
final XcodeBuildResult buildResult = await buildXcodeProject(
app: package,
buildInfo: debuggingOptions.buildInfo,
target: mainPath,
targetOverride: mainPath,
buildForDevice: true,
usesTerminalUi: usesTerminalUi,
);
......
......@@ -20,7 +20,6 @@ import '../base/process.dart';
import '../base/process_manager.dart';
import '../base/utils.dart';
import '../build_info.dart';
import '../bundle.dart' as bundle;
import '../globals.dart';
import '../plugins.dart';
import '../services.dart';
......@@ -189,7 +188,7 @@ class Xcode {
Future<XcodeBuildResult> buildXcodeProject({
BuildableIOSApp app,
BuildInfo buildInfo,
String target: bundle.defaultMainPath,
String targetOverride,
bool buildForDevice,
bool codesign: true,
bool usesTerminalUi: true,
......@@ -246,7 +245,7 @@ Future<XcodeBuildResult> buildXcodeProject({
updateGeneratedXcodeProperties(
projectPath: fs.currentDirectory.path,
buildInfo: buildInfo,
target: target,
targetOverride: targetOverride,
previewDart2: buildInfo.previewDart2,
);
......
......@@ -283,7 +283,7 @@ class IOSSimulator extends Device {
printTrace('Building ${package.name} for $id.');
try {
await _setupUpdatedApplicationBundle(package, debuggingOptions.buildInfo);
await _setupUpdatedApplicationBundle(package, debuggingOptions.buildInfo, mainPath, usesTerminalUi);
} on ToolExit catch (e) {
printError(e.message);
return new LaunchResult.failed();
......@@ -350,14 +350,14 @@ class IOSSimulator extends Device {
return criteria.reduce((bool a, bool b) => a && b);
}
Future<Null> _setupUpdatedApplicationBundle(ApplicationPackage app, BuildInfo buildInfo) async {
await _sideloadUpdatedAssetsForInstalledApplicationBundle(app, buildInfo);
Future<Null> _setupUpdatedApplicationBundle(ApplicationPackage app, BuildInfo buildInfo, String mainPath, bool usesTerminalUi) async {
await _sideloadUpdatedAssetsForInstalledApplicationBundle(app, buildInfo, mainPath);
if (!await _applicationIsInstalledAndRunning(app))
return _buildAndInstallApplicationBundle(app, buildInfo);
return _buildAndInstallApplicationBundle(app, buildInfo, mainPath, usesTerminalUi);
}
Future<Null> _buildAndInstallApplicationBundle(ApplicationPackage app, BuildInfo buildInfo) async {
Future<Null> _buildAndInstallApplicationBundle(ApplicationPackage app, BuildInfo buildInfo, String mainPath, bool usesTerminalUi) async {
// Step 1: Build the Xcode project.
// The build mode for the simulator is always debug.
......@@ -367,7 +367,13 @@ class IOSSimulator extends Device {
extraGenSnapshotOptions: buildInfo.extraGenSnapshotOptions,
preferSharedLibrary: buildInfo.preferSharedLibrary);
final XcodeBuildResult buildResult = await buildXcodeProject(app: app, buildInfo: debugBuildInfo, buildForDevice: false);
final XcodeBuildResult buildResult = await buildXcodeProject(
app: app,
buildInfo: debugBuildInfo,
targetOverride: mainPath,
buildForDevice: false,
usesTerminalUi: usesTerminalUi,
);
if (!buildResult.success)
throwToolExit('Could not build the application for the simulator.');
......@@ -382,10 +388,11 @@ class IOSSimulator extends Device {
await SimControl.instance.install(id, fs.path.absolute(bundle.path));
}
Future<Null> _sideloadUpdatedAssetsForInstalledApplicationBundle(ApplicationPackage app, BuildInfo buildInfo) {
Future<Null> _sideloadUpdatedAssetsForInstalledApplicationBundle(ApplicationPackage app, BuildInfo buildInfo, String mainPath) {
// When running in previewDart2 mode, we still need to run compiler to
// produce kernel file for the application.
return bundle.build(
mainPath: mainPath,
precompiledSnapshot: !buildInfo.previewDart2,
previewDart2: buildInfo.previewDart2,
trackWidgetCreation: buildInfo.trackWidgetCreation,
......
......@@ -37,17 +37,20 @@ void generateXcodeProperties(String projectPath) {
updateGeneratedXcodeProperties(
projectPath: projectPath,
buildInfo: BuildInfo.debug,
target: bundle.defaultMainPath,
targetOverride: bundle.defaultMainPath,
previewDart2: false,
);
}
}
/// Writes or rewrites Xcode property files with the specified information.
///
/// targetOverride: Optional parameter, if null or unspecified the default value
/// from xcode_backend.sh is used 'lib/main.dart'.
void updateGeneratedXcodeProperties({
@required String projectPath,
@required BuildInfo buildInfo,
@required String target,
String targetOverride,
@required bool previewDart2,
}) {
final StringBuffer localsBuffer = new StringBuffer();
......@@ -61,7 +64,8 @@ void updateGeneratedXcodeProperties({
localsBuffer.writeln('FLUTTER_APPLICATION_PATH=${fs.path.normalize(projectPath)}');
// Relative to FLUTTER_APPLICATION_PATH, which is [Directory.current].
localsBuffer.writeln('FLUTTER_TARGET=$target');
if (targetOverride != null)
localsBuffer.writeln('FLUTTER_TARGET=$targetOverride');
// The runtime mode for the current build.
localsBuffer.writeln('FLUTTER_BUILD_MODE=${buildInfo.modeName}');
......
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