Skip to content

Commit 4dbb048

Browse files
committed
fix: framework not removed if only referenced from removed target
1 parent fcb7376 commit 4dbb048

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

lib/pbxProject.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,10 +1677,13 @@ pbxProject.prototype.removeTargetsByProductType = function(targetProductType) {
16771677

16781678
pbxProject.prototype.removeTarget = function(target, targetKey) {
16791679
let files = [];
1680+
var pbxBuildFileSection = this.pbxBuildFileSection();
1681+
var fileReferenceSection = this.pbxFileReferenceSection();
16801682

16811683
// iterate all buildPhases and collect all files that should be removed
16821684
// remove the phase from the appropriate section
16831685
var buildPhases = target["buildPhases"];
1686+
16841687
for (let i = 0; i < buildPhases.length; i++) {
16851688
var buildPhase = buildPhases[i];
16861689
var sectionUuid = buildPhase.value;
@@ -1693,7 +1696,26 @@ pbxProject.prototype.removeTarget = function(target, targetKey) {
16931696
files = files.concat(section[sectionUuid].files);
16941697
} else if (buildPhase.comment === buildPhaseNameForIsa("PBXFrameworksBuildPhase")) {
16951698
section = this.hash.project.objects["PBXFrameworksBuildPhase"];
1696-
files = files.concat(section[sectionUuid].files);
1699+
var frameworkFiles = section[sectionUuid].files;
1700+
for (let q = 0; q < frameworkFiles.length; q++) {
1701+
var currentBuildFileUuid = frameworkFiles[q].value;
1702+
var fileRef = pbxBuildFileSection[currentBuildFileUuid].fileRef;
1703+
var stillReferenced = false;
1704+
for (var buildFileUuid in nonComments(pbxBuildFileSection)) {
1705+
if(pbxBuildFileSection[buildFileUuid].fileRef === fileRef && buildFileUuid !== currentBuildFileUuid){
1706+
stillReferenced = true;
1707+
}
1708+
}
1709+
1710+
if(!stillReferenced) {
1711+
var frameworkFileRef = fileReferenceSection[fileRef];
1712+
var fileToRemove = new pbxFile(unquote(frameworkFileRef.path), {basename: frameworkFileRef.name});
1713+
fileToRemove.fileRef = fileRef;
1714+
this.removeFromFrameworksPbxGroup(fileToRemove);
1715+
removeItemAndCommentFromSectionByUuid(fileReferenceSection, fileRef);
1716+
}
1717+
}
1718+
files = files.concat(frameworkFiles);
16971719
}
16981720

16991721
removeItemAndCommentFromSectionByUuid(section, sectionUuid);
@@ -1734,12 +1756,10 @@ pbxProject.prototype.removeTarget = function(target, targetKey) {
17341756
var productUuid = "";
17351757

17361758
var productReferenceUuid = target.productReference;
1737-
var pbxBuildFileSection = this.pbxBuildFileSection();
1738-
var pbxBuildFileSectionNoComments = nonComments(pbxBuildFileSection);
17391759

17401760
// the productReference is the uuid from the PBXFileReference Section, but we need the one in PBXBuildFile section
17411761
// check the fileRef of all records until we find the product
1742-
for (var uuid in pbxBuildFileSectionNoComments) {
1762+
for (var uuid in nonComments(pbxBuildFileSection)) {
17431763
if (this.pbxBuildFileSection()[uuid].fileRef == productReferenceUuid) {
17441764
productUuid = uuid;
17451765
}
@@ -1787,7 +1807,6 @@ pbxProject.prototype.removeTarget = function(target, targetKey) {
17871807

17881808

17891809
//remove the product from the Products PBXGroup
1790-
var fileReferenceSection = this.pbxFileReferenceSection();
17911810
var productReference = fileReferenceSection[productReferenceUuid];
17921811
var productFile = new pbxFile(productReference.path);
17931812
productFile.fileRef = productReferenceUuid;

0 commit comments

Comments
 (0)