Skip to content

Commit 13988b8

Browse files
author
Dimitar Kerezov
committed
Introduce a way to add PBXTargetDependencies to a target
Includes creation of a PBXContainerItemProxy for each PBXTargetDependency and including the PBXTargetDependencies to the given target
1 parent 7c617e4 commit 13988b8

File tree

3 files changed

+202
-1
lines changed

3 files changed

+202
-1
lines changed

lib/pbxProject.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,61 @@ pbxProject.prototype.addXCConfigurationList = function (configurationObjectsArra
479479
return {uuid: xcConfigurationListUuid, xcConfigurationList: xcConfigurationList};
480480
}
481481

482+
pbxProject.prototype.addTargetDependency = function (target, dependencyTargets) {
483+
if (!target)
484+
return undefined;
485+
486+
var nativeTargets = this.pbxNativeTarget();
487+
488+
if (typeof nativeTargets[target] == "undefined")
489+
throw new Error("Invalid target: " + target);
490+
491+
for (var index = 0; index < dependencyTargets.length; index++) {
492+
var dependencyTarget = dependencyTargets[index];
493+
if (typeof nativeTargets[dependencyTarget] == "undefined")
494+
throw new Error("Invalid target: " + dependencyTarget);
495+
}
496+
497+
var pbxTargetDependency = 'PBXTargetDependency',
498+
pbxContainerItemProxy = 'PBXContainerItemProxy',
499+
pbxTargetDependencySection = this.hash.project.objects[pbxTargetDependency],
500+
pbxContainerItemProxySection = this.hash.project.objects[pbxContainerItemProxy];
501+
502+
for (var index = 0; index < dependencyTargets.length; index++) {
503+
var dependencyTargetUuid = dependencyTargets[index],
504+
dependencyTargetCommentKey = f("%s_comment", dependencyTargetUuid),
505+
targetDependencyUuid = this.generateUuid(),
506+
targetDependencyCommentKey = f("%s_comment", targetDependencyUuid),
507+
itemProxyUuid = this.generateUuid(),
508+
itemProxyCommentKey = f("%s_comment", itemProxyUuid),
509+
itemProxy = {
510+
isa: pbxContainerItemProxy,
511+
containerPortal: this.hash.project['rootObject'],
512+
containerPortal_comment: this.hash.project['rootObject_comment'],
513+
proxyType: 1,
514+
remoteGlobalIDString: dependencyTargetUuid,
515+
remoteInfo: nativeTargets[dependencyTargetUuid].name
516+
},
517+
targetDependency = {
518+
isa: pbxTargetDependency,
519+
target: dependencyTargetUuid,
520+
target_comment: nativeTargets[dependencyTargetCommentKey],
521+
targetProxy: itemProxyUuid,
522+
targetProxy_comment: pbxContainerItemProxy
523+
};
524+
525+
if (pbxContainerItemProxySection && pbxTargetDependencySection) {
526+
pbxContainerItemProxySection[itemProxyUuid] = itemProxy;
527+
pbxContainerItemProxySection[itemProxyCommentKey] = pbxContainerItemProxy;
528+
pbxTargetDependencySection[targetDependencyUuid] = targetDependency;
529+
pbxTargetDependencySection[targetDependencyCommentKey] = pbxTargetDependency;
530+
nativeTargets[target].dependencies.push({value: targetDependencyUuid, comment: pbxTargetDependency})
531+
}
532+
}
533+
534+
return {uuid: target, target: nativeTargets[target]};
535+
}
536+
482537
pbxProject.prototype.addBuildPhase = function (filePathsArray, isa, comment) {
483538
var section = this.hash.project.objects[isa],
484539
fileReferenceSection = this.pbxFileReferenceSection(),

test/addTargetDependency.js

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
var fullProject = require('./fixtures/full-project')
2+
fullProjectStr = JSON.stringify(fullProject),
3+
pbx = require('../lib/pbxProject'),
4+
proj = new pbx('.');
5+
6+
function cleanHash() {
7+
return JSON.parse(fullProjectStr);
8+
}
9+
10+
exports.setUp = function (callback) {
11+
proj.hash = cleanHash();
12+
callback();
13+
}
14+
15+
exports.addTargetDependency = {
16+
'should return undefined when no target specified': function (test) {
17+
var buildPhase = proj.addTargetDependency();
18+
19+
test.ok(typeof buildPhase === 'undefined');
20+
test.done()
21+
},
22+
'should throw when target not found in nativeTargetsSection': function (test) {
23+
test.throws(function() {
24+
proj.addTargetDependency('invalidTarget');
25+
});
26+
test.done()
27+
},
28+
'should throw when any dependency target not found in nativeTargetsSection': function (test) {
29+
test.throws(function() {
30+
proj.addTargetDependency('1D6058900D05DD3D006BFB54', ['invalidTarget']);
31+
});
32+
test.done()
33+
},
34+
'should return the pbxTarget': function (test) {
35+
var target = proj.addTargetDependency('1D6058900D05DD3D006BFB54', ['1D6058900D05DD3D006BFB54']);
36+
37+
test.ok(typeof target == 'object');
38+
test.ok(target.uuid);
39+
test.ok(target.target);
40+
test.done();
41+
},
42+
'should add targetDependencies to target': function (test) {
43+
var targetInPbxProj = proj.pbxNativeTarget()['1D6058900D05DD3D006BFB55'];
44+
test.deepEqual(targetInPbxProj.dependencies, []);
45+
46+
var target = proj.addTargetDependency('1D6058900D05DD3D006BFB55', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target;
47+
test.deepEqual(targetInPbxProj.dependencies, target.dependencies)
48+
test.done()
49+
},
50+
'should create a PBXTargetDependency for each dependency target': function (test) {
51+
var pbxTargetDependencySection = proj.hash.project.objects['PBXTargetDependency'],
52+
target = proj.addTargetDependency('1D6058900D05DD3D006BFB54', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target;
53+
54+
for (var index = 0; index < target.dependencies.length; index++) {
55+
var dependency = target.dependencies[index].value;
56+
test.ok(pbxTargetDependencySection[dependency]);
57+
}
58+
59+
test.done()
60+
},
61+
'should set right comment for each dependency target': function (test) {
62+
var pbxTargetDependencySection = proj.hash.project.objects['PBXTargetDependency'],
63+
target = proj.addTargetDependency('1D6058900D05DD3D006BFB54', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target;
64+
65+
for (var index = 0; index < target.dependencies.length; index++) {
66+
var dependencyCommentKey = target.dependencies[index].value + '_comment';
67+
test.equal(pbxTargetDependencySection[dependencyCommentKey], 'PBXTargetDependency');
68+
}
69+
70+
test.done()
71+
},
72+
'should create a PBXContainerItemProxy for each PBXTargetDependency': function (test) {
73+
var pbxTargetDependencySection = proj.hash.project.objects['PBXTargetDependency'],
74+
pbxContainerItemProxySection = proj.hash.project.objects['PBXContainerItemProxy'],
75+
target = proj.addTargetDependency('1D6058900D05DD3D006BFB54', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target;
76+
77+
for (var index = 0; index < target.dependencies.length; index++) {
78+
var dependency = target.dependencies[index].value,
79+
targetProxy = pbxTargetDependencySection[dependency]['targetProxy'];
80+
81+
test.ok(pbxContainerItemProxySection[targetProxy]);
82+
}
83+
84+
test.done()
85+
},
86+
'should set each PBXContainerItemProxy`s remoteGlobalIDString correctly': function (test) {
87+
var pbxTargetDependencySection = proj.hash.project.objects['PBXTargetDependency'],
88+
pbxContainerItemProxySection = proj.hash.project.objects['PBXContainerItemProxy'],
89+
target = proj.addTargetDependency('1D6058900D05DD3D006BFB55', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target,
90+
remoteGlobalIDStrings = [];
91+
92+
for (var index = 0; index < target.dependencies.length; index++) {
93+
var dependency = target.dependencies[index].value,
94+
targetProxy = pbxTargetDependencySection[dependency]['targetProxy'];
95+
96+
remoteGlobalIDStrings.push(pbxContainerItemProxySection[targetProxy]['remoteGlobalIDString']);
97+
}
98+
99+
test.deepEqual(remoteGlobalIDStrings, ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']);
100+
test.done()
101+
},
102+
'should set each PBXContainerItemProxy`s remoteInfo correctly': function (test) {
103+
var pbxTargetDependencySection = proj.hash.project.objects['PBXTargetDependency'],
104+
pbxContainerItemProxySection = proj.hash.project.objects['PBXContainerItemProxy'],
105+
target = proj.addTargetDependency('1D6058900D05DD3D006BFB55', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target,
106+
remoteInfoArray = [];
107+
108+
for (var index = 0; index < target.dependencies.length; index++) {
109+
var dependency = target.dependencies[index].value,
110+
targetProxy = pbxTargetDependencySection[dependency]['targetProxy'];
111+
112+
remoteInfoArray.push(pbxContainerItemProxySection[targetProxy]['remoteInfo']);
113+
}
114+
115+
test.deepEqual(remoteInfoArray, ['"KitchenSinktablet"', '"TestApp"']);
116+
test.done()
117+
},
118+
'should set each PBXContainerItemProxy`s containerPortal correctly': function (test) {
119+
var pbxTargetDependencySection = proj.hash.project.objects['PBXTargetDependency'],
120+
pbxContainerItemProxySection = proj.hash.project.objects['PBXContainerItemProxy'],
121+
target = proj.addTargetDependency('1D6058900D05DD3D006BFB55', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target;
122+
123+
for (var index = 0; index < target.dependencies.length; index++) {
124+
var dependency = target.dependencies[index].value,
125+
targetProxy = pbxTargetDependencySection[dependency]['targetProxy'];
126+
127+
test.equal(pbxContainerItemProxySection[targetProxy]['containerPortal'], proj.hash.project['rootObject']);
128+
}
129+
130+
test.done()
131+
},
132+
'should set each PBXContainerItemProxy`s proxyType correctly': function (test) {
133+
var pbxTargetDependencySection = proj.hash.project.objects['PBXTargetDependency'],
134+
pbxContainerItemProxySection = proj.hash.project.objects['PBXContainerItemProxy'],
135+
target = proj.addTargetDependency('1D6058900D05DD3D006BFB55', ['1D6058900D05DD3D006BFB54', '1D6058900D05DD3D006BFB55']).target;
136+
137+
for (var index = 0; index < target.dependencies.length; index++) {
138+
var dependency = target.dependencies[index].value,
139+
targetProxy = pbxTargetDependencySection[dependency]['targetProxy'];
140+
141+
test.equal(pbxContainerItemProxySection[targetProxy]['proxyType'], 1);
142+
}
143+
144+
test.done()
145+
}
146+
}

0 commit comments

Comments
 (0)