Skip to content

Commit 3d380f2

Browse files
committed
Add logs around various exits
1 parent 69a7a93 commit 3d380f2

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

Sources/SwiftDriverExecution/MultiJobExecutor.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import struct TSCBasic.ProcessResult
2929
import func TSCBasic.withTemporaryDirectory
3030
import typealias TSCBasic.ProcessEnvironmentBlock
3131
import enum TSCUtility.Diagnostics
32+
import var TSCBasic.stderrStream
3233

3334
// We either import the llbuildSwift shared library or the llbuild framework.
3435
#if canImport(llbuildSwift)
@@ -579,6 +580,10 @@ class ExecuteJobRule: LLBuildRule {
579580

580581
private func executeJob(_ engine: LLTaskBuildEngine) {
581582
if context.isBuildCancelled {
583+
Driver.stdErrQueue.sync {
584+
stderrStream.send("DRIVER EXTRA VERBOSE BUILD WAS CANCELLED\n")
585+
stderrStream.flush()
586+
}
582587
engine.taskIsComplete(DriverBuildValue.jobExecution(success: false))
583588
return
584589
}
@@ -625,6 +630,12 @@ class ExecuteJobRule: LLBuildRule {
625630
let success = result.exitStatus == .terminated(code: EXIT_SUCCESS)
626631

627632
if !success {
633+
Driver.stdErrQueue.sync {
634+
let out = (try? result.utf8Output()) ?? "stdout failed"
635+
let err = (try? result.utf8stderrOutput()) ?? "stderr failed"
636+
stderrStream.send("DRIVER EXTRA VERBOSE JOB FAILED WITH NON-ZERO \(result.exitStatus) \(job) WITH STDOUT '\(out)' AND STDERR '\(err)'\n")
637+
stderrStream.flush()
638+
}
628639
job.removeOutputsOfFailedCompilation(from: context.fileSystem)
629640
switch result.exitStatus {
630641
case let .terminated(code):
@@ -672,6 +683,10 @@ class ExecuteJobRule: LLBuildRule {
672683
context.executorDelegate.jobFinished(job: job, result: result, pid: pid)
673684
}
674685
}
686+
Driver.stdErrQueue.sync {
687+
stderrStream.send("DRIVER EXTRA VERBOSE CAUGHT ERROR IN JOB EXECUTION \(error)\n")
688+
stderrStream.flush()
689+
}
675690
value = .jobExecution(success: false)
676691
}
677692

Sources/swift-driver/main.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,30 +155,49 @@ do {
155155
// FIXME: The following check should be at the end of Driver.init, but current
156156
// usage of the DiagnosticVerifier in tests makes this difficult.
157157
guard !driver.diagnosticEngine.hasErrors else {
158+
printToStderr("DRIVER EXTRA VERBOSE HAD ERRORS")
158159
throw Driver.ErrorDiagnostics.emitted
159160
}
160161

162+
printToStderr("DRIVER EXTRA VERBOSE STARTING PLANNING")
161163
let jobs = try driver.planBuild()
164+
printToStderr("DRIVER EXTRA VERBOSE FINISHED PLANNING")
162165

163166
// Planning may result in further errors emitted
164167
// due to dependency scanning failures.
165168
guard !driver.diagnosticEngine.hasErrors else {
169+
printToStderr("DRIVER EXTRA VERBOSE HAD ERRORS")
166170
throw Driver.ErrorDiagnostics.emitted
167171
}
168172

173+
printToStderr("DRIVER EXTRA VERBOSE RUNNING JOBS")
169174
try driver.run(jobs: jobs)
175+
printToStderr("DRIVER EXTRA VERBOSE FINISHED JOBS")
170176

171177
if driver.diagnosticEngine.hasErrors {
178+
printToStderr("DRIVER EXTRA VERBOSE HAD ERRORS")
172179
exit(getExitCode(EXIT_FAILURE))
173180
}
174181

182+
printToStderr("DRIVER EXTRA VERBOSE SUCCESS")
175183
exit(getExitCode(0))
176184
} catch let diagnosticData as DiagnosticData {
185+
printToStderr("DRIVER EXTRA VERBOSE IN CATCH FOR DIAGNOSTIC EMISSION")
177186
diagnosticsEngine.emit(.error(diagnosticData))
178187
exit(getExitCode(EXIT_FAILURE))
179188
} catch Driver.ErrorDiagnostics.emitted {
189+
printToStderr("DRIVER EXTRA VERBOSE IN CATCH FOR ALREADY EMITTED DIAGNOSTICS")
180190
exit(getExitCode(EXIT_FAILURE))
181191
} catch {
182-
print("error: \(error)")
192+
printToStderr("DRIVER EXTRA VERBOSE IN CATCH FOR OTHER ERROR")
193+
printToStderr("error: \(error)")
183194
exit(getExitCode(EXIT_FAILURE))
184195
}
196+
197+
import var TSCBasic.stderrStream
198+
func printToStderr(_ message: String) {
199+
Driver.stdErrQueue.sync {
200+
stderrStream.send(message + "\n")
201+
stderrStream.flush()
202+
}
203+
}

0 commit comments

Comments
 (0)