Skip to content

Basics: clean up DiagnosticsEngine in Observability #6333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions Sources/Basics/Observability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@

import Dispatch
import Foundation
import TSCBasic

import class TSCBasic.UnknownLocation
import enum TSCUtility.Diagnostics
import protocol TSCBasic.DiagnosticData
import protocol TSCBasic.DiagnosticLocation
import protocol TSCUtility.DiagnosticDataConvertible
import struct TSCBasic.Diagnostic

// this could become a struct when we remove the "errorsReported" pattern

Expand Down Expand Up @@ -527,14 +530,13 @@ extension ObservabilityMetadata {

// MARK: - Compatibility with TSC Diagnostics APIs

@available(*, deprecated, message: "temporary for transition DiagnosticsEngine -> DiagnosticsEmitter")
extension ObservabilityScope {
public func makeDiagnosticsEngine() -> DiagnosticsEngine {
return .init(handlers: [{ Diagnostic($0).map{ self.diagnosticsHandler.handleDiagnostic(scope: self, diagnostic: $0) } }])
public func makeDiagnosticsHandler() -> (TSCBasic.Diagnostic) -> Void {
{ Diagnostic($0).map { self.diagnosticsHandler.handleDiagnostic(scope: self, diagnostic: $0) } }
}
}

@available(*, deprecated, message: "temporary for transition DiagnosticsEngine -> DiagnosticsEmitter")
@available(*, deprecated, message: "temporary for transition TSCBasic.Diagnostic -> SwiftDriver.Diagnostic")
extension Diagnostic {
init?(_ diagnostic: TSCBasic.Diagnostic) {
var metadata = ObservabilityMetadata()
Expand All @@ -558,7 +560,7 @@ extension Diagnostic {
}
}

@available(*, deprecated, message: "temporary for transition DiagnosticsEngine -> DiagnosticsEmitter")
@available(*, deprecated, message: "temporary for transition TSCBasic.Diagnostic -> SwiftDriver.Diagnostic")
extension ObservabilityMetadata {
public var legacyDiagnosticLocation: DiagnosticLocationWrapper? {
get {
Expand Down Expand Up @@ -586,7 +588,7 @@ extension ObservabilityMetadata {
}
}

@available(*, deprecated, message: "temporary for transition DiagnosticsEngine -> DiagnosticsEmitter")
@available(*, deprecated, message: "temporary for transition TSCBasic.Diagnostic -> SwiftDriver.Diagnostic")
extension ObservabilityMetadata {
var legacyDiagnosticData: DiagnosticDataWrapper? {
get {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Build/BuildOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS

let consumeDiagnostics: DiagnosticsEngine = DiagnosticsEngine(handlers: [])
var driver = try Driver(args: commandLine,
diagnosticsEngine: consumeDiagnostics,
diagnosticsOutput: .engine(consumeDiagnostics),
fileSystem: localFileSystem,
executor: executor)
guard !consumeDiagnostics.hasErrors else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Build/LLBuildManifestBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ extension LLBuildManifestBuilder {
)
var driver = try Driver(
args: commandLine,
diagnosticsEngine: self.observabilityScope.makeDiagnosticsEngine(),
diagnosticsOutput: .handler(self.observabilityScope.makeDiagnosticsHandler()),
fileSystem: self.fileSystem,
executor: executor
)
Expand Down
8 changes: 0 additions & 8 deletions Sources/Workspace/Workspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3525,14 +3525,6 @@ fileprivate extension PackageDependency {
}
}

fileprivate extension DiagnosticsEngine {
func append(contentsOf other: DiagnosticsEngine) {
for diagnostic in other.diagnostics {
self.emit(diagnostic.message, location: diagnostic.location)
}
}
}

internal extension PackageReference {
func makeRepositorySpecifier() throws -> RepositorySpecifier {
switch self.kind {
Expand Down