Skip to content

Commit 4cffcd3

Browse files
author
Dimitar Kerezov
committed
Introduce a way to add XCConfigurationLists
By given configuration objects, default configuration name and a comment add all configurations to PBXXCBuildConfigurationSection and add an XCConfigurationList
1 parent 3085e40 commit 4cffcd3

File tree

2 files changed

+145
-0
lines changed

2 files changed

+145
-0
lines changed

lib/pbxProject.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,36 @@ pbxProject.prototype.removeFromPbxFrameworksBuildPhase = function (file) {
398398
}
399399
}
400400

401+
pbxProject.prototype.addXCConfigurationList = function (configurationObjectsArray, defaultConfigurationName, comment) {
402+
var pbxBuildConfigurationSection = this.pbxXCBuildConfigurationSection(),
403+
pbxXCConfigurationListSection = this.pbxXCConfigurationList(),
404+
xcConfigurationListUuid = this.generateUuid(),
405+
commentKey = f("%s_comment", xcConfigurationListUuid),
406+
xcConfigurationList = {
407+
isa: 'XCConfigurationList',
408+
buildConfigurations: [],
409+
defaultConfigurationIsVisible: 0,
410+
defaultConfigurationName: defaultConfigurationName
411+
};
412+
413+
for (var index = 0; index < configurationObjectsArray.length; index++) {
414+
var configuration = configurationObjectsArray[index],
415+
configurationUuid = this.generateUuid(),
416+
configurationCommentKey = f("%s_comment", configurationUuid);
417+
418+
pbxBuildConfigurationSection[configurationUuid] = configuration;
419+
pbxBuildConfigurationSection[configurationCommentKey] = configuration.name;
420+
xcConfigurationList.buildConfigurations.push({value: configurationUuid, comment: configuration.name});
421+
}
422+
423+
if (pbxXCConfigurationListSection) {
424+
pbxXCConfigurationListSection[xcConfigurationListUuid] = xcConfigurationList;
425+
pbxXCConfigurationListSection[commentKey] = comment;
426+
}
427+
428+
return {uuid: xcConfigurationListUuid, xcConfigurationList: xcConfigurationList};
429+
}
430+
401431
pbxProject.prototype.addBuildPhase = function (filePathsArray, isa, comment) {
402432
var section = this.hash.project.objects[isa],
403433
buildPhaseUuid = this.generateUuid(),

test/addXCConfigurationList.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
var fullProject = require('./fixtures/full-project')
2+
fullProjectStr = JSON.stringify(fullProject),
3+
pbx = require('../lib/pbxProject'),
4+
proj = new pbx('.'),
5+
debugConfiguration = {
6+
isa: 'XCBuildConfiguration',
7+
buildSettings: {
8+
GCC_PREPROCESSOR_DEFINITIONS: [
9+
'"DEBUG=1"',
10+
'"$(inherited)"',
11+
],
12+
INFOPLIST_FILE: "Info.Plist",
13+
LD_RUNPATH_SEARCH_PATHS: '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"',
14+
PRODUCT_NAME: '"${TARGET_NAME}"',
15+
SKIP_INSTALL: 'YES'
16+
},
17+
name: 'Debug'
18+
},
19+
releaseConfiguration = {
20+
isa: 'XCBuildConfiguration',
21+
buildSettings: {
22+
INFOPLIST_FILE: "Info.Plist",
23+
LD_RUNPATH_SEARCH_PATHS: '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"',
24+
PRODUCT_NAME: '"${TARGET_NAME}"',
25+
SKIP_INSTALL: 'YES'
26+
},
27+
name: 'Release'
28+
};
29+
30+
function cleanHash() {
31+
return JSON.parse(fullProjectStr);
32+
}
33+
34+
exports.setUp = function (callback) {
35+
proj.hash = cleanHash();
36+
callback();
37+
}
38+
39+
exports.addXCConfigurationList = {
40+
'should return an XCConfigurationList': function (test) {
41+
var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(),
42+
xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment');
43+
44+
test.ok(typeof xcConfigurationList === 'object');
45+
test.done();
46+
},
47+
'should set a uuid on the XCConfigurationList': function (test) {
48+
var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(),
49+
xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment');
50+
51+
test.ok(xcConfigurationList.uuid);
52+
test.done();
53+
},
54+
'should add configurations to pbxBuildConfigurationSection': function (test) {
55+
var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(),
56+
pbxBuildConfigurationSection = myProj.pbxXCBuildConfigurationSection(),
57+
xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'),
58+
xcConfigurationListConfigurations = xcConfigurationList.xcConfigurationList.buildConfigurations;
59+
60+
for (var index = 0; index < xcConfigurationListConfigurations.length; index++) {
61+
var configuration = xcConfigurationListConfigurations[index];
62+
test.ok(pbxBuildConfigurationSection[configuration.value]);
63+
}
64+
65+
test.done();
66+
},
67+
'should add XCConfigurationList to pbxXCConfigurationListSection': function (test) {
68+
var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(),
69+
pbxXCConfigurationListSection = myProj.pbxXCConfigurationList();
70+
xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment');
71+
72+
test.ok(pbxXCConfigurationListSection[xcConfigurationList.uuid]);
73+
test.done();
74+
},
75+
'should add XCConfigurationList object correctly': function (test) {
76+
var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(),
77+
pbxXCConfigurationListSection = myProj.pbxXCConfigurationList();
78+
xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'),
79+
xcConfigurationListInPbx = pbxXCConfigurationListSection[xcConfigurationList.uuid];
80+
81+
test.deepEqual(xcConfigurationListInPbx, xcConfigurationList.xcConfigurationList);
82+
test.done();
83+
},
84+
'should add correct configurations to XCConfigurationList and to pbxBuildConfigurationSection': function (test) {
85+
var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(),
86+
pbxXCConfigurationListSection = myProj.pbxXCConfigurationList();
87+
pbxBuildConfigurationSection = myProj.pbxXCBuildConfigurationSection(),
88+
xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'),
89+
xcConfigurationListConfigurations = xcConfigurationList.xcConfigurationList.buildConfigurations,
90+
expectedConfigurations = [],
91+
xcConfigurationListInPbx = pbxXCConfigurationListSection[xcConfigurationList.uuid];
92+
93+
for (var index = 0; index < xcConfigurationListConfigurations.length; index++) {
94+
var configuration = xcConfigurationListConfigurations[index];
95+
expectedConfigurations.push(pbxBuildConfigurationSection[configuration.value]);
96+
}
97+
98+
test.deepEqual(expectedConfigurations, [debugConfiguration, releaseConfiguration]);
99+
test.deepEqual(xcConfigurationListInPbx.buildConfigurations, xcConfigurationListConfigurations);
100+
test.done();
101+
},
102+
'should set comments for pbxBuildConfigurations': function (test) {
103+
var myProj = new pbx('test/parser/projects/full.pbxproj').parseSync(),
104+
pbxBuildConfigurationSection = myProj.pbxXCBuildConfigurationSection(),
105+
xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'),
106+
xcConfigurationListConfigurations = xcConfigurationList.xcConfigurationList.buildConfigurations;
107+
108+
for (var index = 0; index < xcConfigurationListConfigurations.length; index++) {
109+
var configuration = xcConfigurationListConfigurations[index];
110+
test.ok(pbxBuildConfigurationSection[configuration.value + '_comment']);
111+
}
112+
113+
test.done();
114+
}
115+
}

0 commit comments

Comments
 (0)