Commit a45e4e92 authored by Chris Bracken's avatar Chris Bracken

Support Xcode variable substitution in Info.plist

As of Xcode 7, Apple recommends setting CFBundleIdentifier to
$(PRODUCT_BUNDLE_IDENTIFIER).
parent 55f48f72
......@@ -12,6 +12,7 @@ import 'base/process.dart';
import 'build_info.dart';
import 'globals.dart';
import 'ios/plist_utils.dart';
import 'ios/xcodeproj.dart';
abstract class ApplicationPackage {
/// Package ID from the Android Manifest or equivalent.
......@@ -137,6 +138,8 @@ class IOSApp extends ApplicationPackage {
String value = getValueFromFile(plistPath, kCFBundleIdentifierKey);
if (value == null)
return null;
String projectPath = path.join('ios', 'Runner.xcodeproj');
value = substituteXcodeVariables(value, projectPath, 'Runner');
return new IOSApp(
appDirectory: path.join('ios'),
......
......@@ -15,7 +15,7 @@ import '../build_info.dart';
import '../flx.dart' as flx;
import '../globals.dart';
import '../services.dart';
import 'setup_xcodeproj.dart';
import 'xcodeproj.dart';
String get homeDirectory => path.absolute(Platform.environment['HOME']);
......
......@@ -6,10 +6,14 @@ import 'dart:io';
import 'package:path/path.dart' as path;
import '../base/process.dart';
import '../build_info.dart';
import '../cache.dart';
import '../globals.dart';
final RegExp _settingExpr = new RegExp(r'(\w+)\s*=\s*(\S+)');
final RegExp _varExpr = new RegExp(r'\$\((.*)\)');
void updateXcodeGeneratedProperties(String projectPath, BuildMode mode, String target) {
StringBuffer localsBuffer = new StringBuffer();
......@@ -43,3 +47,28 @@ void updateXcodeGeneratedProperties(String projectPath, BuildMode mode, String t
localsFile.createSync(recursive: true);
localsFile.writeAsStringSync(localsBuffer.toString());
}
Map<String, String> getXcodeBuildSettings(String xcodeProjPath, String target) {
String absProjPath = path.absolute(xcodeProjPath);
String out = runCheckedSync(<String>[
'/usr/bin/xcodebuild', '-project', absProjPath, '-target', target, '-showBuildSettings'
]);
Map<String, String> settings = <String, String>{};
for (String line in out.split('\n').where(_settingExpr.hasMatch)) {
Match match = _settingExpr.firstMatch(line);
settings[match[1]] = match[2];
}
return settings;
}
/// Substitutes variables in [str] with their values from the specified Xcode
/// project and target.
String substituteXcodeVariables(String str, String xcodeProjPath, String target) {
Iterable<Match> matches = _varExpr.allMatches(str);
if (matches.isEmpty)
return str;
Map<String, String> settings = getXcodeBuildSettings(xcodeProjPath, target);
return str.replaceAllMapped(_varExpr, (Match m) => settings[m[1]] ?? m[0]);
}
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