Skip to content
Draft
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
15 changes: 15 additions & 0 deletions Sources/SwiftDriverExecution/MultiJobExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import struct TSCBasic.ProcessResult
import func TSCBasic.withTemporaryDirectory
import typealias TSCBasic.ProcessEnvironmentBlock
import enum TSCUtility.Diagnostics
import var TSCBasic.stderrStream

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

private func executeJob(_ engine: LLTaskBuildEngine) {
if context.isBuildCancelled {
Driver.stdErrQueue.sync {
stderrStream.send("DRIVER EXTRA VERBOSE BUILD WAS CANCELLED\n")
stderrStream.flush()
}
engine.taskIsComplete(DriverBuildValue.jobExecution(success: false))
return
}
Expand Down Expand Up @@ -625,6 +630,12 @@ class ExecuteJobRule: LLBuildRule {
let success = result.exitStatus == .terminated(code: EXIT_SUCCESS)

if !success {
Driver.stdErrQueue.sync {
let out = (try? result.utf8Output()) ?? "stdout failed"
let err = (try? result.utf8stderrOutput()) ?? "stderr failed"
stderrStream.send("DRIVER EXTRA VERBOSE JOB FAILED WITH NON-ZERO \(result.exitStatus) \(job) WITH STDOUT '\(out)' AND STDERR '\(err)'\n")
stderrStream.flush()
}
job.removeOutputsOfFailedCompilation(from: context.fileSystem)
switch result.exitStatus {
case let .terminated(code):
Expand Down Expand Up @@ -672,6 +683,10 @@ class ExecuteJobRule: LLBuildRule {
context.executorDelegate.jobFinished(job: job, result: result, pid: pid)
}
}
Driver.stdErrQueue.sync {
stderrStream.send("DRIVER EXTRA VERBOSE CAUGHT ERROR IN JOB EXECUTION \(error)\n")
stderrStream.flush()
}
value = .jobExecution(success: false)
}

Expand Down
21 changes: 20 additions & 1 deletion Sources/swift-driver/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,30 +155,49 @@ do {
// FIXME: The following check should be at the end of Driver.init, but current
// usage of the DiagnosticVerifier in tests makes this difficult.
guard !driver.diagnosticEngine.hasErrors else {
printToStderr("DRIVER EXTRA VERBOSE HAD ERRORS")
throw Driver.ErrorDiagnostics.emitted
}

printToStderr("DRIVER EXTRA VERBOSE STARTING PLANNING")
let jobs = try driver.planBuild()
printToStderr("DRIVER EXTRA VERBOSE FINISHED PLANNING")

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

printToStderr("DRIVER EXTRA VERBOSE RUNNING JOBS")
try driver.run(jobs: jobs)
printToStderr("DRIVER EXTRA VERBOSE FINISHED JOBS")

if driver.diagnosticEngine.hasErrors {
printToStderr("DRIVER EXTRA VERBOSE HAD ERRORS")
exit(getExitCode(EXIT_FAILURE))
}

printToStderr("DRIVER EXTRA VERBOSE SUCCESS")
exit(getExitCode(0))
} catch let diagnosticData as DiagnosticData {
printToStderr("DRIVER EXTRA VERBOSE IN CATCH FOR DIAGNOSTIC EMISSION")
diagnosticsEngine.emit(.error(diagnosticData))
exit(getExitCode(EXIT_FAILURE))
} catch Driver.ErrorDiagnostics.emitted {
printToStderr("DRIVER EXTRA VERBOSE IN CATCH FOR ALREADY EMITTED DIAGNOSTICS")
exit(getExitCode(EXIT_FAILURE))
} catch {
print("error: \(error)")
printToStderr("DRIVER EXTRA VERBOSE IN CATCH FOR OTHER ERROR")
printToStderr("error: \(error)")
exit(getExitCode(EXIT_FAILURE))
}

import var TSCBasic.stderrStream
func printToStderr(_ message: String) {
Driver.stdErrQueue.sync {
stderrStream.send(message + "\n")
stderrStream.flush()
}
}