Skip to content

Commit 486cd42

Browse files
committed
[xcodegen] Avoid buildable folders for mixed Swift targets
If a Swift target has sources in its folder that aren't part of the target, we can't form a buildable folder.
1 parent 54bf65b commit 486cd42

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

utils/swift-xcodegen/Sources/SwiftXcodeGen/Generator/ProjectGenerator.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,20 @@ fileprivate final class ProjectGenerator {
531531
guard checkNotExcluded(buildRule.parentPath, for: "Swift target") else {
532532
return nil
533533
}
534-
// Create the target. Swift targets can always use buildable folders
535-
// since they have a consistent set of arguments.
534+
// Swift targets can almost always use buildable folders since they have
535+
// a consistent set of arguments, but we need to ensure we don't have any
536+
// child source files that aren't part of the target.
537+
let canUseBuildableFolder = try {
538+
guard let parent = buildRule.parentPath else { return false }
539+
let repoSources = Set(buildRule.sources.repoSources)
540+
return try getAllRepoSubpaths(of: parent)
541+
.allSatisfy { !$0.isSourceLike || repoSources.contains($0) }
542+
}()
543+
// Create the target.
536544
let target = generateBaseTarget(
537-
targetInfo.name, at: buildRule.parentPath, canUseBuildableFolder: true,
538-
productType: .staticArchive, includeInAllTarget: includeInAllTarget
545+
targetInfo.name, at: buildRule.parentPath,
546+
canUseBuildableFolder: canUseBuildableFolder, productType: .staticArchive,
547+
includeInAllTarget: includeInAllTarget
539548
)
540549
guard let target else { return nil }
541550

utils/swift-xcodegen/Sources/SwiftXcodeGen/Path/PathProtocol.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ extension PathProtocol {
127127
hasExtension(.c, .cpp, .m, .mm)
128128
}
129129

130+
var isSourceLike: Bool {
131+
isCSourceLike || hasExtension(.swift)
132+
}
133+
130134
var isDocLike: Bool {
131135
hasExtension(.md, .rst) || fileName.starts(with: "README")
132136
}

0 commit comments

Comments
 (0)