Skip to content

Commit cd6f86f

Browse files
NiklasMerztimbru31
andauthored
Add targetName to paramter to getBuildProperty (#109)
* Add targetName to parameter to getBuildProperty * Update lib/pbxProject.js Co-authored-by: Tim Brust <github@timbrust.de>
1 parent 6c019dd commit cd6f86f

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

lib/pbxProject.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2068,11 +2068,34 @@ pbxProject.prototype.removeFile = function (path, group, opt) {
20682068

20692069

20702070

2071-
pbxProject.prototype.getBuildProperty = function(prop, build) {
2071+
pbxProject.prototype.getBuildProperty = function(prop, build, targetName) {
20722072
var target;
2073+
let validConfigs = [];
2074+
2075+
if (targetName) {
2076+
const target = this.pbxTargetByName(targetName);
2077+
const targetBuildConfigs = target && target.buildConfigurationList;
2078+
2079+
const xcConfigList = this.pbxXCConfigurationList();
2080+
2081+
// Collect the UUID's from the configuration of our target
2082+
for (const configName in xcConfigList) {
2083+
if (!COMMENT_KEY.test(configName) && targetBuildConfigs === configName) {
2084+
const buildVariants = xcConfigList[configName].buildConfigurations;
2085+
2086+
for (const item of buildVariants) {
2087+
validConfigs.push(item.value);
2088+
}
2089+
2090+
break;
2091+
}
2092+
}
2093+
}
2094+
20732095
var configs = this.pbxXCBuildConfigurationSection();
20742096
for (var configName in configs) {
20752097
if (!COMMENT_KEY.test(configName)) {
2098+
if (targetName && !validConfigs.includes(configName)) continue;
20762099
var config = configs[configName];
20772100
if ( (build && config.name === build) || (build === undefined) ) {
20782101
if (config.buildSettings[prop] !== undefined) {

test/pbxProject.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,34 @@ exports['updateBuildProperty function'] = {
214214
}
215215
}
216216

217+
exports['getBuildProperty function'] = {
218+
setUp:function(callback) {
219+
callback();
220+
},
221+
tearDown:function(callback) {
222+
fs.writeFileSync(bcpbx, original_pbx, 'utf-8');
223+
callback();
224+
},
225+
'should change all targets in .pbxproj with multiple targets': function (test) {
226+
var myProj = new pbx('test/parser/projects/multitarget.pbxproj');
227+
myProj.parse(function(err, hash) {
228+
myProj.updateBuildProperty('PRODUCT_BUNDLE_IDENTIFIER', 'comcompanytest');
229+
myProj.writeSync();
230+
test.ok(myProj.getBuildProperty('PRODUCT_BUNDLE_IDENTIFIER') === 'comcompanytest');
231+
test.done();
232+
});
233+
},
234+
'should change only one target in .pbxproj with multiple targets': function (test) {
235+
var myProj = new pbx('test/parser/projects/multitarget.pbxproj');
236+
myProj.parse(function(err, hash) {
237+
myProj.updateBuildProperty('PRODUCT_BUNDLE_IDENTIFIER', 'comcompanytest', null, 'MultiTargetTest');
238+
myProj.writeSync();
239+
test.ok(myProj.getBuildProperty('PRODUCT_BUNDLE_IDENTIFIER', undefined, 'MultiTargetTest') === 'comcompanytest');
240+
test.done();
241+
});
242+
}
243+
}
244+
217245
exports['addBuildProperty function'] = {
218246
setUp:function(callback) {
219247
callback();

0 commit comments

Comments
 (0)