Skip to content

Commit 4e6e28d

Browse files
committed
Refactor clangCachingBlockist to support adding more
1 parent 1a2b65d commit 4e6e28d

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -870,16 +870,8 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
870870

871871
let buildSettingEnabled = cbc.scope.evaluate(BuiltinMacros.CLANG_ENABLE_COMPILE_CACHE)
872872

873-
// If a blocklist is provided in the toolchain, use it to determine the default for the current project
874-
guard let blocklist = clangInfo?.clangCachingBlocklist else {
875-
return buildSettingEnabled
876-
}
877-
878-
// If this project is on the blocklist, override the blocklist default enable for it
879-
if blocklist.isProjectListed(cbc.scope) {
880-
return false
881-
}
882-
return buildSettingEnabled
873+
// If this project is on the blocklist, override the blocklist default enable for it.
874+
return clangInfo?.isCachingBlocked(cbc.scope) == true ? false : buildSettingEnabled
883875
}
884876

885877
private func createExplicitModulesActionAndPayload(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate, _ compilerLauncher: Path?, _ input: FileToBuild, _ language: GCCCompatibleLanguageDialect?, commandLine: [String], scanningOutputPath: Path, isForPCHTask: Bool, clangInfo: DiscoveredClangToolSpecInfo?) -> (action: (any PlannedTaskAction)?, usesExecutionInputs: Bool, payload: ClangExplicitModulesPayload?, signatureData: String?) {

Sources/SWBCore/ToolInfo/ClangToolInfo.swift

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,29 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
public import SWBMacro
1314
public import SWBUtil
1415
import Foundation
1516

17+
public struct ClangBlocklists : Sendable {
18+
19+
public struct CachingBlocklistInfo : ProjectFailuresBlockList, Codable, Sendable {
20+
/// A blocklist of project names that do not support the `CLANG_ENABLE_COMPILE_CACHE` build setting.
21+
let KnownFailures: [String]
22+
23+
enum CodingKeys: String, CodingKey {
24+
case KnownFailures
25+
}
26+
}
27+
28+
var caching: CachingBlocklistInfo? = nil
29+
30+
func isBlocked<BlockListT: ProjectFailuresBlockList>(_ scope: MacroEvaluationScope, info: BlockListT?) -> Bool {
31+
guard let blocklistInfo = info else { return false }
32+
return blocklistInfo.isProjectListed(scope)
33+
}
34+
}
35+
1636
public struct DiscoveredClangToolSpecInfo: DiscoveredCommandLineToolSpecInfo {
1737
public let toolPath: Path
1838
public let clangVersion: Version?
@@ -21,8 +41,8 @@ public struct DiscoveredClangToolSpecInfo: DiscoveredCommandLineToolSpecInfo {
2141

2242
public var toolVersion: Version? { return self.clangVersion }
2343

24-
/// `compilerClientsConfig` Clang caching blocklist
25-
public let clangCachingBlocklist: ClangCachingBlockListInfo?
44+
/// `compilerClientsConfig` blocklists for Clang
45+
public let blocklists: ClangBlocklists
2646

2747
public enum FeatureFlag: String, CaseIterable, Sendable {
2848
case allowPcmWithCompilerErrors = "allow-pcm-with-compiler-errors"
@@ -66,14 +86,10 @@ public struct DiscoveredClangToolSpecInfo: DiscoveredCommandLineToolSpecInfo {
6686
public func deploymentTargetEnvironmentVariableNames() -> Set<String> {
6787
Set(toolFeatures.value(.deploymentTargetEnvironmentVariables)?.stringArrayValue ?? [])
6888
}
69-
}
70-
71-
public struct ClangCachingBlockListInfo : ProjectFailuresBlockList, Codable, Sendable {
72-
let KnownFailures: [String]
7389

74-
enum CodingKeys: String, CodingKey {
75-
case KnownFailures
76-
}
90+
public func isCachingBlocked(_ scope: MacroEvaluationScope) -> Bool {
91+
return blocklists.isBlocked(scope, info: blocklists.caching)
92+
}
7793
}
7894

7995
private let clangVersionRe = RegEx(patternLiteral: #""(?<llvm>[0-9]+(?:\.[0-9]+){0,}) \(clang-(?<clang>[0-9]+(?:\.[0-9]+){0,})\)(?: ((\[.+\])|(\(.+\)))+)?""#)
@@ -91,7 +107,7 @@ public func discoveredClangToolInfo(
91107
) async throws -> DiscoveredClangToolSpecInfo {
92108
// Check that we call a clang variant, 'clang', 'clang++' etc. Note that a test sets `CC` to `/usr/bin/yes` so avoid calling that here.
93109
guard toolPath.basename.starts(with: "clang") else {
94-
return DiscoveredClangToolSpecInfo(toolPath: toolPath, clangVersion: nil, llvmVersion: nil, isAppleClang: false, clangCachingBlocklist: nil, toolFeatures: .none)
110+
return DiscoveredClangToolSpecInfo(toolPath: toolPath, clangVersion: nil, llvmVersion: nil, isAppleClang: false, blocklists: ClangBlocklists(), toolFeatures: .none)
95111
}
96112

97113
// Construct the command line to invoke.
@@ -169,13 +185,15 @@ public func discoveredClangToolInfo(
169185
delegate: delegate
170186
)
171187
}
188+
var blocklists = ClangBlocklists()
189+
blocklists.caching = getBlocklist(type: ClangBlocklists.CachingBlocklistInfo.self, toolchainFilename: "clang-caching.json", delegate: delegate)
172190

173191
return DiscoveredClangToolSpecInfo(
174192
toolPath: toolPath,
175193
clangVersion: clangVersion,
176194
llvmVersion: llvmVersion,
177195
isAppleClang: isAppleClang,
178-
clangCachingBlocklist: getBlocklist(type: ClangCachingBlockListInfo.self, toolchainFilename: "clang-caching.json", delegate: delegate),
196+
blocklists: blocklists,
179197
toolFeatures: getFeatures(at: toolPath)
180198
)
181199
})

0 commit comments

Comments
 (0)