Skip to content

Commit b40596e

Browse files
committed
[writer] handle inline objects
used for PBXBuildFirle and PBXFileReference objects
1 parent af22109 commit b40596e

File tree

3 files changed

+102
-7
lines changed

3 files changed

+102
-7
lines changed

lib/pbxWriter.js

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,66 @@ pbxWriter.prototype.writeSection = function (section) {
226226
cmt = comment(key, section);
227227
obj = section[key]
228228

229-
if (cmt) {
230-
this.write("%s /* %s */ = {\n", key, cmt);
229+
if (obj.isa == 'PBXBuildFile' || obj.isa == 'PBXFileReference') {
230+
this.writeInlineObject(key, cmt, obj);
231231
} else {
232-
this.write("%s = {\n", key);
232+
if (cmt) {
233+
this.write("%s /* %s */ = {\n", key, cmt);
234+
} else {
235+
this.write("%s = {\n", key);
236+
}
237+
238+
this.indentLevel++
239+
240+
this.writeObject(obj)
241+
242+
this.indentLevel--
243+
this.write("};\n");
233244
}
245+
}
246+
}
234247

235-
this.indentLevel++
248+
pbxWriter.prototype.writeInlineObject = function (n, d, r) {
249+
var output = [];
236250

237-
this.writeObject(obj)
251+
var inlineObjectHelper = function (name, desc, ref) {
252+
var key, cmt, obj;
253+
254+
if (desc) {
255+
output.push(f("%s /* %s */ = {", name, desc));
256+
} else {
257+
output.push(f("%s = {", name));
258+
}
238259

239-
this.indentLevel--
240-
this.write("};\n");
260+
for (key in ref) {
261+
if (COMMENT_KEY.test(key)) continue;
262+
263+
cmt = comment(key, ref);
264+
obj = ref[key];
265+
266+
if (isArray(obj)) {
267+
output.push(f("%s = (", key));
268+
269+
for (var i=0; i < obj.length; i++) {
270+
output.push(f("%s, ", obj[i]))
271+
}
272+
273+
output.push("); ");
274+
} else if (isObject(obj)) {
275+
inlineObjectHelper(key, cmt, obj)
276+
} else if (cmt) {
277+
output.push(f("%s = %s /* %s */; ", key, obj, cmt))
278+
} else {
279+
output.push(f("%s = %s; ", key, obj))
280+
}
281+
}
282+
283+
output.push("}; ");
241284
}
285+
286+
inlineObjectHelper(n, d, r);
287+
288+
this.write("%s\n", output.join('').trim());
242289
}
243290

244291
module.exports = pbxWriter;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// !$*UTF8*$!
2+
{
3+
archiveVersion = 1;
4+
classes = {
5+
};
6+
objectVersion = 45;
7+
objects = {
8+
/* Begin PBXBuildFile section */
9+
1D3623260D0F684500981E51 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D3623250D0F684500981E51 /* AppDelegate.m */; };
10+
1D60589B0D05DD56006BFB54 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; };
11+
1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
12+
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
13+
1F766FE113BBADB100FB74C0 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 1F766FDC13BBADB100FB74C0 /* Localizable.strings */; };
14+
1F766FE213BBADB100FB74C0 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 1F766FDF13BBADB100FB74C0 /* Localizable.strings */; };
15+
288765FD0DF74451002DB57D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 288765FC0DF74451002DB57D /* CoreGraphics.framework */; };
16+
301BF552109A68D80062928A /* libPhoneGap.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 301BF535109A57CC0062928A /* libPhoneGap.a */; };
17+
301BF570109A69640062928A /* www in Resources */ = {isa = PBXBuildFile; fileRef = 301BF56E109A69640062928A /* www */; };
18+
301BF5B5109A6A2B0062928A /* AddressBook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 301BF5B4109A6A2B0062928A /* AddressBook.framework */; };
19+
301BF5B7109A6A2B0062928A /* AddressBookUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 301BF5B6109A6A2B0062928A /* AddressBookUI.framework */; };
20+
301BF5B9109A6A2B0062928A /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 301BF5B8109A6A2B0062928A /* AudioToolbox.framework */; };
21+
301BF5BB109A6A2B0062928A /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 301BF5BA109A6A2B0062928A /* AVFoundation.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
22+
301BF5BD109A6A2B0062928A /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 301BF5BC109A6A2B0062928A /* CFNetwork.framework */; };
23+
301BF5BF109A6A2B0062928A /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 301BF5BE109A6A2B0062928A /* CoreLocation.framework */; };
24+
301BF5C1109A6A2B0062928A /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 301BF5C0109A6A2B0062928A /* MediaPlayer.framework */; };
25+
301BF5C3109A6A2B0062928A /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 301BF5C2109A6A2B0062928A /* QuartzCore.framework */; };
26+
301BF5C5109A6A2B0062928A /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 301BF5C4109A6A2B0062928A /* SystemConfiguration.framework */; };
27+
3053AC6F109B7857006FCFE7 /* VERSION in Resources */ = {isa = PBXBuildFile; fileRef = 3053AC6E109B7857006FCFE7 /* VERSION */; };
28+
305D5FD1115AB8F900A74A75 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 305D5FD0115AB8F900A74A75 /* MobileCoreServices.framework */; };
29+
3072F99713A8081B00425683 /* Capture.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 3072F99613A8081B00425683 /* Capture.bundle */; };
30+
307D28A2123043360040C0FA /* PhoneGapBuildSettings.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 307D28A1123043350040C0FA /* PhoneGapBuildSettings.xcconfig */; };
31+
308D05371370CCF300D202BF /* icon-72.png in Resources */ = {isa = PBXBuildFile; fileRef = 308D052E1370CCF300D202BF /* icon-72.png */; };
32+
308D05381370CCF300D202BF /* icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 308D052F1370CCF300D202BF /* icon.png */; };
33+
308D05391370CCF300D202BF /* icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 308D05301370CCF300D202BF /* icon@2x.png */; };
34+
308D053C1370CCF300D202BF /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 308D05341370CCF300D202BF /* Default.png */; };
35+
308D053D1370CCF300D202BF /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 308D05351370CCF300D202BF /* Default@2x.png */; };
36+
30E1352710E2C1420031B30D /* PhoneGap.plist in Resources */ = {isa = PBXBuildFile; fileRef = 30E1352610E2C1420031B30D /* PhoneGap.plist */; };
37+
30E5649213A7FCAF007403D8 /* CoreMedia.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 30E5649113A7FCAF007403D8 /* CoreMedia.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
38+
/* End PBXBuildFile section */
39+
};
40+
rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
41+
}

test/pbxWriter.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ function testContentsInDepth(filename, test) {
3232

3333
test.equal(writtenLines.length, contentLines.length);
3434

35+
for (var i=0; i<writtenLines.length; i++) {
36+
test.equal(writtenLines[i], contentLines[i])
37+
}
38+
3539
test.done();
3640
});
3741
}
@@ -57,5 +61,8 @@ exports.writeSync = {
5761
},
5862
'should write out the "nested-object" test': function (test) {
5963
testProjectContents('test/parser/projects/nested-object.pbxproj', test);
64+
},
65+
'should write out the "build-files" test': function (test) {
66+
testProjectContents('test/parser/projects/build-files.pbxproj', test);
6067
}
6168
}

0 commit comments

Comments
 (0)