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