@@ -143,6 +143,12 @@ public struct Driver {
143143 }
144144 }
145145
146+ /// Specific implementation of a diagnostics output type that can be used when initializing a new `Driver`.
147+ public enum DiagnosticsOutput {
148+ case engine( DiagnosticsEngine )
149+ case handler( DiagnosticsEngine . DiagnosticsHandler )
150+ }
151+
146152 /// The set of environment variables that are visible to the driver and
147153 /// processes it launches. This is a hook for testing; in actual use
148154 /// it should be identical to the real environment.
@@ -452,13 +458,38 @@ public struct Driver {
452458 }
453459 }
454460
461+ @available ( * , deprecated, renamed: " init(args:env:diagnosticsOutput:fileSystem:executor:integratedDriver:compilerExecutableDir:externalTargetModuleDetailsMap:interModuleDependencyOracle:) " )
462+ public init (
463+ args: [ String ] ,
464+ env: [ String : String ] = ProcessEnv . vars,
465+ diagnosticsEngine: DiagnosticsEngine ,
466+ fileSystem: FileSystem = localFileSystem,
467+ executor: DriverExecutor ,
468+ integratedDriver: Bool = true ,
469+ compilerExecutableDir: AbsolutePath ? = nil ,
470+ externalTargetModuleDetailsMap: ExternalTargetModuleDetailsMap ? = nil ,
471+ interModuleDependencyOracle: InterModuleDependencyOracle ? = nil
472+ ) throws {
473+ try self . init (
474+ args: args,
475+ env: env,
476+ diagnosticsOutput: . engine( diagnosticsEngine) ,
477+ fileSystem: fileSystem,
478+ executor: executor,
479+ integratedDriver: integratedDriver,
480+ compilerExecutableDir: compilerExecutableDir,
481+ externalTargetModuleDetailsMap: externalTargetModuleDetailsMap,
482+ interModuleDependencyOracle: interModuleDependencyOracle
483+ )
484+ }
485+
455486 /// Create the driver with the given arguments.
456487 ///
457488 /// - Parameter args: The command-line arguments, including the "swift" or "swiftc"
458489 /// at the beginning.
459490 /// - Parameter env: The environment variables to use. This is a hook for testing;
460491 /// in production, you should use the default argument, which copies the current environment.
461- /// - Parameter diagnosticsEngine : The diagnostic engine used by the driver to emit errors
492+ /// - Parameter diagnosticsOutput : The diagnostics output implementation used by the driver to emit errors
462493 /// and warnings.
463494 /// - Parameter fileSystem: The filesystem used by the driver to find resources/SDKs,
464495 /// expand response files, etc. By default this is the local filesystem.
@@ -476,7 +507,7 @@ public struct Driver {
476507 public init (
477508 args: [ String ] ,
478509 env: [ String : String ] = ProcessEnv . vars,
479- diagnosticsEngine : DiagnosticsEngine = DiagnosticsEngine ( handlers: [ Driver . stderrDiagnosticsHandler] ) ,
510+ diagnosticsOutput : DiagnosticsOutput = . engine ( DiagnosticsEngine ( handlers: [ Driver . stderrDiagnosticsHandler] ) ) ,
480511 fileSystem: FileSystem = localFileSystem,
481512 executor: DriverExecutor ,
482513 integratedDriver: Bool = true ,
@@ -488,7 +519,15 @@ public struct Driver {
488519 self . fileSystem = fileSystem
489520 self . integratedDriver = integratedDriver
490521
522+ let diagnosticsEngine : DiagnosticsEngine
523+ switch diagnosticsOutput {
524+ case . engine( let engine) :
525+ diagnosticsEngine = engine
526+ case . handler( let handler) :
527+ diagnosticsEngine = DiagnosticsEngine ( handlers: [ handler] )
528+ }
491529 self . diagnosticEngine = diagnosticsEngine
530+
492531 self . executor = executor
493532 self . externalTargetModuleDetailsMap = externalTargetModuleDetailsMap
494533
0 commit comments