Skip to content

Commit 9c5fd38

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 8f0e0ae commit 9c5fd38

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +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
3029

3130
/// The Swift driver.
3231
public struct Driver {
32+
/// Stub Error for terminating the process.
33+
public enum Diagnostics: DiagnosticData {
34+
case errorsEmitted
35+
}
36+
37+
extension Diagnostics {
38+
public var description: String {
39+
switch self {
40+
case .errorsEmitted:
41+
return "errors were encountered"
42+
}
43+
}
44+
}
45+
3346
public enum Error: Swift.Error, Equatable, DiagnosticData {
3447
case unknownOrMissingSubcommand(String)
3548
case invalidDriverName(String)
@@ -1839,7 +1852,7 @@ extension Driver {
18391852
if let originalPath = swiftFiles[basename] {
18401853
diagnosticsEngine.emit(.error_two_files_same_name(basename: basename, firstPath: originalPath, secondPath: input))
18411854
diagnosticsEngine.emit(.note_explain_two_files_same_name)
1842-
throw Diagnostics.fatalError
1855+
throw Diagnostics.errorsEmitted
18431856
} else {
18441857
swiftFiles[basename] = input
18451858
}
@@ -1852,7 +1865,7 @@ extension Driver {
18521865
if let mainPath = swiftFiles["main.swift"] {
18531866
diagnosticsEngine.emit(.error_two_files_same_name(basename: "main.swift", firstPath: mainPath, secondPath: "-e"))
18541867
diagnosticsEngine.emit(.note_explain_two_files_same_name)
1855-
throw Diagnostics.fatalError
1868+
throw Diagnostics.errorsEmitted
18561869
}
18571870

18581871
try withTemporaryDirectory(dir: fileSystem.tempDirectory, removeTreeOnDeinit: false) { absPath in
@@ -2878,7 +2891,7 @@ extension Triple {
28782891
return WindowsToolchain.self
28792892
default:
28802893
diagnosticsEngine.emit(.error_unknown_target(triple))
2881-
throw Diagnostics.fatalError
2894+
throw Diagnostics.errorsEmitted
28822895
}
28832896
}
28842897
}

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 Diagnostics.errorsEmitted
478477
}
479478
assert(primaryInputs.count == 1, "Standard compile job had more than one primary input")
480479
let input = primaryInputs[0]

Sources/SwiftDriverExecution/MultiJobExecutor.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import protocol TSCBasic.DiagnosticData
2626
import protocol TSCBasic.FileSystem
2727
import struct TSCBasic.Diagnostic
2828
import struct TSCBasic.ProcessResult
29-
import enum TSCUtility.Diagnostics
3029

3130
// We either import the llbuildSwift shared library or the llbuild framework.
3231
#if canImport(llbuildSwift)
@@ -318,7 +317,7 @@ public final class MultiJobExecutor {
318317

319318
// Throw the stub error the build didn't finish successfully.
320319
if !result.success {
321-
throw Diagnostics.fatalError
320+
throw Diagnostics.errorsEmitted
322321
}
323322
}
324323

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+
exit(getExitCode(EXIT_FAILURE))
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 Diagnostics.errorsEmitted {
118+
exit(getExitCode(EXIT_FAILURE))
117119
} catch {
118120
print("error: \(error)")
119121
exit(getExitCode(EXIT_FAILURE))

0 commit comments

Comments
 (0)