Skip to content

Commit c0ef6b1

Browse files
committed
Allow specifying extra environment variables on a per-job basis
1 parent a8d3820 commit c0ef6b1

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Sources/SwiftDriver/Execution/JobExecutor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ class ExecuteJobRule: LLBuildRule {
333333
private func executeJob(_ engine: LLTaskBuildEngine) {
334334
let context = engine.jobExecutorContext
335335
let resolver = context.argsResolver
336-
let env = context.env
337336
let job = key.job
337+
let env = context.env.merging(job.extraEnvironment, uniquingKeysWith: { $1 })
338338

339339
let value: DriverBuildValue
340340
var pid = 0

Sources/SwiftDriver/Jobs/Job.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public struct Job: Codable, Equatable {
4545

4646
/// The outputs produced by the job.
4747
public var outputs: [TypedVirtualPath]
48+
49+
/// Any extra environment variables which should be set while running the job.
50+
public var extraEnvironment: [String: String]
4851

4952
/// The kind of job.
5053
public var kind: Kind
@@ -55,14 +58,16 @@ public struct Job: Codable, Equatable {
5558
commandLine: [ArgTemplate],
5659
displayInputs: [TypedVirtualPath]? = nil,
5760
inputs: [TypedVirtualPath],
58-
outputs: [TypedVirtualPath]
61+
outputs: [TypedVirtualPath],
62+
extraEnvironment: [String: String] = [:]
5963
) {
6064
self.kind = kind
6165
self.tool = tool
6266
self.commandLine = commandLine
6367
self.displayInputs = displayInputs ?? []
6468
self.inputs = inputs
6569
self.outputs = outputs
70+
self.extraEnvironment = extraEnvironment
6671
}
6772
}
6873

@@ -80,6 +85,13 @@ extension Job: CustomStringConvertible {
8085
}
8186
}
8287

88+
if !self.extraEnvironment.isEmpty {
89+
result += " #"
90+
for (envVar, val) in extraEnvironment {
91+
result += " \(envVar)=\(val)"
92+
}
93+
}
94+
8395
return result
8496
}
8597
}

0 commit comments

Comments
 (0)