-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathPlugin.swift
256 lines (224 loc) · 10.7 KB
/
Plugin.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
public import SWBUtil
import SWBCore
import SWBMacro
import SWBProtocol
import Foundation
import SWBTaskConstruction
@PluginExtensionSystemActor public func initializePlugin(_ manager: PluginManager) {
manager.register(AppleDeveloperDirectoryExtension(), type: DeveloperDirectoryExtensionPoint.self)
manager.register(ApplePlatformSpecsExtension(), type: SpecificationsExtensionPoint.self)
manager.register(ActoolInputFileGroupingStrategyExtension(), type: InputFileGroupingStrategyExtensionPoint.self)
manager.register(ImageScaleFactorsInputFileGroupingStrategyExtension(), type: InputFileGroupingStrategyExtensionPoint.self)
manager.register(LocalizationInputFileGroupingStrategyExtension(), type: InputFileGroupingStrategyExtensionPoint.self)
manager.register(XCStringsInputFileGroupingStrategyExtension(), type: InputFileGroupingStrategyExtensionPoint.self)
manager.register(TaskProducersExtension(), type: TaskProducerExtensionPoint.self)
manager.register(MacCatalystInfoExtension(), type: SDKVariantInfoExtensionPoint.self)
manager.register(ApplePlatformInfoExtension(), type: PlatformInfoExtensionPoint.self)
manager.register(AppleSettingsBuilderExtension(), type: SettingsBuilderExtensionPoint.self)
}
struct AppleDeveloperDirectoryExtension: DeveloperDirectoryExtension {
func fallbackDeveloperDirectory(hostOperatingSystem: OperatingSystem) async throws -> Path? {
try await hostOperatingSystem == .macOS ? Xcode.getActiveDeveloperDirectoryPath() : nil
}
}
struct TaskProducersExtension: TaskProducerExtension {
func createPreSetupTaskProducers(_ context: TaskProducerContext) -> [any TaskProducer] {
[DevelopmentAssetsTaskProducer(context)]
}
var setupTaskProducers: [any TaskProducerFactory] {
[RealityAssetsTaskProducerFactory()]
}
var unorderedPostSetupTaskProducers: [any TaskProducerFactory] {
[
StubBinaryTaskProducerFactory()
]
}
var unorderedPostBuildPhasesTaskProducers: [any TaskProducerFactory] {
[
AppIntentsMetadataTaskProducerFactory()
]
}
var globalTaskProducers: [any GlobalTaskProducerFactory] {
[StubBinaryTaskProducerFactory()]
}
}
struct StubBinaryTaskProducerFactory: TaskProducerFactory, GlobalTaskProducerFactory {
var name: String {
"StubBinaryTaskProducer"
}
func createTaskProducer(_ context: TargetTaskProducerContext, startPhaseNodes: [PlannedVirtualNode], endPhaseNode: PlannedVirtualNode) -> any TaskProducer {
StubBinaryTaskProducer(context, phaseStartNodes: startPhaseNodes, phaseEndNode: endPhaseNode)
}
func createGlobalTaskProducer(_ globalContext: TaskProducerContext, targetContexts: [TaskProducerContext]) -> any TaskProducer {
GlobalStubBinaryTaskProducer(context: globalContext, targetContexts: targetContexts)
}
}
struct AppIntentsMetadataTaskProducerFactory : TaskProducerFactory {
var name: String {
"AppIntentsMetadataTaskProducer"
}
func createTaskProducer(_ context: TargetTaskProducerContext, startPhaseNodes: [PlannedVirtualNode], endPhaseNode: PlannedVirtualNode) -> any TaskProducer {
AppIntentsMetadataTaskProducer(context, phaseStartNodes: startPhaseNodes, phaseEndNode: endPhaseNode)
}
}
struct RealityAssetsTaskProducerFactory: TaskProducerFactory {
var name: String {
"RealityAssetsTaskProducer"
}
func createTaskProducer(_ context: TargetTaskProducerContext, startPhaseNodes: [PlannedVirtualNode], endPhaseNode: PlannedVirtualNode) -> any TaskProducer {
RealityAssetsTaskProducer(context, phaseStartNodes: startPhaseNodes, phaseEndNode: endPhaseNode)
}
}
struct ApplePlatformSpecsExtension: SpecificationsExtension {
func specificationClasses() -> [any SpecIdentifierType.Type] {
[
ActoolCompilerSpec.self,
AppIntentsMetadataCompilerSpec.self,
AppIntentsSSUTrainingCompilerSpec.self,
CoreDataModelCompilerSpec.self,
CoreMLCompilerSpec.self,
CopyTiffFileSpec.self,
CopyXCAppExtensionPointsFileSpec.self,
DittoToolSpec.self,
IBStoryboardLinkerCompilerSpec.self,
IIGCompilerSpec.self,
IbtoolCompilerSpecNIB.self,
IbtoolCompilerSpecStoryboard.self,
InstrumentsPackageBuilderSpec.self,
IntentsCompilerSpec.self,
MetalCompilerSpec.self,
MetalLinkerSpec.self,
MigCompilerSpec.self,
OpenCLCompilerSpec.self,
RealityAssetsCompilerSpec.self,
ReferenceObjectCompilerSpec.self,
ResMergerLinkerSpec.self,
SceneKitToolSpec.self,
XCStringsCompilerSpec.self,
]
}
func specificationFiles(resourceSearchPaths: [Path]) -> Bundle? {
findResourceBundle(nameWhenInstalledInToolchain: "SwiftBuild_SWBApplePlatform", resourceSearchPaths: resourceSearchPaths, defaultBundle: Bundle.module)
}
func specificationDomains() -> [String : [String]] {
var mappings = [
"macosx": ["darwin"],
"driverkit": ["darwin"],
"embedded-shared": ["darwin"],
"embedded": ["embedded-shared"],
"embedded-simulator": ["embedded-shared"],
]
for platform in ["iphone", "appletv", "watch", "xr"] {
mappings["\(platform)os"] = ["\(platform)os-shared", "embedded"]
mappings["\(platform)simulator"] = ["\(platform)os-shared", "embedded-simulator"]
}
return mappings
}
}
struct ActoolInputFileGroupingStrategyExtension: InputFileGroupingStrategyExtension {
func groupingStrategies() -> [String: any InputFileGroupingStrategyFactory] {
struct Factory: InputFileGroupingStrategyFactory {
func makeStrategy(specIdentifier: String) -> any InputFileGroupingStrategy {
ActoolInputFileGroupingStrategy(groupIdentifier: specIdentifier)
}
}
return ["actool": Factory()]
}
func fileTypesCompilingToSwiftSources() -> [String] {
return ["folder.abstractassetcatalog"]
}
}
struct ImageScaleFactorsInputFileGroupingStrategyExtension: InputFileGroupingStrategyExtension {
func groupingStrategies() -> [String: any InputFileGroupingStrategyFactory] {
struct Factory: InputFileGroupingStrategyFactory {
func makeStrategy(specIdentifier: String) -> any InputFileGroupingStrategy {
ImageScaleFactorsInputFileGroupingStrategy(toolName: specIdentifier)
}
}
return ["image-scale-factors": Factory()]
}
func fileTypesCompilingToSwiftSources() -> [String] {
return []
}
}
struct LocalizationInputFileGroupingStrategyExtension: InputFileGroupingStrategyExtension {
func groupingStrategies() -> [String: any InputFileGroupingStrategyFactory] {
struct Factory: InputFileGroupingStrategyFactory {
func makeStrategy(specIdentifier: String) -> any InputFileGroupingStrategy {
LocalizationInputFileGroupingStrategy(toolName: specIdentifier)
}
}
return ["region": Factory()]
}
func fileTypesCompilingToSwiftSources() -> [String] {
return []
}
}
struct XCStringsInputFileGroupingStrategyExtension: InputFileGroupingStrategyExtension {
func groupingStrategies() -> [String: any InputFileGroupingStrategyFactory] {
struct Factory: InputFileGroupingStrategyFactory {
func makeStrategy(specIdentifier: String) -> any InputFileGroupingStrategy {
XCStringsInputFileGroupingStrategy(toolName: specIdentifier)
}
}
return ["xcstrings": Factory()]
}
func fileTypesCompilingToSwiftSources() -> [String] {
return []
}
}
struct ApplePlatformInfoExtension: PlatformInfoExtension {
func knownDeploymentTargetMacroNames() -> Set<String> {
[
"MACOSX_DEPLOYMENT_TARGET",
"IPHONEOS_DEPLOYMENT_TARGET",
"TVOS_DEPLOYMENT_TARGET",
"WATCHOS_DEPLOYMENT_TARGET",
"DRIVERKIT_DEPLOYMENT_TARGET",
"XROS_DEPLOYMENT_TARGET",
]
}
func preferredArchValue(for platformName: String) -> String? {
// FIXME: rdar://65011964 (Remove PLATFORM_PREFERRED_ARCH)
// Don't add values for any new platforms
switch platformName {
case "macosx", "iphonesimulator", "appletvsimulator", "watchsimulator":
return "x86_64"
case "iphoneos", "appletvos", "watchos":
return "arm64"
default:
return nil
}
}
}
struct AppleSettingsBuilderExtension: SettingsBuilderExtension {
func addSDKSettings(_ sdk: SDK, _ variant: SDKVariant?, _ sparseSDKs: [SDK]) throws -> [String : String] {
guard variant?.llvmTargetTripleVendor == "apple" else {
return [:]
}
return [
"PER_ARCH_MODULE_FILE_DIR": "$(PER_ARCH_OBJECT_FILE_DIR)",
]
}
func addBuiltinDefaults(fromEnvironment environment: [String : String], parameters: BuildParameters) throws -> [String : String] { [:] }
func addOverrides(fromEnvironment: [String : String], parameters: BuildParameters) throws -> [String : String] { [:] }
func addProductTypeDefaults(productType: ProductTypeSpec) -> [String : String] { [:] }
func addSDKOverridingSettings(_ sdk: SDK, _ variant: SDKVariant?, _ sparseSDKs: [SDK], specLookupContext: any SWBCore.SpecLookupContext) throws -> [String : String] { [:] }
func addPlatformSDKSettings(_ platform: SWBCore.Platform?, _ sdk: SDK, _ sdkVariant: SDKVariant?) -> [String : String] { [:] }
func xcconfigOverrideData(fromParameters: BuildParameters) -> ByteString { ByteString() }
func getTargetTestingSwiftPluginFlags(_ scope: MacroEvaluationScope, toolchainRegistry: ToolchainRegistry, sdkRegistry: SDKRegistry, activeRunDestination: RunDestinationInfo?, project: SWBCore.Project?) -> [String] { [] }
func shouldSkipPopulatingValidArchs(platform: SWBCore.Platform) -> Bool { false }
func shouldDisableXOJITPreviews(platformName: String, sdk: SDK?) -> Bool { false }
func overridingBuildSettings(_: MacroEvaluationScope, platform: SWBCore.Platform?, productType: ProductTypeSpec) -> [String : String] { [:] }
}