-
Notifications
You must be signed in to change notification settings - Fork 187
Expand file tree
/
Copy pathDummyCommandProducer.swift
More file actions
295 lines (256 loc) · 12.4 KB
/
Copy pathDummyCommandProducer.swift
File metadata and controls
295 lines (256 loc) · 12.4 KB
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
package import Foundation
@_spi(Testing) package import SWBCore
package import SWBUtil
package import SWBMacro
package struct MockCommandProducer: CommandProducer, Sendable {
let core: Core
package let platform: Platform?
package let sdk: SDK?
package let sdkVariant: SDKVariant?
package var project: SWBCore.Project? {
return nil
}
package var specRegistry: SpecRegistry {
return core.specRegistry
}
package let productType: ProductTypeSpec?
package let executableSearchPaths: StackedSearchPath
package let toolchains: [Toolchain]
package let discoveredCommandLineToolSpecInfoCache = DiscoveredCommandLineToolSpecInfoCache(processExecutionCache: ProcessExecutionCache())
package var userPreferences: UserPreferences {
UserPreferences.defaultForTesting
}
package var hostOperatingSystem: OperatingSystem {
core.hostOperatingSystem
}
package init(core: Core, productTypeIdentifier: String, platform platformName: String?, useStandardExecutableSearchPaths: Bool = false, toolchain: Toolchain? = nil, fs: any FSProxy = localFS) throws {
self.core = core
let platform = platformName.map(core.platformRegistry.lookup(name:)) ?? nil
self.platform = platform
self.sdk = (platform?.sdkCanonicalName).map(core.sdkRegistry.lookup) ?? nil
self.sdkVariant = self.sdk?.defaultVariant
self.productType = try core.specRegistry.getSpec(productTypeIdentifier, domain: platform?.name ?? "", ofType: ProductTypeSpec.self)
// Construct some executable search paths if instructed, by mimicking part of what Settings.createExecutableSearchPaths() does, specifically:
// - Add from __XCODE_BUILT_PRODUCTS_DIR_PATHS, if present.
// - Add the binary paths for the default toolchain.
// - Add the platform search paths.
// - Add the standard search paths.
// But we don't add the entries from __XCODE_BUILT_PRODUCTS_DIR_PATHS or from PATH, to ensure a consistent test experience.
// The filesystem in which to search is always the local file system.
var paths = OrderedSet<Path>()
if useStandardExecutableSearchPaths {
for path in core.toolchainRegistry.defaultToolchain?.executableSearchPaths.paths ?? [] {
paths.append(path)
}
for path in platform?.executableSearchPaths.paths ?? [] {
paths.append(path)
}
switch core.developerPath {
case .xcode(let path):
paths.append(path.join("usr").join("bin"))
paths.append(path.join("usr").join("local").join("bin"))
case .swiftToolchain(let path, xcodeDeveloperPath: let xcodeDeveloperPath):
if core.hostOperatingSystem != .windows {
paths.append(path.join("usr").join("bin"))
paths.append(path.join("usr").join("local").join("bin"))
}
if let xcodeDeveloperPath {
paths.append(xcodeDeveloperPath.join("usr").join("bin"))
paths.append(xcodeDeveloperPath.join("usr").join("local").join("bin"))
}
}
switch core.hostOperatingSystem {
case .macOS:
paths.append(contentsOf: [
.root.join("usr").join("bin"),
.root.join("bin"),
.root.join("usr").join("sbin"),
.root.join("sbin"),
])
case .linux:
paths.append(contentsOf: [
.root.join("usr").join("sbin"),
.root.join("usr").join("bin"),
.root.join("sbin"),
.root.join("bin"),
])
case .freebsd:
paths.append(contentsOf: [
.root.join("sbin"),
.root.join("bin"),
.root.join("usr").join("sbin"),
.root.join("usr").join("bin"),
])
case .openbsd:
paths.append(contentsOf: [
.root.join("bin"),
.root.join("sbin"),
.root.join("usr").join("bin"),
.root.join("usr").join("sbin"),
])
case .android:
paths.append(.root.join("system").join("bin"))
case .iOS, .tvOS, .watchOS, .visionOS, .windows, .unknown:
break
}
}
self.executableSearchPaths = StackedSearchPath(paths: [Path](paths), fs: fs)
self.toolchains = toolchain.map { [$0] } ?? []
// Work around compiler (can't use self.getSpec before self initialization)
func getSpec<T: Spec>(_ identifier: String, ofType type: T.Type) throws -> T {
try core.specRegistry.getSpec(identifier, domain: platform?.name ?? "", ofType: type)
}
func getSpec<T: Spec & IdentifiedSpecType>(ofType type: T.Type) throws -> T {
try getSpec(T.identifier, ofType: type)
}
self.clangSpec = try getSpec(ofType: ClangCompilerSpec.self)
self.clangAssemblerSpec = try getSpec(ofType: ClangAssemblerSpec.self)
self.clangPreprocessorSpec = try getSpec(ofType: ClangPreprocessorSpec.self)
self.clangStaticAnalyzerSpec = try getSpec(ofType: ClangStaticAnalyzerSpec.self)
self.entityLinkerToolSpec = try getSpec("com.apple.build-tools.clang-ssaf-linker", ofType: CommandLineToolSpec.self)
self.ssafAnalyzerToolSpec = try getSpec("com.apple.build-tools.clang-ssaf-analyzer", ofType: CommandLineToolSpec.self)
self.clangModuleVerifierSpec = try getSpec(ofType: ClangModuleVerifierSpec.self)
self.diffSpec = try getSpec("com.apple.build-tools.diff", ofType: CommandLineToolSpec.self)
self.stripSpec = try getSpec("com.apple.build-tools.strip", ofType: StripToolSpec.self)
self.ldLinkerSpec = try getSpec(ofType: LdLinkerSpec.self)
self.libtoolLinkerSpec = try getSpec(ofType: LibtoolLinkerSpec.self)
self.lipoSpec = try getSpec(ofType: LipoToolSpec.self)
self.codesignSpec = try getSpec("com.apple.build-tools.codesign", ofType: CodesignToolSpec.self)
self.copySpec = try getSpec(ofType: CopyToolSpec.self)
self.copyPngSpec = try? getSpec("com.apple.build-tasks.copy-png-file", ofType: CommandLineToolSpec.self)
self.copyTiffSpec = try? getSpec("com.apple.build-tasks.copy-tiff-file", ofType: CommandLineToolSpec.self)
self.writeFileSpec = try getSpec("com.apple.build-tools.write-file", ofType: WriteFileSpec.self)
self.createBuildDirectorySpec = try getSpec("com.apple.tools.create-build-directory", ofType: CreateBuildDirectorySpec.self)
self.unifdefSpec = try getSpec("public.build-task.unifdef", ofType: UnifdefToolSpec.self)
self.mkdirSpec = try getSpec("com.apple.tools.mkdir", ofType: MkdirToolSpec.self)
self.swiftCompilerSpec = try getSpec(ofType: SwiftCompilerSpec.self)
self.processSDKImportsSpec = try getSpec(ProcessSDKImportsSpec.identifier, ofType: ProcessSDKImportsSpec.self)
}
package let specDataCaches = Registry<Spec, any SpecDataCache>()
package var configuredTarget: ConfiguredTarget? {
return nil
}
package var preferredArch: String? {
return nil
}
package var sparseSDKs: [SDK] {
return []
}
package let clangSpec: ClangCompilerSpec
package let clangAssemblerSpec: ClangCompilerSpec
package let clangPreprocessorSpec: ClangCompilerSpec
package let clangStaticAnalyzerSpec: ClangCompilerSpec
package let entityLinkerToolSpec: CommandLineToolSpec
package let ssafAnalyzerToolSpec: CommandLineToolSpec
package let clangModuleVerifierSpec: ClangCompilerSpec
package let diffSpec: CommandLineToolSpec
package let stripSpec: StripToolSpec
package let ldLinkerSpec: LdLinkerSpec
package let libtoolLinkerSpec: LibtoolLinkerSpec
package let lipoSpec: LipoToolSpec
package let codesignSpec: CodesignToolSpec
package let copySpec: CopyToolSpec
package let copyPngSpec: CommandLineToolSpec?
package let copyTiffSpec: CommandLineToolSpec?
package let writeFileSpec: WriteFileSpec
package let createBuildDirectorySpec: CreateBuildDirectorySpec
package let unifdefSpec: UnifdefToolSpec
package let mkdirSpec: MkdirToolSpec
package let swiftCompilerSpec: SwiftCompilerSpec
package let processSDKImportsSpec: ProcessSDKImportsSpec
package var defaultWorkingDirectory: Path {
return Path("/tmp")
}
package var moduleInfo: ModuleInfo? {
return nil
}
package var needsVFS: Bool {
return true
}
package var generateAssemblyCommands: Bool {
return false
}
package var generatePreprocessCommands: Bool {
return false
}
package var filePathResolver: FilePathResolver {
fatalError("tests should never access CommandProducer.filePathResolver")
}
package func lookupReference(for guid: String) -> Reference? {
fatalError("unexpected API use")
}
package var signingSettings: Settings.SigningSettings? {
return nil
}
package var xcodeProductBuildVersion: ProductBuildVersion? {
return nil
}
package func expandedSearchPaths(for items: [String], scope: MacroEvaluationScope) -> [String] {
return items
}
package func onDemandResourcesAssetPack(for tags: ODRTagSet) -> ODRAssetPackInfo? {
return nil
}
package func targetSwiftDependencyScopes(for target: ConfiguredTarget, arch: String, variant: String) -> [MacroEvaluationScope] {
return []
}
package var swiftMacroImplementationDescriptors: Set<SWBCore.SwiftMacroImplementationDescriptor>? {
nil
}
package func supportsEagerLinking(scope: MacroEvaluationScope) -> Bool {
false
}
package func projectHeaderInfo(for target: Target) -> ProjectHeaderInfo? {
return nil
}
public var projectLocation: Diagnostic.Location {
return .unknown
}
package func discoveredCommandLineToolSpecInfo(_ delegate: any SWBCore.CoreClientTargetDiagnosticProducingDelegate, _ toolName: String, _ path: Path, _ process: @Sendable (Data) async throws -> any SWBCore.DiscoveredCommandLineToolSpecInfo) async throws -> any SWBCore.DiscoveredCommandLineToolSpecInfo {
try await discoveredCommandLineToolSpecInfoCache.run(delegate, toolName, path, process)
}
package func discoveredCommandLineToolSpecInfo(_ delegate: any SWBCore.CoreClientTargetDiagnosticProducingDelegate, _ toolName: String?, _ commandLine: [String], _ process: @Sendable (Processes.ExecutionResult) async throws -> any SWBCore.DiscoveredCommandLineToolSpecInfo) async throws -> any SWBCore.DiscoveredCommandLineToolSpecInfo {
try await discoveredCommandLineToolSpecInfoCache.run(delegate, toolName, commandLine, process)
}
package func shouldUseSDKStatCache() async -> Bool {
false
}
package var canConstructAppIntentsMetadataTask: Bool {
return false
}
package var canConstructAppIntentsSSUTask: Bool {
return false
}
package var targetRequiredToBuildForIndexing: Bool {
return false
}
package var targetShouldBuildModuleForInstallAPI: Bool {
false
}
package var systemInfo: SystemInfo? {
return nil
}
package func lookupLibclang(path: SWBUtil.Path) -> (libclang: SWBCore.Libclang?, version: Version?) {
(nil, nil)
}
package func lookupPlatformNames(platform: SWBUtil.BuildVersion.Platform) -> Set<String> {
core.lookupPlatformNames(platform: platform)
}
package func lookupPlatformInfo(platform: SWBUtil.BuildVersion.Platform) -> (any PlatformInfoProvider)? {
core.lookupPlatformInfo(platform: platform)
}
package func matchesAnyProjectIdentities(scope: SWBMacro.MacroEvaluationScope, projectIdentities: Set<String>) -> Bool {
false
}
}