@@ -143,6 +143,12 @@ public struct Driver {
143
143
}
144
144
}
145
145
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
+
146
152
/// The set of environment variables that are visible to the driver and
147
153
/// processes it launches. This is a hook for testing; in actual use
148
154
/// it should be identical to the real environment.
@@ -452,13 +458,38 @@ public struct Driver {
452
458
}
453
459
}
454
460
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
+
455
486
/// Create the driver with the given arguments.
456
487
///
457
488
/// - Parameter args: The command-line arguments, including the "swift" or "swiftc"
458
489
/// at the beginning.
459
490
/// - Parameter env: The environment variables to use. This is a hook for testing;
460
491
/// 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
462
493
/// and warnings.
463
494
/// - Parameter fileSystem: The filesystem used by the driver to find resources/SDKs,
464
495
/// expand response files, etc. By default this is the local filesystem.
@@ -476,7 +507,7 @@ public struct Driver {
476
507
public init (
477
508
args: [ String ] ,
478
509
env: [ String : String ] = ProcessEnv . vars,
479
- diagnosticsEngine : DiagnosticsEngine = DiagnosticsEngine ( handlers: [ Driver . stderrDiagnosticsHandler] ) ,
510
+ diagnosticsOutput : DiagnosticsOutput = . engine ( DiagnosticsEngine ( handlers: [ Driver . stderrDiagnosticsHandler] ) ) ,
480
511
fileSystem: FileSystem = localFileSystem,
481
512
executor: DriverExecutor ,
482
513
integratedDriver: Bool = true ,
@@ -488,7 +519,15 @@ public struct Driver {
488
519
self . fileSystem = fileSystem
489
520
self . integratedDriver = integratedDriver
490
521
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
+ }
491
529
self . diagnosticEngine = diagnosticsEngine
530
+
492
531
self . executor = executor
493
532
self . externalTargetModuleDetailsMap = externalTargetModuleDetailsMap
494
533
0 commit comments