Skip to content

Commit 6e0289b

Browse files
committed
Fix membership exceptions for nested synced folder with intermediate groups
1 parent 343f000 commit 6e0289b

2 files changed

Lines changed: 36 additions & 12 deletions

File tree

Sources/XcodeGenKit/PBXProjGenerator.swift

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,29 +1457,30 @@ public class PBXProjGenerator {
14571457
}
14581458

14591459
// add fileSystemSynchronizedGroups
1460-
let synchronizedRootGroups = sourceFiles.compactMap { $0.fileReference as? PBXFileSystemSynchronizedRootGroup }
1460+
let synchronizedRootGroups: [PBXFileSystemSynchronizedRootGroup] = sourceFiles.compactMap { sourceFile in
1461+
guard let syncedGroup = sourceFile.fileReference as? PBXFileSystemSynchronizedRootGroup else { return nil }
1462+
1463+
configureMembershipExceptions(
1464+
for: syncedGroup,
1465+
path: sourceFile.path,
1466+
target: target,
1467+
targetObject: targetObject,
1468+
infoPlistFiles: infoPlistFiles
1469+
)
1470+
return syncedGroup
1471+
}
14611472
if !synchronizedRootGroups.isEmpty {
1462-
for syncedGroup in synchronizedRootGroups {
1463-
configureMembershipExceptions(
1464-
for: syncedGroup,
1465-
target: target,
1466-
targetObject: targetObject,
1467-
infoPlistFiles: infoPlistFiles
1468-
)
1469-
}
14701473
targetObject.fileSystemSynchronizedGroups = synchronizedRootGroups
14711474
}
14721475
}
14731476

14741477
private func configureMembershipExceptions(
14751478
for syncedGroup: PBXFileSystemSynchronizedRootGroup,
1479+
path syncedPath: Path,
14761480
target: Target,
14771481
targetObject: PBXTarget,
14781482
infoPlistFiles: [Config: String]
14791483
) {
1480-
guard let syncedGroupPath = syncedGroup.path else { return }
1481-
let syncedPath = (project.basePath + Path(syncedGroupPath)).normalize()
1482-
14831484
guard let targetSource = target.sources.first(where: {
14841485
(project.basePath + $0.path).normalize() == syncedPath
14851486
}) else { return }

Tests/XcodeGenKitTests/SourceGeneratorTests.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,29 @@ class SourceGeneratorTests: XCTestCase {
203203
try expect(exceptions.contains("a.swift")) == false
204204
}
205205

206+
$0.it("adds membership exceptions for nested synced folder with intermediate groups") {
207+
let directories = """
208+
Sources:
209+
Nested:
210+
- a.swift
211+
- b.swift
212+
"""
213+
try createDirectories(directories)
214+
215+
let source = TargetSource(path: "Sources/Nested", excludes: ["b.swift"], type: .syncedFolder)
216+
let target = Target(name: "Test", type: .application, platform: .iOS, sources: [source])
217+
let project = Project(basePath: directoryPath, name: "Test", targets: [target], options: .init(createIntermediateGroups: true))
218+
219+
let pbxProj = try project.generatePbxProj()
220+
let sourcesGroup = try unwrap(try pbxProj.getMainGroup().children.first { $0.nameOrPath == "Sources" } as? PBXGroup)
221+
let syncedFolder = try unwrap(sourcesGroup.children.compactMap { $0 as? PBXFileSystemSynchronizedRootGroup }.first)
222+
223+
let exceptionSet = try unwrap(syncedFolder.exceptions?.first as? PBXFileSystemSynchronizedBuildFileExceptionSet)
224+
let exceptions = try unwrap(exceptionSet.membershipExceptions)
225+
226+
try expect(exceptions) == ["b.swift"]
227+
}
228+
206229
$0.it("auto-excludes Info.plist from synced folder membership") {
207230
let directories = """
208231
Sources:

0 commit comments

Comments
 (0)