Skip to content

Commit

Permalink
fix: ensure that file references are fixed for filesystem synchronize…
Browse files Browse the repository at this point in the history
…d root groups (#897)

* Ensure that file references are fixed for filesystem synchronized root groups

* Fix lint

* fix: Ensure that file references are fixed for filesystem synchronized root groups
  • Loading branch information
bryansum authored Jan 27, 2025
1 parent 15b85e6 commit 684e4ef
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Sources/XcodeProj/Utils/ReferenceGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ final class ReferenceGenerator: ReferenceGenerating {
guard let childFileElement: PBXFileElement = child.getObject() else { return }
if let childGroup = childFileElement as? PBXGroup {
try generateGroupReferences(childGroup, identifiers: identifiers)
} else if let childSynchronizedRootGroup = childFileElement as? PBXFileSystemSynchronizedRootGroup {
try generateSynchronizedRootGroupReferences(childSynchronizedRootGroup, identifiers: identifiers)
} else if let childFileReference = childFileElement as? PBXFileReference {
try generateFileReference(childFileReference, identifiers: identifiers)
} else if let childReferenceProxy = childFileElement as? PBXReferenceProxy {
Expand All @@ -161,6 +163,21 @@ final class ReferenceGenerator: ReferenceGenerating {
fixReference(for: fileReference, identifiers: identifiers)
}

/// Generates the reference for a synchronized root group object.
///
/// - Parameters:
/// - synchronizedRootGroup: synchronized root group instance.
/// - identifiers: list of identifiers.
private func generateSynchronizedRootGroupReferences(_ synchronizedRootGroup: PBXFileSystemSynchronizedRootGroup,
identifiers: [String]) throws {
var identifiers = identifiers
if let groupName = synchronizedRootGroup.fileName() {
identifiers.append(groupName)
}

fixReference(for: synchronizedRootGroup, identifiers: identifiers)
}

/// Generates the reference for a configuration list object.
///
/// - Parameters:
Expand Down
34 changes: 34 additions & 0 deletions Tests/XcodeProjTests/Utils/ReferenceGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ class ReferenceGeneratorTests: XCTestCase {

XCTAssertNotEqual(firstProductsGroupUUID, secondProductsGroupUUID)
}

func test_projectWithFilesystemSynchronizedRootGroup_convertsReferencesToPermanent() throws {
let project = PBXProj(rootObject: nil, objectVersion: 0, archiveVersion: 0, classes: [:], objects: [])
let pbxProject = project.makeProject()

let syncedGroup = project.makeSynchronizedRootGroup()
let target = project.makeTarget()
target.fileSystemSynchronizedGroups = [syncedGroup]
pbxProject.targets.append(target)

let referenceGenerator = ReferenceGenerator(outputSettings: PBXOutputSettings())
try referenceGenerator.generateReferences(proj: project)

XCTAssert(!syncedGroup.reference.temporary)
}
}

private extension PBXProj {
Expand Down Expand Up @@ -168,4 +183,23 @@ private extension PBXProj {

return (target, buildFile)
}

func makeTarget() -> PBXTarget {
let target = PBXNativeTarget(name: "MyApp",
productName: "MyApp.app",
productType: .application)
add(object: target)
return target
}

func makeSynchronizedRootGroup() -> PBXFileSystemSynchronizedRootGroup {
let syncedGroup = PBXFileSystemSynchronizedRootGroup(
sourceTree: .group,
path: "SyncedPath",
name: "SyncedGroup"
)
add(object: syncedGroup)
rootObject!.mainGroup.children.append(syncedGroup)
return syncedGroup
}
}

0 comments on commit 684e4ef

Please sign in to comment.