@@ -28,6 +28,8 @@ import struct TSCBasic.SHA256
2828import var TSCBasic. localFileSystem
2929import var TSCBasic. stderrStream
3030import var TSCBasic. stdoutStream
31+ import typealias TSCBasic. ProcessEnvironmentBlock
32+ import struct TSCBasic. ProcessEnvironmentKey
3133
3234extension Driver {
3335 /// Stub Error for terminating the process.
@@ -153,7 +155,7 @@ public struct Driver {
153155 /// The set of environment variables that are visible to the driver and
154156 /// processes it launches. This is a hook for testing; in actual use
155157 /// it should be identical to the real environment.
156- public let env : [ String : String ]
158+ public let env : ProcessEnvironmentBlock
157159
158160 /// Whether we are using the driver as the integrated driver via libSwiftDriver
159161 public let integratedDriver : Bool
@@ -814,11 +816,44 @@ public struct Driver {
814816 )
815817 }
816818
819+ @available ( * , deprecated, renamed: " init(args:envBlock:diagnosticsOutput:fileSystem:executor:integratedDriver:compilerIntegratedTooling:compilerExecutableDir:externalTargetModuleDetailsMap:interModuleDependencyOracle:) " )
820+ @_disfavoredOverload
821+ public init (
822+ args: [ String ] ,
823+ env: [ String : String ] = ProcessEnv . vars,
824+ diagnosticsOutput: DiagnosticsOutput = . engine( DiagnosticsEngine ( handlers: [ Driver . stderrDiagnosticsHandler] ) ) ,
825+ fileSystem: FileSystem = localFileSystem,
826+ executor: DriverExecutor ,
827+ integratedDriver: Bool = true ,
828+ compilerIntegratedTooling: Bool = false ,
829+ compilerExecutableDir: AbsolutePath ? = nil ,
830+ externalTargetModuleDetailsMap: ExternalTargetModuleDetailsMap ? = nil ,
831+ interModuleDependencyOracle: InterModuleDependencyOracle ? = nil
832+ ) throws {
833+ let envBlock = env. reduce ( [ : ] ) { ( partialResult: ProcessEnvironmentBlock , tuple: ( key: String , value: String ) ) in
834+ var result = partialResult
835+ result [ ProcessEnvironmentKey ( tuple. key) ] = tuple. value
836+ return result
837+ }
838+ try self . init (
839+ args: args,
840+ envBlock: envBlock,
841+ diagnosticsOutput: diagnosticsOutput,
842+ fileSystem: fileSystem,
843+ executor: executor,
844+ integratedDriver: integratedDriver,
845+ compilerIntegratedTooling: false ,
846+ compilerExecutableDir: compilerExecutableDir,
847+ externalTargetModuleDetailsMap: externalTargetModuleDetailsMap,
848+ interModuleDependencyOracle: interModuleDependencyOracle
849+ )
850+ }
851+
817852 /// Create the driver with the given arguments.
818853 ///
819854 /// - Parameter args: The command-line arguments, including the "swift" or "swiftc"
820855 /// at the beginning.
821- /// - Parameter env : The environment variables to use. This is a hook for testing;
856+ /// - Parameter envBlock : The environment variables to use. This is a hook for testing;
822857 /// in production, you should use the default argument, which copies the current environment.
823858 /// - Parameter diagnosticsOutput: The diagnostics output implementation used by the driver to emit errors
824859 /// and warnings.
@@ -836,7 +871,7 @@ public struct Driver {
836871 /// shared across different module builds by a build system.
837872 public init (
838873 args: [ String ] ,
839- env : [ String : String ] = ProcessEnv . vars ,
874+ envBlock : ProcessEnvironmentBlock = ProcessEnv . block ,
840875 diagnosticsOutput: DiagnosticsOutput = . engine( DiagnosticsEngine ( handlers: [ Driver . stderrDiagnosticsHandler] ) ) ,
841876 fileSystem: FileSystem = localFileSystem,
842877 executor: DriverExecutor ,
@@ -845,7 +880,7 @@ public struct Driver {
845880 compilerExecutableDir: AbsolutePath ? = nil ,
846881 interModuleDependencyOracle: InterModuleDependencyOracle ? = nil
847882 ) throws {
848- self . env = env
883+ self . env = envBlock
849884 self . fileSystem = fileSystem
850885 self . integratedDriver = integratedDriver
851886 self . compilerIntegratedTooling = compilerIntegratedTooling
@@ -2535,7 +2570,7 @@ extension Driver {
25352570 static func determineNumParallelJobs(
25362571 _ parsedOptions: inout ParsedOptions ,
25372572 diagnosticsEngine: DiagnosticsEngine ,
2538- env: [ String : String ]
2573+ env: ProcessEnvironmentBlock
25392574 ) -> Int ? {
25402575 guard let numJobs = parseIntOption ( & parsedOptions, option: . j, diagnosticsEngine: diagnosticsEngine) else {
25412576 return nil
@@ -3028,7 +3063,7 @@ extension Driver {
30283063 targetTriple: Triple ? ,
30293064 fileSystem: FileSystem ,
30303065 diagnosticsEngine: DiagnosticsEngine ,
3031- env: [ String : String ]
3066+ env: ProcessEnvironmentBlock
30323067 ) -> VirtualPath ? {
30333068 var sdkPath : String ?
30343069
@@ -3558,7 +3593,7 @@ extension Driver {
35583593 _ parsedOptions: inout ParsedOptions ,
35593594 diagnosticsEngine: DiagnosticsEngine ,
35603595 compilerMode: CompilerMode ,
3561- env: [ String : String ] ,
3596+ env: ProcessEnvironmentBlock ,
35623597 executor: DriverExecutor ,
35633598 fileSystem: FileSystem ,
35643599 useStaticResourceDir: Bool ,
@@ -3589,7 +3624,7 @@ extension Driver {
35893624 static func computeTargetInfo( _ parsedOptions: inout ParsedOptions ,
35903625 diagnosticsEngine: DiagnosticsEngine ,
35913626 compilerMode: CompilerMode ,
3592- env: [ String : String ] ,
3627+ env: ProcessEnvironmentBlock ,
35933628 executor: DriverExecutor ,
35943629 libSwiftScan: SwiftScan ? ,
35953630 toolchain: Toolchain ,
0 commit comments