Skip to content

Commit a84d3e7

Browse files
Dimitar Kerezove2l3n
Dimitar Kerezov
authored andcommitted
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 056f43d commit a84d3e7

File tree

3 files changed

+202
-1
lines changed

3 files changed

+202
-1
lines changed

lib/pbxProject.js

+55
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,61 @@ pbxProject.prototype.addXCConfigurationList = function (configurationObjectsArra
519519
return {uuid: xcConfigurationListUuid, xcConfigurationList: xcConfigurationList};
520520
}
521521

522+
pbxProject.prototype.addTargetDependency = function (target, dependencyTargets) {
523+
if (!target)
524+
return undefined;
525+
526+
var nativeTargets = this.pbxNativeTarget();
527+
528+
if (typeof nativeTargets[target] == "undefined")
529+
throw new Error("Invalid target: " + target);
530+
531+
for (var index = 0; index < dependencyTargets.length; index++) {
532+
var dependencyTarget = dependencyTargets[index];
533+
if (typeof nativeTargets[dependencyTarget] == "undefined")
534+
throw new Error("Invalid target: " + dependencyTarget);
535+
}
536+
537+
var pbxTargetDependency = 'PBXTargetDependency',
538+
pbxContainerItemProxy = 'PBXContainerItemProxy',
539+
pbxTargetDependencySection = this.hash.project.objects[pbxTargetDependency],
540+
pbxContainerItemProxySection = this.hash.project.objects[pbxContainerItemProxy];
541+
542+
for (var index = 0; index < dependencyTargets.length; index++) {
543+
var dependencyTargetUuid = dependencyTargets[index],
544+
dependencyTargetCommentKey = f("%s_comment", dependencyTargetUuid),
545+
targetDependencyUuid = this.generateUuid(),
546+
targetDependencyCommentKey = f("%s_comment", targetDependencyUuid),
547+
itemProxyUuid = this.generateUuid(),
548+
itemProxyCommentKey = f("%s_comment", itemProxyUuid),
549+
itemProxy = {
550+
isa: pbxContainerItemProxy,
551+
containerPortal: this.hash.project['rootObject'],
552+
containerPortal_comment: this.hash.project['rootObject_comment'],
553+
proxyType: 1,
554+
remoteGlobalIDString: dependencyTargetUuid,
555+
remoteInfo: nativeTargets[dependencyTargetUuid].name
556+
},
557+
targetDependency = {
558+
isa: pbxTargetDependency,
559+
target: dependencyTargetUuid,
560+
target_comment: nativeTargets[dependencyTargetCommentKey],
561+
targetProxy: itemProxyUuid,
562+
targetProxy_comment: pbxContainerItemProxy
563+
};
564+
565+
if (pbxContainerItemProxySection && pbxTargetDependencySection) {
566+
pbxContainerItemProxySection[itemProxyUuid] = itemProxy;
567+
pbxContainerItemProxySection[itemProxyCommentKey] = pbxContainerItemProxy;
568+
pbxTargetDependencySection[targetDependencyUuid] = targetDependency;
569+
pbxTargetDependencySection[targetDependencyCommentKey] = pbxTargetDependency;
570+
nativeTargets[target].dependencies.push({value: targetDependencyUuid, comment: pbxTargetDependency})
571+
}
572+
}
573+
574+
return {uuid: target, target: nativeTargets[target]};
575+
}
576+
522577
pbxProject.prototype.addBuildPhase = function (filePathsArray, isa, comment) {
523578
var section = this.hash.project.objects[isa],
524579
fileReferenceSection = this.pbxFileReferenceSection(),

test/addTargetDependency.js

+146
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)