[xcodegen] Avoid tracking inferArgs per target/source

This is unnecessary since we never configure it
per target, just check the global setting.
This commit is contained in:
Hamish Knight
2025-01-01 13:34:48 +00:00
parent 38c1d28197
commit ddfe63bdc8
4 changed files with 18 additions and 41 deletions

View File

@@ -13,13 +13,13 @@
struct ClangTarget {
var name: String
var parentPath: RelativePath
var sources: [Source]
var unbuildableSources: [Source]
var sources: [RelativePath]
var unbuildableSources: [RelativePath]
var headers: [RelativePath]
init(
name: String, parentPath: RelativePath,
sources: [Source], unbuildableSources: [Source] = [],
sources: [RelativePath], unbuildableSources: [RelativePath] = [],
headers: [RelativePath]
) {
self.name = name
@@ -30,13 +30,6 @@ struct ClangTarget {
}
}
extension ClangTarget {
struct Source {
var path: RelativePath
var inferArgs: Bool
}
}
extension RepoBuildDir {
func getCSourceFilePaths(for path: RelativePath) throws -> [RelativePath] {
try getAllRepoSubpaths(of: path).filter(\.isCSourceLike)
@@ -58,24 +51,15 @@ extension RepoBuildDir {
return nil
}
var sources: [ClangTarget.Source] = []
var unbuildableSources: [ClangTarget.Source] = []
var sources: [RelativePath] = []
var unbuildableSources: [RelativePath] = []
for path in sourcePaths {
let source: ClangTarget.Source? =
if try clangArgs.hasBuildArgs(for: path) {
.init(path: path, inferArgs: false)
} else if target.inferArgs {
.init(path: path, inferArgs: true)
} else {
nil
}
guard let source else { continue }
// If we're inferring arguments, or have a known unbuildable, treat as not
// If we have no arguments, or have a known unbuildable, treat as not
// buildable. We'll still include it in the project, but in a separate
// target that isn't built by default.
if source.inferArgs || knownUnbuildables.contains(path) {
unbuildableSources.append(source)
if try !clangArgs.hasBuildArgs(for: path) ||
knownUnbuildables.contains(path) {
unbuildableSources.append(path)
continue
}
// If we have no '.o' present for a given file, assume it's not buildable.
@@ -84,10 +68,10 @@ extension RepoBuildDir {
if target.mayHaveUnbuildableFiles,
try !clangArgs.isObjectFilePresent(for: path) {
log.debug("! Treating '\(path)' as unbuildable; no '.o' file")
unbuildableSources.append(source)
unbuildableSources.append(path)
continue
}
sources.append(source)
sources.append(path)
}
return ClangTarget(

View File

@@ -15,16 +15,13 @@ struct ClangTargetSource {
var name: String
var path: RelativePath
var mayHaveUnbuildableFiles: Bool
var inferArgs: Bool
init(
at path: RelativePath, named name: String,
mayHaveUnbuildableFiles: Bool,
inferArgs: Bool
mayHaveUnbuildableFiles: Bool
) {
self.name = name
self.path = path
self.mayHaveUnbuildableFiles = mayHaveUnbuildableFiles
self.inferArgs = inferArgs
}
}

View File

@@ -34,7 +34,7 @@ fileprivate final class ProjectGenerator {
private var groups: [RelativePath: CachedGroup] = [:]
private var files: [RelativePath: Xcode.FileReference] = [:]
private var targets: [String: Xcode.Target] = [:]
private var unbuildableSources: [ClangTarget.Source] = []
private var unbuildableSources: [RelativePath] = []
private var runnableBuildTargets: [RunnableTarget: Xcode.Target] = [:]
/// The group in which external files are stored.
@@ -321,12 +321,11 @@ fileprivate final class ProjectGenerator {
return false
}
let parent = clangTarget.parentPath
let sources = clangTarget.sources.map(\.path)
let hasConsistentArgs = try sources.allSatisfy {
let hasConsistentArgs = try clangTarget.sources.allSatisfy {
try !buildDir.clangArgs.hasUniqueArgs(for: $0, parent: parent)
}
guard hasConsistentArgs else { return false }
return try canUseBuildableFolder(at: parent, sources: sources)
return try canUseBuildableFolder(at: parent, sources: clangTarget.sources)
}
func canUseBuildableFolder(
@@ -394,15 +393,14 @@ fileprivate final class ProjectGenerator {
let sourcesToBuild = target.addSourcesBuildPhase()
for source in targetInfo.sources {
let sourcePath = source.path
guard let sourceRef = getOrCreateRepoRef(.file(sourcePath)) else {
guard let sourceRef = getOrCreateRepoRef(.file(source)) else {
continue
}
let buildFile = sourcesToBuild.addBuildFile(fileRef: sourceRef)
// Add any per-file settings.
var fileArgs = try buildDir.clangArgs.getUniqueArgs(
for: sourcePath, parent: targetPath, infer: source.inferArgs
for: source, parent: targetPath, infer: spec.inferArgs
)
if !fileArgs.isEmpty {
applyBaseSubstitutions(to: &fileArgs)

View File

@@ -206,9 +206,7 @@ extension ProjectSpec {
guard let path = mapPath(path, for: "Clang target") else { return }
let name = name ?? path.fileName
clangTargetSources.append(ClangTargetSource(
at: path, named: name,
mayHaveUnbuildableFiles: mayHaveUnbuildableFiles,
inferArgs: inferArgs
at: path, named: name, mayHaveUnbuildableFiles: mayHaveUnbuildableFiles
))
}