mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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:
@@ -13,13 +13,13 @@
|
|||||||
struct ClangTarget {
|
struct ClangTarget {
|
||||||
var name: String
|
var name: String
|
||||||
var parentPath: RelativePath
|
var parentPath: RelativePath
|
||||||
var sources: [Source]
|
var sources: [RelativePath]
|
||||||
var unbuildableSources: [Source]
|
var unbuildableSources: [RelativePath]
|
||||||
var headers: [RelativePath]
|
var headers: [RelativePath]
|
||||||
|
|
||||||
init(
|
init(
|
||||||
name: String, parentPath: RelativePath,
|
name: String, parentPath: RelativePath,
|
||||||
sources: [Source], unbuildableSources: [Source] = [],
|
sources: [RelativePath], unbuildableSources: [RelativePath] = [],
|
||||||
headers: [RelativePath]
|
headers: [RelativePath]
|
||||||
) {
|
) {
|
||||||
self.name = name
|
self.name = name
|
||||||
@@ -30,13 +30,6 @@ struct ClangTarget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ClangTarget {
|
|
||||||
struct Source {
|
|
||||||
var path: RelativePath
|
|
||||||
var inferArgs: Bool
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension RepoBuildDir {
|
extension RepoBuildDir {
|
||||||
func getCSourceFilePaths(for path: RelativePath) throws -> [RelativePath] {
|
func getCSourceFilePaths(for path: RelativePath) throws -> [RelativePath] {
|
||||||
try getAllRepoSubpaths(of: path).filter(\.isCSourceLike)
|
try getAllRepoSubpaths(of: path).filter(\.isCSourceLike)
|
||||||
@@ -58,24 +51,15 @@ extension RepoBuildDir {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var sources: [ClangTarget.Source] = []
|
var sources: [RelativePath] = []
|
||||||
var unbuildableSources: [ClangTarget.Source] = []
|
var unbuildableSources: [RelativePath] = []
|
||||||
for path in sourcePaths {
|
for path in sourcePaths {
|
||||||
let source: ClangTarget.Source? =
|
// If we have no arguments, or have a known unbuildable, treat as not
|
||||||
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
|
|
||||||
// buildable. We'll still include it in the project, but in a separate
|
// buildable. We'll still include it in the project, but in a separate
|
||||||
// target that isn't built by default.
|
// target that isn't built by default.
|
||||||
if source.inferArgs || knownUnbuildables.contains(path) {
|
if try !clangArgs.hasBuildArgs(for: path) ||
|
||||||
unbuildableSources.append(source)
|
knownUnbuildables.contains(path) {
|
||||||
|
unbuildableSources.append(path)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// If we have no '.o' present for a given file, assume it's not buildable.
|
// If we have no '.o' present for a given file, assume it's not buildable.
|
||||||
@@ -84,10 +68,10 @@ extension RepoBuildDir {
|
|||||||
if target.mayHaveUnbuildableFiles,
|
if target.mayHaveUnbuildableFiles,
|
||||||
try !clangArgs.isObjectFilePresent(for: path) {
|
try !clangArgs.isObjectFilePresent(for: path) {
|
||||||
log.debug("! Treating '\(path)' as unbuildable; no '.o' file")
|
log.debug("! Treating '\(path)' as unbuildable; no '.o' file")
|
||||||
unbuildableSources.append(source)
|
unbuildableSources.append(path)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
sources.append(source)
|
sources.append(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ClangTarget(
|
return ClangTarget(
|
||||||
|
|||||||
@@ -15,16 +15,13 @@ struct ClangTargetSource {
|
|||||||
var name: String
|
var name: String
|
||||||
var path: RelativePath
|
var path: RelativePath
|
||||||
var mayHaveUnbuildableFiles: Bool
|
var mayHaveUnbuildableFiles: Bool
|
||||||
var inferArgs: Bool
|
|
||||||
|
|
||||||
init(
|
init(
|
||||||
at path: RelativePath, named name: String,
|
at path: RelativePath, named name: String,
|
||||||
mayHaveUnbuildableFiles: Bool,
|
mayHaveUnbuildableFiles: Bool
|
||||||
inferArgs: Bool
|
|
||||||
) {
|
) {
|
||||||
self.name = name
|
self.name = name
|
||||||
self.path = path
|
self.path = path
|
||||||
self.mayHaveUnbuildableFiles = mayHaveUnbuildableFiles
|
self.mayHaveUnbuildableFiles = mayHaveUnbuildableFiles
|
||||||
self.inferArgs = inferArgs
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ fileprivate final class ProjectGenerator {
|
|||||||
private var groups: [RelativePath: CachedGroup] = [:]
|
private var groups: [RelativePath: CachedGroup] = [:]
|
||||||
private var files: [RelativePath: Xcode.FileReference] = [:]
|
private var files: [RelativePath: Xcode.FileReference] = [:]
|
||||||
private var targets: [String: Xcode.Target] = [:]
|
private var targets: [String: Xcode.Target] = [:]
|
||||||
private var unbuildableSources: [ClangTarget.Source] = []
|
private var unbuildableSources: [RelativePath] = []
|
||||||
private var runnableBuildTargets: [RunnableTarget: Xcode.Target] = [:]
|
private var runnableBuildTargets: [RunnableTarget: Xcode.Target] = [:]
|
||||||
|
|
||||||
/// The group in which external files are stored.
|
/// The group in which external files are stored.
|
||||||
@@ -321,12 +321,11 @@ fileprivate final class ProjectGenerator {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
let parent = clangTarget.parentPath
|
let parent = clangTarget.parentPath
|
||||||
let sources = clangTarget.sources.map(\.path)
|
let hasConsistentArgs = try clangTarget.sources.allSatisfy {
|
||||||
let hasConsistentArgs = try sources.allSatisfy {
|
|
||||||
try !buildDir.clangArgs.hasUniqueArgs(for: $0, parent: parent)
|
try !buildDir.clangArgs.hasUniqueArgs(for: $0, parent: parent)
|
||||||
}
|
}
|
||||||
guard hasConsistentArgs else { return false }
|
guard hasConsistentArgs else { return false }
|
||||||
return try canUseBuildableFolder(at: parent, sources: sources)
|
return try canUseBuildableFolder(at: parent, sources: clangTarget.sources)
|
||||||
}
|
}
|
||||||
|
|
||||||
func canUseBuildableFolder(
|
func canUseBuildableFolder(
|
||||||
@@ -394,15 +393,14 @@ fileprivate final class ProjectGenerator {
|
|||||||
let sourcesToBuild = target.addSourcesBuildPhase()
|
let sourcesToBuild = target.addSourcesBuildPhase()
|
||||||
|
|
||||||
for source in targetInfo.sources {
|
for source in targetInfo.sources {
|
||||||
let sourcePath = source.path
|
guard let sourceRef = getOrCreateRepoRef(.file(source)) else {
|
||||||
guard let sourceRef = getOrCreateRepoRef(.file(sourcePath)) else {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
let buildFile = sourcesToBuild.addBuildFile(fileRef: sourceRef)
|
let buildFile = sourcesToBuild.addBuildFile(fileRef: sourceRef)
|
||||||
|
|
||||||
// Add any per-file settings.
|
// Add any per-file settings.
|
||||||
var fileArgs = try buildDir.clangArgs.getUniqueArgs(
|
var fileArgs = try buildDir.clangArgs.getUniqueArgs(
|
||||||
for: sourcePath, parent: targetPath, infer: source.inferArgs
|
for: source, parent: targetPath, infer: spec.inferArgs
|
||||||
)
|
)
|
||||||
if !fileArgs.isEmpty {
|
if !fileArgs.isEmpty {
|
||||||
applyBaseSubstitutions(to: &fileArgs)
|
applyBaseSubstitutions(to: &fileArgs)
|
||||||
|
|||||||
@@ -206,9 +206,7 @@ extension ProjectSpec {
|
|||||||
guard let path = mapPath(path, for: "Clang target") else { return }
|
guard let path = mapPath(path, for: "Clang target") else { return }
|
||||||
let name = name ?? path.fileName
|
let name = name ?? path.fileName
|
||||||
clangTargetSources.append(ClangTargetSource(
|
clangTargetSources.append(ClangTargetSource(
|
||||||
at: path, named: name,
|
at: path, named: name, mayHaveUnbuildableFiles: mayHaveUnbuildableFiles
|
||||||
mayHaveUnbuildableFiles: mayHaveUnbuildableFiles,
|
|
||||||
inferArgs: inferArgs
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user