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
|
//===----------------------------------------------------------------------===//
//
// 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 SWBCore
package import SWBUtil
package import Testing
/// An empty delegate implementation.
package final class EmptyTargetDependencyResolverDelegate: TargetDependencyResolverDelegate, Sendable {
package let diagnosticContext: DiagnosticContextData
package let workspace: Workspace
private let diagnosticsEngines = LockedValue<[ConfiguredTarget?: DiagnosticsEngine]>(.init())
package init(workspace: Workspace) {
self.workspace = workspace
self.diagnosticContext = DiagnosticContextData(target: nil)
}
package func diagnosticsEngine(for target: ConfiguredTarget?) -> DiagnosticProducingDelegateProtocolPrivate<DiagnosticsEngine> {
return .init(diagnosticsEngines.withLock { $0.getOrInsert(target, { DiagnosticsEngine() }) })
}
package var diagnostics: [ConfiguredTarget?: [Diagnostic]] {
diagnosticsEngines.withLock { $0.mapValues { $0.diagnostics } }
}
package func emit(_ diagnostic: Diagnostic) {
diagnosticsEngine(for: nil).emit(diagnostic)
}
package func updateProgress(statusMessage: String, showInLog: Bool) { }
}
extension EmptyTargetDependencyResolverDelegate {
package func checkNoDiagnostics(sourceLocation: SourceLocation = #_sourceLocation) {
checkDiagnostics([], sourceLocation: sourceLocation)
}
package func checkDiagnostics(
format: Diagnostic.LocalizedDescriptionFormat = .debugWithoutBehavior,
_ diagnostics: [String],
sourceLocation: SourceLocation = #_sourceLocation
) {
#expect(self.diagnostics.formatLocalizedDescription(format, workspace: workspace, filter: { _ in true }).sorted() == diagnostics.sorted(), sourceLocation: sourceLocation)
}
}
extension TargetBuildGraph {
/// Convenience initializer which uses an empty delegate implementation for testing.
package init(workspaceContext: WorkspaceContext, buildRequest: BuildRequest, buildRequestContext: BuildRequestContext) async {
await self.init(workspaceContext: workspaceContext, buildRequest: buildRequest, buildRequestContext: buildRequestContext, delegate: EmptyTargetDependencyResolverDelegate(workspace: workspaceContext.workspace))
}
}
package struct TargetGraphFactory: Sendable {
let workspaceContext: WorkspaceContext
let buildRequest: BuildRequest
let buildRequestContext: BuildRequestContext
let delegate: EmptyTargetDependencyResolverDelegate
package init(workspaceContext: WorkspaceContext, buildRequest: BuildRequest, buildRequestContext: BuildRequestContext, delegate: EmptyTargetDependencyResolverDelegate) {
self.workspaceContext = workspaceContext
self.buildRequest = buildRequest
self.buildRequestContext = buildRequestContext
self.delegate = delegate
}
package enum GraphType: CaseIterable, Sendable {
case dependency
case linkage
}
package func graph(type: GraphType) async -> any TargetGraph {
switch type {
case .dependency:
return await TargetBuildGraph(workspaceContext: workspaceContext, buildRequest: buildRequest, buildRequestContext: buildRequestContext, delegate: delegate)
case .linkage:
return await TargetLinkageGraph(workspaceContext: workspaceContext, buildRequest: buildRequest, buildRequestContext: buildRequestContext, delegate: delegate)
}
}
}
|