Skip to content

Commit ddfe63b

Browse files
committed
[xcodegen] Avoid tracking inferArgs per target/source
This is unnecessary since we never configure it per target, just check the global setting.
1 parent 38c1d28 commit ddfe63b

File tree

4 files changed

+18
-41
lines changed

4 files changed

+18
-41
lines changed

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

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
struct ClangTarget {
1414
var name: String
1515
var parentPath: RelativePath
16-
var sources: [Source]
17-
var unbuildableSources: [Source]
16+
var sources: [RelativePath]
17+
var unbuildableSources: [RelativePath]
1818
var headers: [RelativePath]
1919

2020
init(
2121
name: String, parentPath: RelativePath,
22-
sources: [Source], unbuildableSources: [Source] = [],
22+
sources: [RelativePath], unbuildableSources: [RelativePath] = [],
2323
headers: [RelativePath]
2424
) {
2525
self.name = name
@@ -30,13 +30,6 @@ struct ClangTarget {
3030
}
3131
}
3232

33-
extension ClangTarget {
34-
struct Source {
35-
var path: RelativePath
36-
var inferArgs: Bool
37-
}
38-
}
39-
4033
extension RepoBuildDir {
4134
func getCSourceFilePaths(for path: RelativePath) throws -> [RelativePath] {
4235
try getAllRepoSubpaths(of: path).filter(\.isCSourceLike)
@@ -58,24 +51,15 @@ extension RepoBuildDir {
5851
return nil
5952
}
6053

61-
var sources: [ClangTarget.Source] = []
62-
var unbuildableSources: [ClangTarget.Source] = []
54+
var sources: [RelativePath] = []
55+
var unbuildableSources: [RelativePath] = []
6356
for path in sourcePaths {
64-
let source: ClangTarget.Source? =
65-
if try clangArgs.hasBuildArgs(for: path) {
66-
.init(path: path, inferArgs: false)
67-
} else if target.inferArgs {
68-
.init(path: path, inferArgs: true)
69-
} else {
70-
nil
71-
}
72-
guard let source else { continue }
73-
74-
// If we're inferring arguments, or have a known unbuildable, treat as not
57+
// If we have no arguments, or have a known unbuildable, treat as not
7558
// buildable. We'll still include it in the project, but in a separate
7659
// target that isn't built by default.
77-
if source.inferArgs || knownUnbuildables.contains(path) {
78-
unbuildableSources.append(source)
60+
if try !clangArgs.hasBuildArgs(for: path) ||
61+
knownUnbuildables.contains(path) {
62+
unbuildableSources.append(path)
7963
continue
8064
}
8165
// If we have no '.o' present for a given file, assume it's not buildable.
@@ -84,10 +68,10 @@ extension RepoBuildDir {
8468
if target.mayHaveUnbuildableFiles,
8569
try !clangArgs.isObjectFilePresent(for: path) {
8670
log.debug("! Treating '\(path)' as unbuildable; no '.o' file")
87-
unbuildableSources.append(source)
71+
unbuildableSources.append(path)
8872
continue
8973
}
90-
sources.append(source)
74+
sources.append(path)
9175
}
9276

9377
return ClangTarget(

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@ struct ClangTargetSource {
1515
var name: String
1616
var path: RelativePath
1717
var mayHaveUnbuildableFiles: Bool
18-
var inferArgs: Bool
1918

2019
init(
2120
at path: RelativePath, named name: String,
22-
mayHaveUnbuildableFiles: Bool,
23-
inferArgs: Bool
21+
mayHaveUnbuildableFiles: Bool
2422
) {
2523
self.name = name
2624
self.path = path
2725
self.mayHaveUnbuildableFiles = mayHaveUnbuildableFiles
28-
self.inferArgs = inferArgs
2926
}
3027
}

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
@@ -321,12 +321,11 @@ fileprivate final class ProjectGenerator {
321321
return false
322322
}
323323
let parent = clangTarget.parentPath
324-
let sources = clangTarget.sources.map(\.path)
325-
let hasConsistentArgs = try sources.allSatisfy {
324+
let hasConsistentArgs = try clangTarget.sources.allSatisfy {
326325
try !buildDir.clangArgs.hasUniqueArgs(for: $0, parent: parent)
327326
}
328327
guard hasConsistentArgs else { return false }
329-
return try canUseBuildableFolder(at: parent, sources: sources)
328+
return try canUseBuildableFolder(at: parent, sources: clangTarget.sources)
330329
}
331330

332331
func canUseBuildableFolder(
@@ -394,15 +393,14 @@ fileprivate final class ProjectGenerator {
394393
let sourcesToBuild = target.addSourcesBuildPhase()
395394

396395
for source in targetInfo.sources {
397-
let sourcePath = source.path
398-
guard let sourceRef = getOrCreateRepoRef(.file(sourcePath)) else {
396+
guard let sourceRef = getOrCreateRepoRef(.file(source)) else {
399397
continue
400398
}
401399
let buildFile = sourcesToBuild.addBuildFile(fileRef: sourceRef)
402400

403401
// Add any per-file settings.
404402
var fileArgs = try buildDir.clangArgs.getUniqueArgs(
405-
for: sourcePath, parent: targetPath, infer: source.inferArgs
403+
for: source, parent: targetPath, infer: spec.inferArgs
406404
)
407405
if !fileArgs.isEmpty {
408406
applyBaseSubstitutions(to: &fileArgs)

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ extension ProjectSpec {
206206
guard let path = mapPath(path, for: "Clang target") else { return }
207207
let name = name ?? path.fileName
208208
clangTargetSources.append(ClangTargetSource(
209-
at: path, named: name,
210-
mayHaveUnbuildableFiles: mayHaveUnbuildableFiles,
211-
inferArgs: inferArgs
209+
at: path, named: name, mayHaveUnbuildableFiles: mayHaveUnbuildableFiles
212210
))
213211
}
214212

0 commit comments

Comments
 (0)