Skip to content

Commit 3ff290b

Browse files
committed
Adds the embed option pbxProject.addFramework
This allows us to add and embed a dynamic framework to a project that already contains the Embed Frameworks build phase
1 parent 19879f9 commit 3ff290b

File tree

1 file changed

+53
-4
lines changed

1 file changed

+53
-4
lines changed

lib/pbxProject.js

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,13 @@ pbxProject.prototype.addFramework = function (fpath, opt) {
194194
this.addToFrameworksPbxGroup(file); // PBXGroup
195195
this.addToPbxFrameworksBuildPhase(file); // PBXFrameworksBuildPhase
196196

197-
if(opt && opt.customFramework == true) {
198-
this.addToFrameworkSearchPaths(file);
197+
if (opt) {
198+
if (opt.customFramework == true) {
199+
this.addToFrameworkSearchPaths(file);
200+
}
201+
if (opt.embed == true) {
202+
this.addToPbxEmbedFrameworksBuildPhase(file);
203+
}
199204
}
200205

201206
return file;
@@ -209,8 +214,13 @@ pbxProject.prototype.removeFramework = function (fpath, opt) {
209214
this.removeFromFrameworksPbxGroup(file); // PBXGroup
210215
this.removeFromPbxFrameworksBuildPhase(file); // PBXFrameworksBuildPhase
211216

212-
if(opt && opt.customFramework) {
213-
this.removeFromFrameworkSearchPaths(path.dirname(fpath));
217+
if (opt) {
218+
if (opt.customFramework == true) {
219+
this.removeFromFrameworkSearchPaths(path.dirname(fpath));
220+
}
221+
if (opt.embed == true) {
222+
this.removePbxFromFrameworksBuildPhase(file);
223+
}
214224
}
215225

216226
return file;
@@ -386,6 +396,41 @@ pbxProject.prototype.removeFromPbxFrameworksBuildPhase = function (file) {
386396
}
387397
}
388398

399+
pbxProject.prototype.addToPbxEmbedFrameworksBuildPhase = function (file) {
400+
var embeddedFrameworkAttributes = ['CodeSignOnCopy', 'RemoveHeadersOnCopy'];
401+
402+
var embedFile = new pbxFile(file.path);
403+
embedFile.settings = { ATTRIBUTES: embeddedFrameworkAttributes };
404+
embedFile.uuid = this.generateUuid();
405+
embedFile.fileRef = file.fileRef;
406+
embedFile.group = 'Embed Frameworks';
407+
408+
this.addToPbxBuildFileSection(embedFile);
409+
410+
var embedFrameworks = this.pbxEmbedFrameworksBuildPhaseObj();
411+
embedFrameworks.files.push(pbxBuildPhaseObj(embedFile));
412+
}
413+
414+
pbxProject.prototype.removeFromPbxEmbedFrameworksBuildPhase = function (file) {
415+
var embedFile = new pbxFile(fpath);
416+
embedFile.group = 'Embed Frameworks';
417+
418+
var embedFrameworks = this.pbxEmbedFrameworksBuildPhaseObj();
419+
for (var i in embedFrameworks.files) {
420+
if (embedFrameworks.files[i].comment == longComment(file)) {
421+
var uuid = embedFrameworks.files[i].uuid;
422+
if (uuid in this.pbxBuildFileSection()) {
423+
delete this.pbxBuildFileSection()[uuid];
424+
var commentKey = f("%s_comment", uuid);
425+
delete this.pbxBuildFileSection()[commentKey];
426+
}
427+
428+
sources.files.splice(i, 1);
429+
break;
430+
}
431+
}
432+
}
433+
389434
// helper access functions
390435
pbxProject.prototype.pbxBuildFileSection = function () {
391436
return this.hash.project.objects['PBXBuildFile'];
@@ -428,6 +473,10 @@ pbxProject.prototype.pbxFrameworksBuildPhaseObj = function () {
428473
return this.buildPhaseObject('PBXFrameworksBuildPhase', 'Frameworks');
429474
}
430475

476+
pbxProject.prototype.pbxEmbedFrameworksBuildPhaseObj = function () {
477+
return this.buildPhaseObject('PBXCopyFilesBuildPhase', 'Embed Frameworks');
478+
}
479+
431480
pbxProject.prototype.buildPhaseObject = function (name, group) {
432481
var section = this.hash.project.objects[name],
433482
obj, sectionKey, key;

0 commit comments

Comments
 (0)