@@ -34,7 +34,7 @@ fileprivate final class ProjectGenerator {
3434 private var groups : [ RelativePath : CachedGroup ] = [ : ]
3535 private var files : [ RelativePath : Xcode . FileReference ] = [ : ]
3636 private var targets : [ String : Xcode . Target ] = [ : ]
37- private var unbuildableSources : [ ClangTarget . Source ] = [ ]
37+ private var unbuildableSources : [ RelativePath ] = [ ]
3838 private var runnableBuildTargets : [ RunnableTarget : Xcode . Target ] = [ : ]
3939
4040 /// The group in which external files are stored.
@@ -154,8 +154,9 @@ fileprivate final class ProjectGenerator {
154154 guard let path else { return true }
155155
156156 // Not very efficient, but excludedPaths should be small in practice.
157- guard let excluded = spec. excludedPaths. first ( where: { path. hasPrefix ( $0. path) } )
158- else {
157+ guard let excluded = spec. excludedPaths. first (
158+ where: { path. starts ( with: $0. path) }
159+ ) else {
159160 return true
160161 }
161162 if let description, let reason = excluded. reason {
@@ -213,10 +214,18 @@ fileprivate final class ProjectGenerator {
213214 _ name: String , at parentPath: RelativePath ? , canUseBuildableFolder: Bool ,
214215 productType: Xcode . Target . ProductType ? , includeInAllTarget: Bool
215216 ) -> Xcode . Target ? {
216- guard targets [ name] == nil else {
217- log. warning ( " Duplicate target ' \( name) ', skipping " )
218- return nil
219- }
217+ let name = {
218+ // If we have a same-named target, disambiguate.
219+ if targets [ name] == nil {
220+ return name
221+ }
222+ var i = 2
223+ var newName : String { " \( name) \( i) " }
224+ while targets [ newName] != nil {
225+ i += 1
226+ }
227+ return newName
228+ } ( )
220229 var buildableFolder : Xcode . FileReference ?
221230 if let parentPath, !parentPath. components. isEmpty {
222231 // If we've been asked to use buildable folders, see if we can create
@@ -230,7 +239,9 @@ fileprivate final class ProjectGenerator {
230239 group ( for: repoRelativePath. appending ( parentPath) ) != nil else {
231240 // If this isn't a child of an explicitly added reference, something
232241 // has probably gone wrong.
233- if !spec. referencesToAdd. contains ( where: { parentPath. hasPrefix ( $0. path) } ) {
242+ if !spec. referencesToAdd. contains (
243+ where: { parentPath. starts ( with: $0. path) }
244+ ) {
234245 log. warning ( """
235246 Target ' \( name) ' at ' \( repoRelativePath. appending ( parentPath) ) ' is \
236247 nested in a folder reference; skipping. This is likely an xcodegen bug.
@@ -310,12 +321,11 @@ fileprivate final class ProjectGenerator {
310321 return false
311322 }
312323 let parent = clangTarget. parentPath
313- let sources = clangTarget. sources. map ( \. path)
314- let hasConsistentArgs = try sources. allSatisfy {
324+ let hasConsistentArgs = try clangTarget. sources. allSatisfy {
315325 try ! buildDir. clangArgs. hasUniqueArgs ( for: $0, parent: parent)
316326 }
317327 guard hasConsistentArgs else { return false }
318- return try canUseBuildableFolder ( at: parent, sources: sources)
328+ return try canUseBuildableFolder ( at: parent, sources: clangTarget . sources)
319329 }
320330
321331 func canUseBuildableFolder(
@@ -383,15 +393,14 @@ fileprivate final class ProjectGenerator {
383393 let sourcesToBuild = target. addSourcesBuildPhase ( )
384394
385395 for source in targetInfo. sources {
386- let sourcePath = source. path
387- guard let sourceRef = getOrCreateRepoRef ( . file( sourcePath) ) else {
396+ guard let sourceRef = getOrCreateRepoRef ( . file( source) ) else {
388397 continue
389398 }
390399 let buildFile = sourcesToBuild. addBuildFile ( fileRef: sourceRef)
391400
392401 // Add any per-file settings.
393402 var fileArgs = try buildDir. clangArgs. getUniqueArgs (
394- for: sourcePath , parent: targetPath, infer: source . inferArgs
403+ for: source , parent: targetPath, infer: spec . inferArgs
395404 )
396405 if !fileArgs. isEmpty {
397406 applyBaseSubstitutions ( to: & fileArgs)
@@ -747,12 +756,7 @@ fileprivate final class ProjectGenerator {
747756 let target = try buildDir. getClangTarget (
748757 for: targetSource, knownUnbuildables: spec. knownUnbuildables
749758 )
750- guard var target else { continue }
751- // We may have a Swift target with the same name, disambiguate.
752- // FIXME: We ought to be able to support mixed-source targets.
753- if targets [ target. name] != nil {
754- target. name = " \( target. name) -clang "
755- }
759+ guard let target else { continue }
756760 try generateClangTarget ( target)
757761 }
758762
0 commit comments