@@ -363,11 +363,11 @@ final class CopyCommand: CustomLLBuildCommand {
363
363
364
364
/// Convenient llbuild build system delegate implementation
365
365
final class BuildOperationBuildSystemDelegateHandler : LLBuildBuildSystemDelegate , SwiftCompilerOutputParserDelegate {
366
- var outputStream : ThreadSafeOutputByteStream
367
- var progressAnimation : ProgressAnimationProtocol
368
- var onCommmandFailure : ( ( ) -> Void ) ?
369
- var isVerbose : Bool = false
370
- weak var delegate : SPMBuildCore . BuildSystemDelegate ?
366
+ private let outputStream : ThreadSafeOutputByteStream
367
+ private let progressAnimation : ProgressAnimationProtocol
368
+ var commandFailureHandler : ( ( ) -> Void ) ?
369
+ private let logLevel : Basics . Diagnostic . Severity
370
+ private weak var delegate : SPMBuildCore . BuildSystemDelegate ?
371
371
private let buildSystem : SPMBuildCore . BuildSystem
372
372
private let queue = DispatchQueue ( label: " org.swift.swiftpm.build-delegate " )
373
373
private var taskTracker = CommandTaskTracker ( )
@@ -382,22 +382,24 @@ final class BuildOperationBuildSystemDelegateHandler: LLBuildBuildSystemDelegate
382
382
383
383
init (
384
384
buildSystem: SPMBuildCore . BuildSystem ,
385
- bctx : BuildExecutionContext ,
385
+ buildExecutionContext : BuildExecutionContext ,
386
386
outputStream: OutputByteStream ,
387
387
progressAnimation: ProgressAnimationProtocol ,
388
+ logLevel: Basics . Diagnostic . Severity ,
388
389
observabilityScope: ObservabilityScope ,
389
390
delegate: SPMBuildCore . BuildSystemDelegate ?
390
391
) {
392
+ self . buildSystem = buildSystem
393
+ self . buildExecutionContext = buildExecutionContext
391
394
// FIXME: Implement a class convenience initializer that does this once they are supported
392
395
// https://forums.swift.org/t/allow-self-x-in-class-convenience-initializers/15924
393
396
self . outputStream = outputStream as? ThreadSafeOutputByteStream ?? ThreadSafeOutputByteStream ( outputStream)
394
397
self . progressAnimation = progressAnimation
395
- self . buildExecutionContext = bctx
396
- self . delegate = delegate
397
- self . buildSystem = buildSystem
398
+ self . logLevel = logLevel
398
399
self . observabilityScope = observabilityScope
400
+ self . delegate = delegate
399
401
400
- let swiftParsers = bctx . buildDescription? . swiftCommands. mapValues { tool in
402
+ let swiftParsers = buildExecutionContext . buildDescription? . swiftCommands. mapValues { tool in
401
403
SwiftCompilerOutputParser ( targetName: tool. moduleName, delegate: self )
402
404
} ?? [ : ]
403
405
self . swiftParsers = swiftParsers
@@ -429,7 +431,7 @@ final class BuildOperationBuildSystemDelegateHandler: LLBuildBuildSystemDelegate
429
431
}
430
432
431
433
func hadCommandFailure( ) {
432
- onCommmandFailure ? ( )
434
+ self . commandFailureHandler ? ( )
433
435
}
434
436
435
437
func handleDiagnostic( _ diagnostic: SPMLLBuild . Diagnostic ) {
@@ -446,7 +448,7 @@ final class BuildOperationBuildSystemDelegateHandler: LLBuildBuildSystemDelegate
446
448
}
447
449
448
450
func commandStatusChanged( _ command: SPMLLBuild . Command , kind: CommandStatusKind ) {
449
- guard !isVerbose else { return }
451
+ guard !self . logLevel . isVerbose else { return }
450
452
guard command. shouldShowStatus else { return }
451
453
guard !swiftParsers. keys. contains ( command. name) else { return }
452
454
@@ -467,7 +469,7 @@ final class BuildOperationBuildSystemDelegateHandler: LLBuildBuildSystemDelegate
467
469
468
470
queue. async {
469
471
self . delegate? . buildSystem ( self . buildSystem, didStartCommand: BuildSystemCommand ( command) )
470
- if self . isVerbose {
472
+ if self . logLevel . isVerbose {
471
473
self . outputStream <<< command. verboseDescription <<< " \n "
472
474
self . outputStream. flush ( )
473
475
}
@@ -485,7 +487,7 @@ final class BuildOperationBuildSystemDelegateHandler: LLBuildBuildSystemDelegate
485
487
queue. async {
486
488
self . delegate? . buildSystem ( self . buildSystem, didFinishCommand: BuildSystemCommand ( command) )
487
489
488
- if !self . isVerbose {
490
+ if !self . logLevel . isVerbose {
489
491
let targetName = self . swiftParsers [ command. name] ? . targetName
490
492
self . taskTracker. commandFinished ( command, result: result, targetName: targetName)
491
493
self . updateProgress ( )
@@ -575,7 +577,7 @@ final class BuildOperationBuildSystemDelegateHandler: LLBuildBuildSystemDelegate
575
577
576
578
func swiftCompilerOutputParser( _ parser: SwiftCompilerOutputParser , didParse message: SwiftCompilerMessage ) {
577
579
queue. async {
578
- if self . isVerbose {
580
+ if self . logLevel . isVerbose {
579
581
if let text = message. verboseProgressText {
580
582
self . outputStream <<< text <<< " \n "
581
583
self . outputStream. flush ( )
@@ -587,7 +589,7 @@ final class BuildOperationBuildSystemDelegateHandler: LLBuildBuildSystemDelegate
587
589
588
590
if let output = message. standardOutput {
589
591
// first we want to print the output so users have it handy
590
- if !self . isVerbose {
592
+ if !self . logLevel . isVerbose {
591
593
self . progressAnimation. clear ( )
592
594
}
593
595
@@ -609,7 +611,7 @@ final class BuildOperationBuildSystemDelegateHandler: LLBuildBuildSystemDelegate
609
611
func swiftCompilerOutputParser( _ parser: SwiftCompilerOutputParser , didFailWith error: Error ) {
610
612
let message = ( error as? LocalizedError ) ? . errorDescription ?? error. localizedDescription
611
613
self . observabilityScope. emit ( . swiftCompilerOutputParsingError( message) )
612
- onCommmandFailure ? ( )
614
+ self . commandFailureHandler ? ( )
613
615
}
614
616
615
617
func buildComplete( success: Bool ) {
0 commit comments