Skip to content

Commit 57f2a08

Browse files
Adjusting framework settings to only be applied when embedding to avoid parsing crashes on Xcode 7.3
1 parent 8c6fa3a commit 57f2a08

File tree

4 files changed

+59
-26
lines changed

4 files changed

+59
-26
lines changed

lib/pbxFile.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var FILETYPE_BY_EXTENSION = {
3434
'archive.ar': 'Frameworks',
3535
'compiled.mach-o.dylib': 'Frameworks',
3636
'wrapper.framework': 'Frameworks',
37+
'embedded.framework': 'Embed Frameworks',
3738
'sourcecode.c.h': 'Resources',
3839
'sourcecode.c.objc': 'Sources',
3940
'sourcecode.swift': 'Sources'
@@ -93,7 +94,7 @@ function defaultEncoding(fileRef) {
9394
}
9495
}
9596

96-
function detectGroup(fileRef) {
97+
function detectGroup(fileRef, opt) {
9798
var extension = path.extname(fileRef.basename).substring(1),
9899
filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
99100
groupName = GROUP_BY_FILETYPE[unquoted(filetype)];
@@ -102,6 +103,10 @@ function detectGroup(fileRef) {
102103
return 'Sources';
103104
}
104105

106+
if (opt.customFramework && opt.embed) {
107+
return GROUP_BY_FILETYPE['embedded.framework'];
108+
}
109+
105110
if (!groupName) {
106111
return DEFAULT_GROUP;
107112
}
@@ -161,7 +166,7 @@ function pbxFile(filepath, opt) {
161166

162167
this.basename = path.basename(filepath);
163168
this.lastKnownFileType = opt.lastKnownFileType || detectType(filepath);
164-
this.group = detectGroup(self);
169+
this.group = detectGroup(self, opt);
165170

166171
// for custom frameworks
167172
if (opt.customFramework == true) {
@@ -195,7 +200,7 @@ function pbxFile(filepath, opt) {
195200
this.settings.COMPILER_FLAGS = util.format('"%s"', opt.compilerFlags);
196201
}
197202

198-
if (opt.sign) {
203+
if (opt.embed && opt.sign) {
199204
if (!this.settings)
200205
this.settings = {};
201206
if (!this.settings.ATTRIBUTES)

lib/pbxProject.js

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,13 @@ pbxProject.prototype.removeResourceFile = function(path, opt) {
261261
}
262262

263263
pbxProject.prototype.addFramework = function(fpath, opt) {
264+
var customFramework = opt && opt.customFramework == true;
265+
var link = !opt || (opt.link == undefined || opt.link); //defaults to true if not specified
266+
var embed = opt && opt.embed; //defaults to false if not specified
267+
268+
if (opt) {
269+
delete opt.embed;
270+
}
264271

265272
var file = new pbxFile(fpath, opt);
266273

@@ -270,10 +277,6 @@ pbxProject.prototype.addFramework = function(fpath, opt) {
270277

271278
if (this.hasFile(file.path)) return false;
272279

273-
var customFramework = opt && opt.customFramework == true;
274-
var link = !opt || (opt.link == undefined || opt.link); //defaults to true if not specified
275-
var embed = opt && opt.embed; //defaults to false if not specified
276-
277280
this.addToPbxBuildFileSection(file); // PBXBuildFile
278281
this.addToPbxFileReferenceSection(file); // PBXFileReference
279282
this.addToFrameworksPbxGroup(file); // PBXGroup
@@ -286,27 +289,51 @@ pbxProject.prototype.addFramework = function(fpath, opt) {
286289
this.addToFrameworkSearchPaths(file);
287290

288291
if (embed) {
289-
this.addToPbxEmbedFrameworksBuildPhase(file); // PBXCopyFilesBuildPhase
292+
opt.embed = embed;
293+
var embeddedFile = new pbxFile(fpath, opt);
294+
295+
embeddedFile.uuid = this.generateUuid();
296+
embeddedFile.fileRef = file.fileRef;
297+
298+
//keeping a separate PBXBuildFile entry for Embed Frameworks
299+
this.addToPbxBuildFileSection(embeddedFile); // PBXBuildFile
300+
301+
this.addToPbxEmbedFrameworksBuildPhase(embeddedFile); // PBXCopyFilesBuildPhase
302+
303+
return embeddedFile;
290304
}
291305
}
292306

293307
return file;
294308
}
295309

296310
pbxProject.prototype.removeFramework = function(fpath, opt) {
311+
var embed = opt && opt.embed;
312+
313+
if (opt) {
314+
delete opt.embed;
315+
}
316+
297317
var file = new pbxFile(fpath, opt);
298318
file.target = opt ? opt.target : undefined;
299319

300320
this.removeFromPbxBuildFileSection(file); // PBXBuildFile
301321
this.removeFromPbxFileReferenceSection(file); // PBXFileReference
302322
this.removeFromFrameworksPbxGroup(file); // PBXGroup
303323
this.removeFromPbxFrameworksBuildPhase(file); // PBXFrameworksBuildPhase
304-
this.removeFromPbxEmbedFrameworksBuildPhase(file); // PBXCopyFilesBuildPhase
305324

306325
if (opt && opt.customFramework) {
307326
this.removeFromFrameworkSearchPaths(path.dirname(fpath));
308327
}
309328

329+
opt.embed = true;
330+
var embeddedFile = new pbxFile(fpath, opt);
331+
332+
embeddedFile.fileRef = file.fileRef;
333+
334+
this.removeFromPbxBuildFileSection(embeddedFile); // PBXBuildFile
335+
this.removeFromPbxEmbedFrameworksBuildPhase(embeddedFile); // PBXCopyFilesBuildPhase
336+
310337
return file;
311338
}
312339

@@ -600,12 +627,13 @@ pbxProject.prototype.addToPbxEmbedFrameworksBuildPhase = function (file) {
600627
pbxProject.prototype.removeFromPbxEmbedFrameworksBuildPhase = function (file) {
601628
var sources = this.pbxEmbedFrameworksBuildPhaseObj(file.target);
602629
if (sources) {
630+
var files = [];
603631
for (i in sources.files) {
604-
if (sources.files[i].comment == longComment(file)) {
605-
sources.files.splice(i, 1);
606-
break;
632+
if (sources.files[i].comment != longComment(file)) {
633+
files.push(sources.files[i]);
607634
}
608635
}
636+
sources.files = files;
609637
}
610638
}
611639

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "Andrew Lunny <alunny@gmail.com>",
33
"name": "xcode",
44
"description": "parser for xcodeproj/project.pbxproj files",
5-
"version": "0.8.3",
5+
"version": "0.8.6",
66
"main": "index.js",
77
"repository": {
88
"url": "https://github.com/alunny/node-xcode.git"

test/addFramework.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ function frameworkSearchPaths(proj) {
4545
exports.addFramework = {
4646
'should return a pbxFile': function (test) {
4747
var newFile = proj.addFramework('libsqlite3.dylib');
48-
console.log(newFile);
4948

5049
test.equal(newFile.constructor, pbxFile);
5150
test.done()
@@ -131,18 +130,6 @@ exports.addFramework = {
131130

132131
test.done();
133132
},
134-
'should add the PBXBuildFile object correctly /w signable frameworks': function (test) {
135-
var newFile = proj.addFramework('libsqlite3.dylib', { sign: true }),
136-
buildFileSection = proj.pbxBuildFileSection(),
137-
buildFileEntry = buildFileSection[newFile.uuid];
138-
139-
test.equal(buildFileEntry.isa, 'PBXBuildFile');
140-
test.equal(buildFileEntry.fileRef, newFile.fileRef);
141-
test.equal(buildFileEntry.fileRef_comment, 'libsqlite3.dylib');
142-
test.deepEqual(buildFileEntry.settings, { ATTRIBUTES: [ 'CodeSignOnCopy' ] });
143-
144-
test.done();
145-
},
146133
'should add to the Frameworks PBXGroup': function (test) {
147134
var newLength = proj.pbxGroupByName('Frameworks').children.length + 1,
148135
newFile = proj.addFramework('libsqlite3.dylib'),
@@ -229,4 +216,17 @@ exports.addFramework = {
229216
test.equal(frameworks.files.length, 0);
230217
test.done();
231218
},
219+
'should add the PBXBuildFile object correctly /w signable frameworks': function (test) {
220+
var newFile = proj.addFramework('/path/to/SomeSignable.framework', { customFramework: true, embed: true, sign: true }),
221+
buildFileSection = proj.pbxBuildFileSection(),
222+
buildFileEntry = buildFileSection[newFile.uuid];
223+
224+
test.equal(newFile.group, 'Embed Frameworks');
225+
test.equal(buildFileEntry.isa, 'PBXBuildFile');
226+
test.equal(buildFileEntry.fileRef, newFile.fileRef);
227+
test.equal(buildFileEntry.fileRef_comment, 'SomeSignable.framework');
228+
test.deepEqual(buildFileEntry.settings, { ATTRIBUTES: [ 'CodeSignOnCopy' ] });
229+
230+
test.done();
231+
},
232232
}

0 commit comments

Comments
 (0)