Skip to content

Commit 1e9abfa

Browse files
committed
support -v
1 parent ff622c2 commit 1e9abfa

File tree

2 files changed

+66
-32
lines changed

2 files changed

+66
-32
lines changed

Sources/SwiftDriver/Jobs/PrebuiltModulesJob.swift

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,69 @@
1212
import TSCBasic
1313
import SwiftOptions
1414

15+
public class PrebuitModuleGenerationDelegate: JobExecutionDelegate {
16+
var failingModules = Set<String>()
17+
var commandMap: [Int: String] = [:]
18+
let diagnosticsEngine: DiagnosticsEngine
19+
let verbose: Bool
20+
public init(_ diagnosticsEngine: DiagnosticsEngine, _ verbose: Bool) {
21+
self.diagnosticsEngine = diagnosticsEngine
22+
self.verbose = verbose
23+
}
24+
25+
func printJobInfo(_ job: Job, _ start: Bool) {
26+
guard verbose else {
27+
return
28+
}
29+
for arg in job.commandLine {
30+
if case .path(let p) = arg {
31+
if p.extension == "swiftinterface" {
32+
Driver.stdErrQueue.sync {
33+
stderrStream <<< (start ? "started: " : "finished: ")
34+
stderrStream <<< p.absolutePath!.pathString <<< "\n"
35+
stderrStream.flush()
36+
}
37+
return
38+
}
39+
}
40+
}
41+
}
42+
43+
public func jobStarted(job: Job, arguments: [String], pid: Int) {
44+
commandMap[pid] = arguments.reduce("") { return $0 + " " + $1 }
45+
printJobInfo(job, true)
46+
}
47+
48+
public var hasStdlibFailure: Bool {
49+
return failingModules.contains("Swift") || failingModules.contains("_Concurrency")
50+
}
51+
52+
public func jobFinished(job: Job, result: ProcessResult, pid: Int) {
53+
switch result.exitStatus {
54+
case .terminated(code: let code):
55+
if code == 0 {
56+
printJobInfo(job, false)
57+
} else {
58+
failingModules.insert(job.moduleName)
59+
let result: String = try! result.utf8stderrOutput()
60+
Driver.stdErrQueue.sync {
61+
stderrStream <<< "failed: " <<< commandMap[pid]! <<< "\n"
62+
stderrStream <<< result <<< "\n"
63+
stderrStream.flush()
64+
}
65+
}
66+
#if !os(Windows)
67+
case .signalled:
68+
diagnosticsEngine.emit(.remark("\(job.moduleName) interrupted"))
69+
#endif
70+
}
71+
}
72+
73+
public func jobSkipped(job: Job) {
74+
diagnosticsEngine.emit(.error("\(job.moduleName) skipped"))
75+
}
76+
}
77+
1578
public struct PrebuiltModuleInput {
1679
// The path to the input/output of the a module building task.
1780
let path: TypedVirtualPath

Sources/swift-build-sdk-interfaces/main.swift

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -38,38 +38,9 @@ if rawOutputDir.isEmpty {
3838
/// they are Foundation and anything below.
3939
let coreMode = CommandLine.arguments.contains("-core")
4040

41-
class PrebuitGenDelegate: JobExecutionDelegate {
42-
var failingModules = Set<String>()
43-
var commandMap: [Int: String] = [:]
44-
func jobStarted(job: Job, arguments: [String], pid: Int) {
45-
commandMap[pid] = arguments.reduce("") { return $0 + " " + $1 }
46-
}
47-
48-
var hasStdlibFailure: Bool {
49-
return failingModules.contains("Swift") || failingModules.contains("_Concurrency")
50-
}
41+
/// Verbose to print more info
42+
let verbose = CommandLine.arguments.contains("-v")
5143

52-
func jobFinished(job: Job, result: ProcessResult, pid: Int) {
53-
switch result.exitStatus {
54-
case .terminated(code: let code):
55-
if code != 0 {
56-
failingModules.insert(job.moduleName)
57-
Driver.stdErrQueue.sync {
58-
stderrStream <<< "failed: " <<< commandMap[pid]! <<< "\n"
59-
stderrStream.flush()
60-
}
61-
}
62-
#if !os(Windows)
63-
case .signalled:
64-
diagnosticsEngine.emit(.remark("\(job.moduleName) interrupted"))
65-
#endif
66-
}
67-
}
68-
69-
func jobSkipped(job: Job) {
70-
diagnosticsEngine.emit(.error("\(job.moduleName) skipped"))
71-
}
72-
}
7344
do {
7445
let sdkPath = try VirtualPath(path: sdkPathRaw).absolutePath!
7546
if !localFileSystem.exists(sdkPath) {
@@ -136,7 +107,7 @@ do {
136107
executor: executor,
137108
compilerExecutableDir: swiftcPath.parentDirectory)
138109
let (jobs, danglingJobs) = try driver.generatePrebuitModuleGenerationJobs(with: inputMap, into: outputDir, exhaustive: !coreMode)
139-
let delegate = PrebuitGenDelegate()
110+
let delegate = PrebuitModuleGenerationDelegate(diagnosticsEngine, verbose)
140111
do {
141112
try executor.execute(workload: DriverExecutorWorkload.init(jobs, nil, continueBuildingAfterErrors: true),
142113
delegate: delegate, numParallelJobs: 128)

0 commit comments

Comments
 (0)