Xcode backend refactor (#23387)
* Use Xcode build configurations to drive Flutter build mode
This commit is contained in:
@@ -298,6 +298,35 @@ Future<XcodeBuildResult> buildXcodeProject({
|
||||
printError(' open ios/Runner.xcworkspace');
|
||||
return XcodeBuildResult(success: false);
|
||||
}
|
||||
if (!projectInfo.hasBuildConfiguratinForBuildMode(buildInfo.modeName)) {
|
||||
// This error will occur with previous versions of the generated Xcode project, where a "Profile"
|
||||
// build configuration did not exist. It may also occur if a user manually removes or renames
|
||||
// configurations from Runner.xcodeproj.
|
||||
printError('The Xcode project does not define a build configuration "${buildInfo.modeName}",');
|
||||
printError('which is needed by Flutter tooling to run "--${buildInfo.modeName}" from the command line.');
|
||||
printError('');
|
||||
printError('Open Xcode to fix the problem:');
|
||||
printError(' open ios/Runner.xcodeproj');
|
||||
printError('');
|
||||
printError('1. Click on "Runner" in the project navigator.');
|
||||
printError('2. Ensure the Runner PROJECT is selected, not the Runner TARGET.');
|
||||
if (buildInfo.isDebug) {
|
||||
printError('3. Click the Editor->Add Configuration->Duplicate "Debug" Configuration.');
|
||||
} else {
|
||||
printError('3. Click the Editor->Add Configuration->Duplicate "Release" Configuration.');
|
||||
}
|
||||
printError('');
|
||||
printError(' If this option is disabled, it is likely you have the target selected instead');
|
||||
printError(' of the project; see:');
|
||||
printError(' https://stackoverflow.com/questions/19842746/adding-a-build-configuration-in-xcode');
|
||||
printError('');
|
||||
printError(' If you have created a completely custom set of build configurations,');
|
||||
printError(' you can set the FLUTTER_BUILD_MODE=${buildInfo.modeName.toLowerCase()}');
|
||||
printError(' in the .xcconfig file for that configuration and run from Xcode.');
|
||||
printError('');
|
||||
printError('4. If you are not using completely custom build configurations, name the newly created configuration ${buildInfo.modeName}.');
|
||||
return XcodeBuildResult(success: false);
|
||||
}
|
||||
final String scheme = projectInfo.schemeFor(buildInfo);
|
||||
if (scheme == null) {
|
||||
printError('');
|
||||
|
||||
@@ -49,21 +49,11 @@ Future<void> updateGeneratedXcodeProperties({
|
||||
if (targetOverride != null)
|
||||
localsBuffer.writeln('FLUTTER_TARGET=$targetOverride');
|
||||
|
||||
// The runtime mode for the current build.
|
||||
localsBuffer.writeln('FLUTTER_BUILD_MODE=${buildInfo.modeName}');
|
||||
|
||||
// The build outputs directory, relative to FLUTTER_APPLICATION_PATH.
|
||||
localsBuffer.writeln('FLUTTER_BUILD_DIR=${getBuildDirectory()}');
|
||||
|
||||
localsBuffer.writeln('SYMROOT=\${SOURCE_ROOT}/../${getIosBuildDirectory()}');
|
||||
|
||||
if (!project.isModule) {
|
||||
// For module projects we do not want to write the FLUTTER_FRAMEWORK_DIR
|
||||
// explicitly. Rather we rely on the xcode backend script and the Podfile
|
||||
// logic to derive it from FLUTTER_ROOT and FLUTTER_BUILD_MODE.
|
||||
localsBuffer.writeln('FLUTTER_FRAMEWORK_DIR=${flutterFrameworkDir(buildInfo.mode)}');
|
||||
}
|
||||
|
||||
final String buildName = buildInfo?.buildName ?? project.manifest.buildName;
|
||||
if (buildName != null) {
|
||||
localsBuffer.writeln('FLUTTER_BUILD_NAME=$buildName');
|
||||
@@ -247,6 +237,17 @@ class XcodeProjectInfo {
|
||||
return baseConfiguration + '-$scheme';
|
||||
}
|
||||
|
||||
/// Checks whether the [buildConfigurations] contains the specified string, without
|
||||
/// regard to case.
|
||||
bool hasBuildConfiguratinForBuildMode(String buildMode) {
|
||||
buildMode = buildMode.toLowerCase();
|
||||
for (String name in buildConfigurations) {
|
||||
if (name.toLowerCase() == buildMode) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/// Returns unique scheme matching [buildInfo], or null, if there is no unique
|
||||
/// best match.
|
||||
String schemeFor(BuildInfo buildInfo) {
|
||||
@@ -274,7 +275,13 @@ class XcodeProjectInfo {
|
||||
});
|
||||
}
|
||||
|
||||
static String _baseConfigurationFor(BuildInfo buildInfo) => buildInfo.isDebug ? 'Debug' : 'Release';
|
||||
static String _baseConfigurationFor(BuildInfo buildInfo) {
|
||||
if (buildInfo.isDebug)
|
||||
return 'Debug';
|
||||
if (buildInfo.isProfile)
|
||||
return 'Profile';
|
||||
return 'Release';
|
||||
}
|
||||
|
||||
static String _uniqueMatch(Iterable<String> strings, bool matches(String s)) {
|
||||
final List<String> options = strings.where(matches).toList();
|
||||
|
||||
Reference in New Issue
Block a user