@@ -34,7 +34,7 @@ fileprivate final class ProjectGenerator {
34
34
private var groups : [ RelativePath : CachedGroup ] = [ : ]
35
35
private var files : [ RelativePath : Xcode . FileReference ] = [ : ]
36
36
private var targets : [ String : Xcode . Target ] = [ : ]
37
- private var unbuildableSources : [ ClangTarget . Source ] = [ ]
37
+ private var unbuildableSources : [ RelativePath ] = [ ]
38
38
private var runnableBuildTargets : [ RunnableTarget : Xcode . Target ] = [ : ]
39
39
40
40
/// The group in which external files are stored.
@@ -154,8 +154,9 @@ fileprivate final class ProjectGenerator {
154
154
guard let path else { return true }
155
155
156
156
// 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 {
159
160
return true
160
161
}
161
162
if let description, let reason = excluded. reason {
@@ -213,10 +214,18 @@ fileprivate final class ProjectGenerator {
213
214
_ name: String , at parentPath: RelativePath ? , canUseBuildableFolder: Bool ,
214
215
productType: Xcode . Target . ProductType ? , includeInAllTarget: Bool
215
216
) -> 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
+ } ( )
220
229
var buildableFolder : Xcode . FileReference ?
221
230
if let parentPath, !parentPath. components. isEmpty {
222
231
// If we've been asked to use buildable folders, see if we can create
@@ -230,7 +239,9 @@ fileprivate final class ProjectGenerator {
230
239
group ( for: repoRelativePath. appending ( parentPath) ) != nil else {
231
240
// If this isn't a child of an explicitly added reference, something
232
241
// 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
+ ) {
234
245
log. warning ( """
235
246
Target ' \( name) ' at ' \( repoRelativePath. appending ( parentPath) ) ' is \
236
247
nested in a folder reference; skipping. This is likely an xcodegen bug.
@@ -310,12 +321,11 @@ fileprivate final class ProjectGenerator {
310
321
return false
311
322
}
312
323
let parent = clangTarget. parentPath
313
- let sources = clangTarget. sources. map ( \. path)
314
- let hasConsistentArgs = try sources. allSatisfy {
324
+ let hasConsistentArgs = try clangTarget. sources. allSatisfy {
315
325
try ! buildDir. clangArgs. hasUniqueArgs ( for: $0, parent: parent)
316
326
}
317
327
guard hasConsistentArgs else { return false }
318
- return try canUseBuildableFolder ( at: parent, sources: sources)
328
+ return try canUseBuildableFolder ( at: parent, sources: clangTarget . sources)
319
329
}
320
330
321
331
func canUseBuildableFolder(
@@ -383,15 +393,14 @@ fileprivate final class ProjectGenerator {
383
393
let sourcesToBuild = target. addSourcesBuildPhase ( )
384
394
385
395
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 {
388
397
continue
389
398
}
390
399
let buildFile = sourcesToBuild. addBuildFile ( fileRef: sourceRef)
391
400
392
401
// Add any per-file settings.
393
402
var fileArgs = try buildDir. clangArgs. getUniqueArgs (
394
- for: sourcePath , parent: targetPath, infer: source . inferArgs
403
+ for: source , parent: targetPath, infer: spec . inferArgs
395
404
)
396
405
if !fileArgs. isEmpty {
397
406
applyBaseSubstitutions ( to: & fileArgs)
@@ -747,12 +756,7 @@ fileprivate final class ProjectGenerator {
747
756
let target = try buildDir. getClangTarget (
748
757
for: targetSource, knownUnbuildables: spec. knownUnbuildables
749
758
)
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 }
756
760
try generateClangTarget ( target)
757
761
}
758
762
0 commit comments