Skip to content

Commit d0dd2e4

Browse files
committed
[Job] Add a nice description to Job.
The description can be used by clients that want to print what's going on. This will be used to replace a giant switch in SwiftPM, and can help give a consistent presentation across build systems that integrate the Swift driver.
1 parent 0a4ee42 commit d0dd2e4

16 files changed

+99
-18
lines changed

Sources/SwiftDriver/Dependency Scanning/ModuleDependencyBuildGeneration.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ extension Driver {
6565
swiftModuleDetails.commandLine?.forEach { commandLine.appendFlag($0) }
6666

6767
return Job(
68+
moduleName: moduleName,
6869
kind: .emitModule,
6970
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
7071
commandLine: commandLine,
@@ -99,6 +100,7 @@ extension Driver {
99100
clangModuleDetails.commandLine?.forEach { commandLine.appendFlags("-Xcc", $0) }
100101

101102
return Job(
103+
moduleName: moduleName,
102104
kind: .generatePCM,
103105
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
104106
commandLine: commandLine,

Sources/SwiftDriver/Jobs/AutolinkExtractJob.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extension Driver {
2929
commandLine.appendPath(output)
3030

3131
return Job(
32+
moduleName: moduleName,
3233
kind: .autolinkExtract,
3334
tool: .absolute(try toolchain.getToolPath(.swiftAutolinkExtract)),
3435
commandLine: commandLine,

Sources/SwiftDriver/Jobs/BackendJob.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ extension Driver {
6565
allOutputs += outputs
6666

6767
return Job(
68+
moduleName: moduleName,
6869
kind: .backend,
6970
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
7071
commandLine: commandLine,

Sources/SwiftDriver/Jobs/CompileJob.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ extension Driver {
205205
}
206206

207207
return Job(
208+
moduleName: moduleName,
208209
kind: .compile,
209210
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
210211
commandLine: commandLine,

Sources/SwiftDriver/Jobs/EmitModuleJob.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ extension Driver {
6969
commandLine.appendPath(moduleOutputPath)
7070

7171
return Job(
72+
moduleName: moduleName,
7273
kind: .emitModule,
7374
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
7475
commandLine: commandLine,

Sources/SwiftDriver/Jobs/GenerateDSYMJob.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ extension Driver {
2323
commandLine.appendPath(outputPath)
2424

2525
return Job(
26+
moduleName: moduleName,
2627
kind: .generateDSYM,
2728
tool: .absolute(try toolchain.getToolPath(.dsymutil)),
2829
commandLine: commandLine,

Sources/SwiftDriver/Jobs/GeneratePCHJob.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ extension Driver {
6262
outputs.append(output)
6363

6464
return Job(
65+
moduleName: moduleName,
6566
kind: .generatePCH,
6667
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
6768
commandLine: commandLine,

Sources/SwiftDriver/Jobs/GeneratePCMJob.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ extension Driver {
5353
try commandLine.appendLast(.indexStorePath, from: &parsedOptions)
5454

5555
return Job(
56+
moduleName: moduleName,
5657
kind: .generatePCM,
5758
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
5859
commandLine: commandLine,

Sources/SwiftDriver/Jobs/InterpretJob.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extension Driver {
4141
targetTriple: self.targetTriple)
4242

4343
return Job(
44+
moduleName: moduleName,
4445
kind: .interpret,
4546
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
4647
commandLine: commandLine,

Sources/SwiftDriver/Jobs/Job.swift

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public struct Job: Codable, Equatable, Hashable {
4242
case path(VirtualPath)
4343
}
4444

45+
/// The SWift module this job involves.
46+
public var moduleName: String
47+
4548
/// The tool to invoke.
4649
public var tool: VirtualPath
4750

@@ -70,6 +73,7 @@ public struct Job: Codable, Equatable, Hashable {
7073
public var kind: Kind
7174

7275
public init(
76+
moduleName: String,
7377
kind: Kind,
7478
tool: VirtualPath,
7579
commandLine: [ArgTemplate],
@@ -80,6 +84,7 @@ public struct Job: Codable, Equatable, Hashable {
8084
requiresInPlaceExecution: Bool = false,
8185
supportsResponseFiles: Bool = false
8286
) {
87+
self.moduleName = moduleName
8388
self.kind = kind
8489
self.tool = tool
8590
self.commandLine = commandLine
@@ -115,6 +120,58 @@ extension Job {
115120
}
116121
}
117122

123+
extension Job : CustomStringConvertible {
124+
public var description: String {
125+
let moduleName = "hello"
126+
switch kind {
127+
case .compile:
128+
return "Compiling \(moduleName) \(displayInputs.first?.file.name ?? "")"
129+
130+
case .mergeModule:
131+
return "Merging module \(moduleName)"
132+
133+
case .link:
134+
return "Linking \(moduleName)"
135+
136+
case .generateDSYM:
137+
return "Generating dSYM for module \(moduleName)"
138+
139+
case .autolinkExtract:
140+
return "Extracting autolink information for module \(moduleName)"
141+
142+
case .emitModule:
143+
return "Emitting module for \(moduleName)"
144+
145+
case .generatePCH:
146+
return "Compiling bridging header \(displayInputs.first!.file.name)"
147+
148+
case .generatePCM:
149+
return "Compiling Clang module \(displayInputs.first!.file.name)"
150+
151+
case .interpret:
152+
return "Interpreting \(displayInputs.first!.file.name)"
153+
154+
case .repl:
155+
return "Executing Swift REPL"
156+
157+
case .verifyDebugInfo:
158+
return "Verifying debug information for module \(moduleName)"
159+
160+
case .printTargetInfo:
161+
return "Gathering target information for module \(moduleName)"
162+
163+
case .versionRequest:
164+
return "Getting Swift version information"
165+
166+
case .help:
167+
return "Swift help"
168+
169+
case .backend:
170+
return "Embedding bitcode for \(moduleName)"
171+
}
172+
}
173+
}
174+
118175
extension Job.Kind {
119176
/// Whether this job kind uses the Swift frontend.
120177
public var isSwiftFrontend: Bool {

Sources/SwiftDriver/Jobs/LinkJob.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ extension Driver {
5353

5454
// TODO: some, but not all, linkers support response files.
5555
return Job(
56+
moduleName: moduleName,
5657
kind: .link,
5758
tool: .absolute(toolPath),
5859
commandLine: commandLine,

Sources/SwiftDriver/Jobs/MergeModuleJob.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ extension Driver {
5050
commandLine.appendPath(moduleOutput!.outputPath)
5151

5252
return Job(
53+
moduleName: moduleName,
5354
kind: .mergeModule,
5455
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
5556
commandLine: commandLine,

Sources/SwiftDriver/Jobs/Planning.swift

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -226,34 +226,40 @@ extension Driver {
226226
try commandLine.appendLast(.targetVariant, from: &parsedOptions)
227227
try commandLine.appendLast(.sdk, from: &parsedOptions)
228228
try commandLine.appendLast(.resourceDir, from: &parsedOptions)
229-
return Job(kind: .printTargetInfo,
230-
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
231-
commandLine: commandLine,
232-
inputs: [],
233-
outputs: [],
234-
requiresInPlaceExecution: true)
229+
return Job(
230+
moduleName: moduleName,
231+
kind: .printTargetInfo,
232+
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
233+
commandLine: commandLine,
234+
inputs: [],
235+
outputs: [],
236+
requiresInPlaceExecution: true)
235237
}
236238

237239
if parsedOptions.hasArgument(.version) || parsedOptions.hasArgument(.version_) {
238-
return Job(kind: .versionRequest,
239-
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
240-
commandLine: [.flag("--version")],
241-
inputs: [],
242-
outputs: [],
243-
requiresInPlaceExecution: true)
240+
return Job(
241+
moduleName: moduleName,
242+
kind: .versionRequest,
243+
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
244+
commandLine: [.flag("--version")],
245+
inputs: [],
246+
outputs: [],
247+
requiresInPlaceExecution: true)
244248
}
245249

246250
if parsedOptions.contains(.help) || parsedOptions.contains(.helpHidden) {
247251
var commandLine: [Job.ArgTemplate] = [.flag("-tool=\(driverKind.rawValue)")]
248252
if parsedOptions.contains(.helpHidden) {
249253
commandLine.append(.flag("-show-hidden"))
250254
}
251-
return Job(kind: .help,
252-
tool: .absolute(try toolchain.getToolPath(.swiftHelp)),
253-
commandLine: commandLine,
254-
inputs: [],
255-
outputs: [],
256-
requiresInPlaceExecution: true)
255+
return Job(
256+
moduleName: moduleName,
257+
kind: .help,
258+
tool: .absolute(try toolchain.getToolPath(.swiftHelp)),
259+
commandLine: commandLine,
260+
inputs: [],
261+
outputs: [],
262+
requiresInPlaceExecution: true)
257263
}
258264

259265
return nil

Sources/SwiftDriver/Jobs/ReplJob.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ extension Driver {
2323
// Squash important frontend options into a single argument for LLDB.
2424
let lldbArg = "--repl=\(commandLine.joinedArguments)"
2525
return Job(
26+
moduleName: moduleName,
2627
kind: .repl,
2728
tool: .absolute(try toolchain.getToolPath(.lldb)),
2829
commandLine: [Job.ArgTemplate.flag(lldbArg)],

Sources/SwiftDriver/Jobs/VerifyDebugInfoJob.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ extension Driver {
2121
commandLine.appendPath(input.file)
2222

2323
return Job(
24+
moduleName: moduleName,
2425
kind: .verifyDebugInfo,
2526
tool: .absolute(try toolchain.getToolPath(.dwarfdump)),
2627
commandLine: commandLine,

Tests/SwiftDriverTests/JobExecutorTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ final class JobExecutorTests: XCTestCase {
8181
]
8282

8383
let compileFoo = Job(
84+
moduleName: "main",
8485
kind: .compile,
8586
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
8687
commandLine: [
@@ -104,6 +105,7 @@ final class JobExecutorTests: XCTestCase {
104105
)
105106

106107
let compileMain = Job(
108+
moduleName: "main",
107109
kind: .compile,
108110
tool: .absolute(try toolchain.getToolPath(.swiftCompiler)),
109111
commandLine: [
@@ -127,6 +129,7 @@ final class JobExecutorTests: XCTestCase {
127129
)
128130

129131
let link = Job(
132+
moduleName: "main",
130133
kind: .link,
131134
tool: .absolute(try toolchain.getToolPath(.dynamicLinker)),
132135
commandLine: [
@@ -167,6 +170,7 @@ final class JobExecutorTests: XCTestCase {
167170

168171
func testStubProcessProtocol() throws {
169172
let job = Job(
173+
moduleName: "main",
170174
kind: .compile,
171175
tool: .absolute(AbsolutePath("/usr/bin/swift")),
172176
commandLine: [.flag("something")],

0 commit comments

Comments
 (0)