Skip to content

Commit a7b43eb

Browse files
committed
fix(ios): only remove the embed entries the SPM service wrote
1 parent 8bbb03f commit a7b43eb

2 files changed

Lines changed: 61 additions & 4 deletions

File tree

‎lib/services/ios/spm-pbxproj-service.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,12 @@ export class SPMPbxprojService implements ISPMPbxprojService {
319319
});
320320

321321
if (!embedLibs.has(lib)) {
322-
this.removeEmbedEntries(project, target, spmProductDependencyUUID);
322+
this.removeEmbedEntries(
323+
project,
324+
target,
325+
spmProductDependencyUUID,
326+
`${lib} in Embed Frameworks`,
327+
);
323328
continue;
324329
}
325330

@@ -360,19 +365,22 @@ export class SPMPbxprojService implements ISPMPbxprojService {
360365
}
361366

362367
/**
363-
* Drops a product from this target's Embed Frameworks phases, and its
364-
* build file once no other copy phase lists it.
368+
* Drops the embed entry this service wrote for a product from this
369+
* target's Embed Frameworks phases, and its build file once no other copy
370+
* phase lists it. Copy entries written by anyone else are left alone.
365371
*/
366372
private removeEmbedEntries(
367373
project: any,
368374
target: any,
369375
productRef: string,
376+
embedComment: string,
370377
): void {
371378
const buildFiles = project.hash.project.objects["PBXBuildFile"] ?? {};
372379
const copyPhases =
373380
project.hash.project.objects["PBXCopyFilesBuildPhase"] ?? {};
374381
const isProductFile = (file: any) =>
375-
buildFiles[file.value]?.productRef === productRef;
382+
buildFiles[file.value]?.productRef === productRef &&
383+
buildFiles[`${file.value}_comment`] === embedComment;
376384

377385
const removed = new Set<string>();
378386
for (const phase of target.buildPhases ?? []) {

‎test/services/ios/spm-pbxproj-service.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,55 @@ describe("SPMPbxprojService", () => {
601601
assert.lengthOf(embedPhaseFileUuids(parsePbxproj(projectRoot)), 0);
602602
});
603603

604+
it("leaves copy entries it did not write for the same product", () => {
605+
assert.isTrue(
606+
service.addPackages(projectRoot, [
607+
{
608+
targetName: TARGET_NAME,
609+
package: { ...dynamicPackage, embed: [] },
610+
},
611+
]),
612+
);
613+
const project = parsePbxproj(projectRoot);
614+
const objects = project.hash.project.objects;
615+
const productRef = Object.keys(
616+
objects["XCSwiftPackageProductDependency"],
617+
).find(
618+
(key) =>
619+
objects["XCSwiftPackageProductDependency"][`${key}_comment`] ===
620+
"DynamicProduct",
621+
);
622+
const userFileUuid = project.generateUuid();
623+
objects["PBXBuildFile"][userFileUuid] = {
624+
isa: "PBXBuildFile",
625+
productRef,
626+
productRef_comment: "DynamicProduct",
627+
};
628+
objects["PBXBuildFile"][`${userFileUuid}_comment`] =
629+
"DynamicProduct in Copy Runtime Libraries";
630+
objects["PBXCopyFilesBuildPhase"][EMBED_PHASE_ID].files.push({
631+
value: userFileUuid,
632+
comment: "DynamicProduct in Copy Runtime Libraries",
633+
});
634+
writeFileSync(
635+
path.join(projectRoot, `${TARGET_NAME}.xcodeproj`, "project.pbxproj"),
636+
project.writeSync(),
637+
);
638+
639+
assert.isTrue(
640+
service.addPackages(projectRoot, [
641+
{
642+
targetName: TARGET_NAME,
643+
package: { ...dynamicPackage, embed: [] },
644+
},
645+
]),
646+
);
647+
648+
assert.deepEqual(embedPhaseFileUuids(parsePbxproj(projectRoot)), [
649+
userFileUuid,
650+
]);
651+
});
652+
604653
it("keeps an embed entry another target still lists", () => {
605654
const watchExtensionId = addTarget(
606655
projectRoot,

0 commit comments

Comments
 (0)