Skip to content

Commit e9c8bbc

Browse files
Martin Bektchieve2l3n
authored andcommitted
Fix parser to merge properties of multiple sections with the same name
Xcode handles this correctly and some tools might produce such projects.
1 parent b9dd025 commit e9c8bbc

File tree

4 files changed

+97
-4
lines changed

4 files changed

+97
-4
lines changed

lib/parser/pbxproj.js

Lines changed: 24 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/parser/pbxproj.pegjs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
{
22
function merge(hash, secondHash) {
33
secondHash = secondHash[0]
4-
for(var i in secondHash)
5-
hash[i] = secondHash[i]
4+
for(var i in secondHash) {
5+
hash[i] = merge_obj(hash[i], secondHash[i]);
6+
}
67

78
return hash;
89
}
10+
11+
function merge_obj(obj, secondObj) {
12+
if (!obj)
13+
return secondObj;
14+
15+
for(var i in secondObj)
16+
obj[i] = merge_obj(obj[i], secondObj[i]);
17+
18+
return obj;
19+
}
920
}
1021

1122
/*
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// !$*UTF8*$!
2+
{
3+
archiveVersion = 1;
4+
classes = {
5+
};
6+
objectVersion = 45;
7+
rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
8+
objects = {
9+
/* Begin PBXTargetDependency section */
10+
301BF551109A68C00062928A /* PBXTargetDependency */ = {
11+
isa = PBXTargetDependency;
12+
name = PhoneGapLib;
13+
targetProxy = 301BF550109A68C00062928A /* PBXContainerItemProxy */;
14+
};
15+
/* End PBXTargetDependency section */
16+
17+
/* Begin PBXTargetDependency section */
18+
45FDD1944D304A9F96DF3AC6 /* PBXTargetDependency */ = {
19+
isa = PBXTargetDependency;
20+
name = SecondLib;
21+
targetProxy = 301BF550109A68C00062928A /* PBXContainerItemProxy */;
22+
};
23+
/* End PBXTargetDependency section */
24+
};
25+
}

test/parser/section-split.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
var PEG = require('pegjs'),
2+
fs = require('fs'),
3+
pbx = fs.readFileSync('test/parser/projects/section-split.pbxproj', 'utf-8'),
4+
grammar = fs.readFileSync('lib/parser/pbxproj.pegjs', 'utf-8'),
5+
parser = PEG.buildParser(grammar),
6+
rawProj = parser.parse(pbx),
7+
project = rawProj.project;
8+
9+
exports['should have a PBXTargetDependency section'] = function (test) {
10+
test.ok(project.objects['PBXTargetDependency']);
11+
test.done();
12+
}
13+
14+
exports['should have the right child of PBXTargetDependency section'] = function (test) {
15+
test.ok(project.objects['PBXTargetDependency']['301BF551109A68C00062928A']);
16+
test.done();
17+
}
18+
19+
exports['should have the right properties on the dependency'] = function (test) {
20+
var dependency = project.objects['PBXTargetDependency']['301BF551109A68C00062928A'];
21+
22+
test.equal(dependency.isa, 'PBXTargetDependency')
23+
test.equal(dependency.name, 'PhoneGapLib')
24+
test.equal(dependency.targetProxy, '301BF550109A68C00062928A')
25+
test.equal(dependency['targetProxy_comment'], 'PBXContainerItemProxy')
26+
27+
test.done();
28+
}
29+
30+
exports['should merge two PBXTargetDependency sections'] = function (test) {
31+
test.ok(project.objects['PBXTargetDependency']['301BF551109A68C00062928A']);
32+
test.ok(project.objects['PBXTargetDependency']['45FDD1944D304A9F96DF3AC6']);
33+
test.done();
34+
}
35+

0 commit comments

Comments
 (0)