@@ -28,6 +28,8 @@ import struct TSCBasic.SHA256
28
28
import var TSCBasic. localFileSystem
29
29
import var TSCBasic. stderrStream
30
30
import var TSCBasic. stdoutStream
31
+ import typealias TSCBasic. ProcessEnvironmentBlock
32
+ import struct TSCBasic. ProcessEnvironmentKey
31
33
32
34
extension Driver {
33
35
/// Stub Error for terminating the process.
@@ -153,7 +155,7 @@ public struct Driver {
153
155
/// The set of environment variables that are visible to the driver and
154
156
/// processes it launches. This is a hook for testing; in actual use
155
157
/// it should be identical to the real environment.
156
- public let env : [ String : String ]
158
+ public let env : ProcessEnvironmentBlock
157
159
158
160
/// Whether we are using the driver as the integrated driver via libSwiftDriver
159
161
public let integratedDriver : Bool
@@ -814,11 +816,44 @@ public struct Driver {
814
816
)
815
817
}
816
818
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
+
817
852
/// Create the driver with the given arguments.
818
853
///
819
854
/// - Parameter args: The command-line arguments, including the "swift" or "swiftc"
820
855
/// 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;
822
857
/// in production, you should use the default argument, which copies the current environment.
823
858
/// - Parameter diagnosticsOutput: The diagnostics output implementation used by the driver to emit errors
824
859
/// and warnings.
@@ -836,7 +871,7 @@ public struct Driver {
836
871
/// shared across different module builds by a build system.
837
872
public init (
838
873
args: [ String ] ,
839
- env : [ String : String ] = ProcessEnv . vars ,
874
+ envBlock : ProcessEnvironmentBlock = ProcessEnv . block ,
840
875
diagnosticsOutput: DiagnosticsOutput = . engine( DiagnosticsEngine ( handlers: [ Driver . stderrDiagnosticsHandler] ) ) ,
841
876
fileSystem: FileSystem = localFileSystem,
842
877
executor: DriverExecutor ,
@@ -845,7 +880,7 @@ public struct Driver {
845
880
compilerExecutableDir: AbsolutePath ? = nil ,
846
881
interModuleDependencyOracle: InterModuleDependencyOracle ? = nil
847
882
) throws {
848
- self . env = env
883
+ self . env = envBlock
849
884
self . fileSystem = fileSystem
850
885
self . integratedDriver = integratedDriver
851
886
self . compilerIntegratedTooling = compilerIntegratedTooling
@@ -2535,7 +2570,7 @@ extension Driver {
2535
2570
static func determineNumParallelJobs(
2536
2571
_ parsedOptions: inout ParsedOptions ,
2537
2572
diagnosticsEngine: DiagnosticsEngine ,
2538
- env: [ String : String ]
2573
+ env: ProcessEnvironmentBlock
2539
2574
) -> Int ? {
2540
2575
guard let numJobs = parseIntOption ( & parsedOptions, option: . j, diagnosticsEngine: diagnosticsEngine) else {
2541
2576
return nil
@@ -3028,7 +3063,7 @@ extension Driver {
3028
3063
targetTriple: Triple ? ,
3029
3064
fileSystem: FileSystem ,
3030
3065
diagnosticsEngine: DiagnosticsEngine ,
3031
- env: [ String : String ]
3066
+ env: ProcessEnvironmentBlock
3032
3067
) -> VirtualPath ? {
3033
3068
var sdkPath : String ?
3034
3069
@@ -3558,7 +3593,7 @@ extension Driver {
3558
3593
_ parsedOptions: inout ParsedOptions ,
3559
3594
diagnosticsEngine: DiagnosticsEngine ,
3560
3595
compilerMode: CompilerMode ,
3561
- env: [ String : String ] ,
3596
+ env: ProcessEnvironmentBlock ,
3562
3597
executor: DriverExecutor ,
3563
3598
fileSystem: FileSystem ,
3564
3599
useStaticResourceDir: Bool ,
@@ -3589,7 +3624,7 @@ extension Driver {
3589
3624
static func computeTargetInfo( _ parsedOptions: inout ParsedOptions ,
3590
3625
diagnosticsEngine: DiagnosticsEngine ,
3591
3626
compilerMode: CompilerMode ,
3592
- env: [ String : String ] ,
3627
+ env: ProcessEnvironmentBlock ,
3593
3628
executor: DriverExecutor ,
3594
3629
libSwiftScan: SwiftScan ? ,
3595
3630
toolchain: Toolchain ,
0 commit comments