Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure that file references are fixed for filesystem synchronized root groups #897

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Loading