Skip to content

Commit dc3aecc

Browse files
committed
Move project identity matching to a plugin
These are behaviors specific to certain environments that don't belong in the core logic.
1 parent 4a645f9 commit dc3aecc

File tree

15 files changed

+83
-40
lines changed

15 files changed

+83
-40
lines changed

Sources/SWBApplePlatform/Plugin.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,4 @@ struct AppleSettingsBuilderExtension: SettingsBuilderExtension {
262262
let constValueProtocols = [appIntentsProtocols, extensionKitProtocols].joined(separator: " ")
263263
return ["SWIFT_EMIT_CONST_VALUE_PROTOCOLS" : constValueProtocols]
264264
}
265-
func addOverrides(fromEnvironment: [String : String], parameters: BuildParameters) throws -> [String : String] { [:] }
266-
func addProductTypeDefaults(productType: ProductTypeSpec) -> [String : String] { [:] }
267-
func addSDKOverridingSettings(_ sdk: SDK, _ variant: SDKVariant?, _ sparseSDKs: [SDK], specLookupContext: any SWBCore.SpecLookupContext, environment: [String: String]) throws -> [String : String] { [:] }
268-
func addPlatformSDKSettings(_ platform: SWBCore.Platform?, _ sdk: SDK, _ sdkVariant: SDKVariant?) -> [String : String] { [:] }
269-
func xcconfigOverrideData(fromParameters: BuildParameters) -> ByteString { ByteString() }
270-
func getTargetTestingSwiftPluginFlags(_ scope: MacroEvaluationScope, toolchainRegistry: ToolchainRegistry, sdkRegistry: SDKRegistry, activeRunDestination: RunDestinationInfo?, project: SWBCore.Project?) -> [String] { [] }
271-
func shouldSkipPopulatingValidArchs(platform: SWBCore.Platform, sdk: SDK?) -> Bool { false }
272-
func shouldDisableXOJITPreviews(platformName: String, sdk: SDK?) -> Bool { false }
273-
func overridingBuildSettings(_: MacroEvaluationScope, platform: SWBCore.Platform?, productType: ProductTypeSpec) -> [String : String] { [:] }
274265
}

Sources/SWBCore/Extensions/SettingsBuilderExtension.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,21 @@ public protocol SettingsBuilderExtension: Sendable {
5353
func shouldDisableXOJITPreviews(platformName: String, sdk: SDK?) -> Bool
5454

5555
func overridingBuildSettings(_: MacroEvaluationScope, platform: Platform?, productType: ProductTypeSpec) -> [String: String]
56+
57+
func matchesAnyProjectIdentities(scope: MacroEvaluationScope, projectIdentities: Set<String>) -> Bool
58+
}
59+
60+
extension SettingsBuilderExtension {
61+
public func addOverrides(fromEnvironment: [String: String], parameters: BuildParameters) throws -> [String: String] { [:] }
62+
public func addBuiltinDefaults(fromEnvironment environment: [String: String], parameters: BuildParameters) throws -> [String: String] { [:] }
63+
public func addProductTypeDefaults(productType: ProductTypeSpec) -> [String: String] { [:] }
64+
public func addSDKSettings(_ sdk: SDK, _ variant: SDKVariant?, _ sparseSDKs: [SDK]) throws -> [String: String] { [:] }
65+
public func addSDKOverridingSettings(_ sdk: SDK, _ variant: SDKVariant?, _ sparseSDKs: [SDK], specLookupContext: any SWBCore.SpecLookupContext, environment: [String: String]) throws -> [String: String] { [:] }
66+
public func addPlatformSDKSettings(_ platform: SWBCore.Platform?, _ sdk: SDK, _ sdkVariant: SDKVariant?) -> [String: String] { [:] }
67+
public func xcconfigOverrideData(fromParameters: BuildParameters) -> ByteString { ByteString() }
68+
public func getTargetTestingSwiftPluginFlags(_ scope: MacroEvaluationScope, toolchainRegistry: ToolchainRegistry, sdkRegistry: SDKRegistry, activeRunDestination: RunDestinationInfo?, project: SWBCore.Project?) -> [String] { [] }
69+
public func shouldSkipPopulatingValidArchs(platform: SWBCore.Platform, sdk: SDK?) -> Bool { false }
70+
public func shouldDisableXOJITPreviews(platformName: String, sdk: SDK?) -> Bool { false }
71+
public func overridingBuildSettings(_: MacroEvaluationScope, platform: SWBCore.Platform?, productType: ProductTypeSpec) -> [String: String] { [:] }
72+
public func matchesAnyProjectIdentities(scope: MacroEvaluationScope, projectIdentities: Set<String>) -> Bool { false }
5673
}

Sources/SWBCore/Settings/BuiltinMacros.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,8 +1210,6 @@ public final class BuiltinMacros {
12101210
public static let TARGET_DEVICE_PLATFORM_NAME = BuiltinMacros.declareStringMacro("TARGET_DEVICE_PLATFORM_NAME")
12111211

12121212
public static let RC_ARCHS = BuiltinMacros.declareStringListMacro("RC_ARCHS")
1213-
public static let RC_BASE_PROJECT_NAME = BuiltinMacros.declareStringMacro("RC_BASE_PROJECT_NAME")
1214-
public static let RC_ProjectName = BuiltinMacros.declareStringMacro("RC_ProjectName")
12151213

12161214
// LLVM Target
12171215
public static let LLVM_TARGET_TRIPLE_OS_VERSION = BuiltinMacros.declareStringMacro("LLVM_TARGET_TRIPLE_OS_VERSION")
@@ -2140,8 +2138,6 @@ public final class BuiltinMacros {
21402138
PUBLIC_HEADERS_FOLDER_PATH,
21412139
ProductResourcesDir,
21422140
RC_ARCHS,
2143-
RC_BASE_PROJECT_NAME,
2144-
RC_ProjectName,
21452141
RECORD_SYSTEM_HEADER_DEPENDENCIES_OUTSIDE_SYSROOT,
21462142
RECURSIVE_SEARCH_PATHS_FOLLOW_SYMLINKS,
21472143
MAKE_MERGEABLE,

Sources/SWBCore/Settings/Settings.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,11 @@ public struct SettingsContext: Sendable {
11761176
}
11771177

11781178
/// This class is responsible for construction of the build settings to use when evaluate macros for a project or target.
1179-
private class SettingsBuilder {
1179+
private class SettingsBuilder: ProjectMatchLookup {
1180+
func matchesAnyProjectIdentities(scope: SWBMacro.MacroEvaluationScope, projectIdentities: Set<String>) -> Bool {
1181+
workspaceContext.core.pluginManager.extensions(of: SettingsBuilderExtensionPoint.self).contains(where: { ext in ext.matchesAnyProjectIdentities(scope: scope, projectIdentities: projectIdentities) })
1182+
}
1183+
11801184
/// This struct wraps properties which are bound as a result of the input parameters and then used to compute the full settings.
11811185
struct BoundProperties {
11821186

@@ -1664,7 +1668,7 @@ private class SettingsBuilder {
16641668
}
16651669

16661670
if scope.evaluate(BuiltinMacros.ENABLE_PROJECT_OVERRIDE_SPECS), let projectOverrideSpec = core.specRegistry.findSpecs(ProjectOverridesSpec.self, domain: "").filter({ spec in
1667-
spec.projectName == (scope.evaluate(BuiltinMacros.RC_ProjectName).nilIfEmpty ?? scope.evaluate(BuiltinMacros.SRCROOT).basename)
1671+
matchesAnyProjectIdentities(scope: scope, projectIdentities: [spec.projectName])
16681672
}).only {
16691673
push(projectOverrideSpec.buildSettings)
16701674
self.warnings.append("Applying Swift Build settings override to project for \(projectOverrideSpec.bugReport).")

Sources/SWBCore/SpecImplementations/CompilerSpec.swift

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,9 @@ protocol ProjectFailuresBlockList {
108108
}
109109

110110
extension ProjectFailuresBlockList {
111-
func isProjectListed(_ scope: MacroEvaluationScope) -> Bool {
111+
func isProjectListed(_ producer: any CommandProducer, _ scope: MacroEvaluationScope) -> Bool {
112112
// Check if this project is on the blocklist.
113-
let RC_ProjectName = scope.evaluate(BuiltinMacros.RC_ProjectName)
114-
if !RC_ProjectName.isEmpty, KnownFailures.contains(RC_ProjectName) {
115-
return true
116-
}
117-
let RC_BaseProjectName = scope.evaluate(BuiltinMacros.RC_BASE_PROJECT_NAME)
118-
if !RC_BaseProjectName.isEmpty, KnownFailures.contains(RC_BaseProjectName) {
119-
return true
120-
}
121-
let projectName = scope.evaluate(BuiltinMacros.PROJECT_NAME)
122-
return KnownFailures.contains(projectName)
113+
producer.matchesAnyProjectIdentities(scope: scope, projectIdentities: Set(KnownFailures))
123114
}
124115
}
125116

Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
904904
let buildSettingEnabled = cbc.scope.evaluate(BuiltinMacros.CLANG_ENABLE_COMPILE_CACHE)
905905

906906
// If this project is on the blocklist, override the blocklist default enable for it.
907-
return clangInfo?.isCachingBlocked(cbc.scope) == true ? false : buildSettingEnabled
907+
return clangInfo?.isCachingBlocked(cbc.producer, cbc.scope) == true ? false : buildSettingEnabled
908908
}
909909

910910
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/SpecImplementations/Tools/SwiftCompiler.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
14081408
scope.evaluate(BuiltinMacros._EXPERIMENTAL_SWIFT_EXPLICIT_MODULES) == .enabled
14091409

14101410
// If this project is on the blocklist, override the blocklist default enable for it
1411-
if let explicitModuleBlocklist = await getExplicitModuleBlocklist(producer, scope, delegate), explicitModuleBlocklist.isProjectListed(scope) {
1411+
if let explicitModuleBlocklist = await getExplicitModuleBlocklist(producer, scope, delegate), explicitModuleBlocklist.isProjectListed(producer, scope) {
14121412
return false
14131413
}
14141414

@@ -1463,7 +1463,7 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
14631463
if blocklist.Modules.contains(moduleName) {
14641464
return false
14651465
}
1466-
if blocklist.isProjectListed(cbc.scope) {
1466+
if blocklist.isProjectListed(cbc.producer, cbc.scope) {
14671467
return false
14681468
}
14691469
}

Sources/SWBCore/TaskGeneration.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,12 @@ extension PlatformBuildContext {
9797
}
9898
}
9999

100+
public protocol ProjectMatchLookup {
101+
func matchesAnyProjectIdentities(scope: MacroEvaluationScope, projectIdentities: Set<String>) -> Bool
102+
}
103+
100104
/// Protocol describing the interface producers use to communicate information to the command build context.
101-
public protocol CommandProducer: PlatformBuildContext, SpecLookupContext, ReferenceLookupContext, PlatformInfoLookup {
105+
public protocol CommandProducer: PlatformBuildContext, SpecLookupContext, ReferenceLookupContext, PlatformInfoLookup, ProjectMatchLookup {
102106
/// The configured target the command is being produced for, if any.
103107
var configuredTarget: ConfiguredTarget? { get }
104108

Sources/SWBCore/ToolInfo/ClangToolInfo.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public struct ClangBlocklists : Sendable {
3838
var builtinModuleVerify: BuiltinModuleVerifierInfo? = nil
3939

4040
/// Helper method for determining if a given functionality is blocklisted for the active scope.
41-
func isBlocked<BlockListT: ProjectFailuresBlockList>(_ scope: MacroEvaluationScope, info: BlockListT?) -> Bool {
41+
func isBlocked<BlockListT: ProjectFailuresBlockList>(_ producer: any CommandProducer, _ scope: MacroEvaluationScope, info: BlockListT?) -> Bool {
4242
guard let blocklistInfo = info else { return false }
43-
return blocklistInfo.isProjectListed(scope)
43+
return blocklistInfo.isProjectListed(producer, scope)
4444
}
4545
}
4646

@@ -98,12 +98,12 @@ public struct DiscoveredClangToolSpecInfo: DiscoveredCommandLineToolSpecInfo {
9898
Set(toolFeatures.value(.deploymentTargetEnvironmentVariables)?.stringArrayValue ?? [])
9999
}
100100

101-
public func isCachingBlocked(_ scope: MacroEvaluationScope) -> Bool {
102-
return blocklists.isBlocked(scope, info: blocklists.caching)
101+
public func isCachingBlocked(_ producer: any CommandProducer, _ scope: MacroEvaluationScope) -> Bool {
102+
return blocklists.isBlocked(producer, scope, info: blocklists.caching)
103103
}
104104

105-
public func isBuiltinModuleVerifyBlocked(_ scope: MacroEvaluationScope) -> Bool {
106-
return blocklists.isBlocked(scope, info: blocklists.builtinModuleVerify)
105+
public func isBuiltinModuleVerifyBlocked(_ producer: any CommandProducer, _ scope: MacroEvaluationScope) -> Bool {
106+
return blocklists.isBlocked(producer, scope, info: blocklists.builtinModuleVerify)
107107
}
108108
}
109109

Sources/SWBTaskConstruction/TaskProducers/OtherTaskProducers/ModuleVerifierTaskProducer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ final class ModuleVerifierTaskProducer: PhasedTaskProducer, TaskProducer {
150150
return
151151
}
152152
// Fallback to external verifier if current scope is blocklisted.
153-
if clangInfo?.isBuiltinModuleVerifyBlocked(scope) == true {
153+
if clangInfo?.isBuiltinModuleVerifyBlocked(context, scope) == true {
154154
fallbackToExternal = true
155155
return
156156
}

0 commit comments

Comments
 (0)