You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2014/09/05 20:14:33 UTC
[28/50] git commit: CB-7118 iOS: add target-device and
MinimumOSVersion support to config.xml
CB-7118 iOS: add target-device and MinimumOSVersion support to config.xml
github: close #57
Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/db00cdcd
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/db00cdcd
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/db00cdcd
Branch: refs/heads/master
Commit: db00cdcd01b7cb249a755e5ecc46c33e7f92134d
Parents: 2207e47
Author: sgrebnov <v-...@microsoft.com>
Authored: Fri Jul 11 09:44:50 2014 +0400
Committer: Anis Kadri <an...@apache.org>
Committed: Fri Sep 5 11:12:19 2014 -0700
----------------------------------------------------------------------
cordova-lib/src/cordova/metadata/ios_parser.js | 71 +++++++++++++++++++--
1 file changed, 64 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/db00cdcd/cordova-lib/src/cordova/metadata/ios_parser.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/metadata/ios_parser.js b/cordova-lib/src/cordova/metadata/ios_parser.js
index a6254ac..f43f194 100644
--- a/cordova-lib/src/cordova/metadata/ios_parser.js
+++ b/cordova-lib/src/cordova/metadata/ios_parser.js
@@ -134,11 +134,17 @@ module.exports.prototype = {
shell.cp('-f', src, dest);
}
});
+
+ var me = this;
+ return this.update_build_settings(config).then(function() {
+ if (name == me.originalName) {
+ events.emit('verbose', 'iOS Product Name has not changed (still "' + me.originalName + '")');
+ return Q();
+ }
- if (name != this.originalName) {
// Update product name inside pbxproj file
- var proj = new xcode.project(this.pbxproj);
- var parser = this;
+ var proj = new xcode.project(me.pbxproj);
+ var parser = me;
var d = Q.defer();
proj.parse(function(err,hash) {
if (err) {
@@ -163,10 +169,7 @@ module.exports.prototype = {
}
});
return d.promise;
- } else {
- events.emit('verbose', 'iOS Product Name has not changed (still "' + this.originalName + '")');
- return Q();
- }
+ });
},
// Returns the platform-specific www directory.
@@ -217,6 +220,38 @@ module.exports.prototype = {
self.update_overrides();
util.deleteSvnFolders(self.www_dir());
});
+ },
+
+ update_build_settings:function(config) {
+ var targetDevice = parseTargetDevicePreference(config.getPreference('target-device', 'ios'));
+ var deploymentTarget = config.getPreference('deployment-target', 'ios');
+
+ // no build settings provided, we don't need to parse and update .pbxproj file
+ if (!targetDevice && !deploymentTarget) {
+ return Q();
+ }
+
+ var me = this;
+ var d = Q.defer();
+ var proj = new xcode.project(this.pbxproj);
+ proj.parse(function(err,hash) {
+ if (err) {
+ d.reject(new Error('An error occured during parsing of project.pbxproj. Start weeping. Output: ' + err));
+ return;
+ }
+ var buildConfiguration = proj.pbxXCBuildConfigurationSection();
+ if (targetDevice) {
+ // TODO: replace propReplace with proj.updateBuildProperty after below is release
+ // https://github.com/alunny/node-xcode/pull/33
+ propReplace(buildConfiguration, 'TARGETED_DEVICE_FAMILY', targetDevice);
+ }
+ if (deploymentTarget) {
+ propReplace(buildConfiguration, 'IPHONEOS_DEPLOYMENT_TARGET', deploymentTarget);
+ }
+ fs.writeFileSync(me.pbxproj, proj.writeSync(), 'utf-8');
+ d.resolve();
+ });
+ return d.promise;
}
};
@@ -226,3 +261,25 @@ module.exports.prototype = {
function default_CFBundleVersion(version) {
return version.split('-')[0];
}
+// Converts cordova specific representation of target device to XCode value
+function parseTargetDevicePreference(value) {
+ if (!value) return null;
+ var map = { 'universal': '"1,2"', 'handset': '"1"', 'tablet': '"2"'}
+ if (map[value.toLowerCase()]) {
+ return map[value.toLowerCase()]
+ }
+ events.emit('warn', 'Unknown target-device preference value: "' + value + '".');
+ return null;
+}
+// helper recursive prop search+replace
+function propReplace(obj, prop, value) {
+ for (var p in obj) {
+ if (obj.hasOwnProperty(p)) {
+ if (typeof obj[p] == 'object') {
+ propReplace(obj[p], prop, value);
+ } else if (p == prop) {
+ obj[p] = value;
+ }
+ }
+ }
+}