Skip to content

Commit 2c37f31

Browse files
committed
Remove last trace of TSCUtility
Replace use of `Diagnostic.fatalError` with a `SwiftDriver.Diagnostics.errorsEmitted` type which removes the final reference to `TSCUtility` in the actual shipping code. References within the test suite may remain for now.
1 parent ab0ca9b commit 2c37f31

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,23 @@ import struct TSCBasic.RelativePath
2626
import var TSCBasic.localFileSystem
2727
import var TSCBasic.stderrStream
2828
import var TSCBasic.stdoutStream
29-
import enum TSCUtility.Diagnostics
29+
30+
extension Driver {
31+
/// Stub Error for terminating the process.
32+
public enum ErrorDiagnostics: Swift.Error {
33+
case emitted
34+
}
35+
}
36+
37+
extension Driver.ErrorDiagnostics: CustomStringConvertible {
38+
public var description: String {
39+
switch self {
40+
case .emitted:
41+
return "errors were encountered"
42+
}
43+
}
44+
}
45+
3046

3147
/// The Swift driver.
3248
public struct Driver {
@@ -1839,7 +1855,7 @@ extension Driver {
18391855
if let originalPath = swiftFiles[basename] {
18401856
diagnosticsEngine.emit(.error_two_files_same_name(basename: basename, firstPath: originalPath, secondPath: input))
18411857
diagnosticsEngine.emit(.note_explain_two_files_same_name)
1842-
throw Diagnostics.fatalError
1858+
throw ErrorDiagnostics.emitted
18431859
} else {
18441860
swiftFiles[basename] = input
18451861
}
@@ -1852,7 +1868,7 @@ extension Driver {
18521868
if let mainPath = swiftFiles["main.swift"] {
18531869
diagnosticsEngine.emit(.error_two_files_same_name(basename: "main.swift", firstPath: mainPath, secondPath: "-e"))
18541870
diagnosticsEngine.emit(.note_explain_two_files_same_name)
1855-
throw Diagnostics.fatalError
1871+
throw ErrorDiagnostics.emitted
18561872
}
18571873

18581874
try withTemporaryDirectory(dir: fileSystem.tempDirectory, removeTreeOnDeinit: false) { absPath in
@@ -2878,7 +2894,7 @@ extension Triple {
28782894
return WindowsToolchain.self
28792895
default:
28802896
diagnosticsEngine.emit(.error_unknown_target(triple))
2881-
throw Diagnostics.fatalError
2897+
throw Driver.ErrorDiagnostics.emitted
28822898
}
28832899
}
28842900
}

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import class TSCBasic.LocalFileOutputByteStream
1414
import class TSCBasic.TerminalController
1515
import struct TSCBasic.RelativePath
1616
import var TSCBasic.stderrStream
17-
import enum TSCUtility.Diagnostics
1817

1918
/// Whether we should produce color diagnostics by default.
2019
fileprivate func shouldColorDiagnostics() -> Bool {
@@ -474,7 +473,7 @@ extension Driver {
474473
if parsedOptions.hasArgument(.updateCode) {
475474
guard compilerMode == .standardCompile else {
476475
diagnosticEngine.emit(.error_update_code_not_supported(in: compilerMode))
477-
throw Diagnostics.fatalError
476+
throw ErrorDiagnostics.emitted
478477
}
479478
assert(primaryInputs.count == 1, "Standard compile job had more than one primary input")
480479
let input = primaryInputs[0]

Sources/swift-driver/main.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import class TSCBasic.Process
3232
import class TSCBasic.ProcessSet
3333
import protocol TSCBasic.DiagnosticData
3434
import var TSCBasic.localFileSystem
35-
import enum TSCUtility.Diagnostics
3635

3736
let interruptSignalSource = DispatchSource.makeSignalSource(signal: SIGINT)
3837
let diagnosticsEngine = DiagnosticsEngine(handlers: [Driver.stderrDiagnosticsHandler])
@@ -100,20 +99,23 @@ do {
10099

101100
// FIXME: The following check should be at the end of Driver.init, but current
102101
// usage of the DiagnosticVerifier in tests makes this difficult.
103-
guard !driver.diagnosticEngine.hasErrors else { throw Diagnostics.fatalError }
102+
guard !driver.diagnosticEngine.hasErrors else {
103+
throw Driver.ErrorDiagnostics.emitted
104+
}
104105

105106
let jobs = try driver.planBuild()
106107
try driver.run(jobs: jobs)
107108

108109
if driver.diagnosticEngine.hasErrors {
109110
exit(getExitCode(EXIT_FAILURE))
110111
}
112+
111113
exit(getExitCode(0))
112-
} catch Diagnostics.fatalError {
113-
exit(getExitCode(EXIT_FAILURE))
114114
} catch let diagnosticData as DiagnosticData {
115115
diagnosticsEngine.emit(.error(diagnosticData))
116116
exit(getExitCode(EXIT_FAILURE))
117+
} catch Driver.ErrorDiagnostics.emitted {
118+
exit(getExitCode(EXIT_FAILURE))
117119
} catch {
118120
print("error: \(error)")
119121
exit(getExitCode(EXIT_FAILURE))

0 commit comments

Comments
 (0)