@@ -55,11 +55,9 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
55
55
/// The path to scratch space (.build) directory.
56
56
let scratchDirectory : AbsolutePath
57
57
58
- /// The llbuild build delegate reference.
59
- private var buildSystemDelegate : BuildOperationBuildSystemDelegateHandler ?
60
-
61
- /// The llbuild build system reference.
62
- private var buildSystem : SPMLLBuild . BuildSystem ?
58
+ /// The llbuild build system reference previously created
59
+ /// via `createBuildSystem` call.
60
+ private var current : ( buildSystem: SPMLLBuild . BuildSystem , tracker: LLBuildProgressTracker ) ?
63
61
64
62
/// If build manifest caching should be enabled.
65
63
public let cacheBuildManifest : Bool
@@ -194,7 +192,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
194
192
195
193
/// Cancel the active build operation.
196
194
public func cancel( deadline: DispatchTime ) throws {
197
- buildSystem ? . cancel ( )
195
+ current ? . buildSystem . cancel ( )
198
196
}
199
197
200
198
// Emit a warning if a target imports another target in this build
@@ -355,8 +353,10 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
355
353
try verifyTargetImports ( in: buildDescription)
356
354
357
355
// Create the build system.
358
- let buildSystem = try self . createBuildSystem ( buildDescription: buildDescription)
359
- self . buildSystem = buildSystem
356
+ let ( buildSystem, progressTracker) = try self . createBuildSystem (
357
+ buildDescription: buildDescription
358
+ )
359
+ self . current = ( buildSystem, progressTracker)
360
360
361
361
// If any plugins are part of the build set, compile them now to surface
362
362
// any errors up-front. Returns true if we should proceed with the build
@@ -366,7 +366,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
366
366
}
367
367
368
368
// delegate is only available after createBuildSystem is called
369
- self . buildSystemDelegate ? . buildStart ( configuration: self . productsBuildParameters. configuration)
369
+ progressTracker . buildStart ( configuration: self . productsBuildParameters. configuration)
370
370
371
371
// Perform the build.
372
372
let llbuildTarget = try computeLLBuildTargetName ( for: subset)
@@ -386,12 +386,11 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
386
386
subsetDescriptor = nil
387
387
}
388
388
389
- self . buildSystemDelegate ? . buildComplete (
389
+ progressTracker . buildComplete (
390
390
success: success,
391
391
duration: duration,
392
392
subsetDescriptor: subsetDescriptor
393
393
)
394
- self . delegate? . buildSystem ( self , didFinishWithResult: success)
395
394
guard success else { throw Diagnostics . fatalError }
396
395
397
396
// Create backwards-compatibility symlink to old build path.
@@ -459,45 +458,48 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
459
458
throw InternalError ( " unknown plugin script runner " )
460
459
}
461
460
// Compile the plugin, getting back a PluginCompilationResult.
462
- class Delegate : PluginScriptCompilerDelegate {
461
+ final class Delegate : PluginScriptCompilerDelegate {
463
462
let preparationStepName : String
464
- let buildSystemDelegate : BuildOperationBuildSystemDelegateHandler ?
465
- init ( preparationStepName: String , buildSystemDelegate : BuildOperationBuildSystemDelegateHandler ? ) {
463
+ let progressTracker : LLBuildProgressTracker ?
464
+ init ( preparationStepName: String , progressTracker : LLBuildProgressTracker ? ) {
466
465
self . preparationStepName = preparationStepName
467
- self . buildSystemDelegate = buildSystemDelegate
466
+ self . progressTracker = progressTracker
468
467
}
469
468
func willCompilePlugin( commandLine: [ String ] , environment: EnvironmentVariables ) {
470
- self . buildSystemDelegate ? . preparationStepStarted ( preparationStepName)
469
+ self . progressTracker ? . preparationStepStarted ( preparationStepName)
471
470
}
472
471
func didCompilePlugin( result: PluginCompilationResult ) {
473
- self . buildSystemDelegate ? . preparationStepHadOutput (
472
+ self . progressTracker ? . preparationStepHadOutput (
474
473
preparationStepName,
475
474
output: result. commandLine. joined ( separator: " " ) ,
476
475
verboseOnly: true
477
476
)
478
477
if !result. compilerOutput. isEmpty {
479
- self . buildSystemDelegate ? . preparationStepHadOutput (
478
+ self . progressTracker ? . preparationStepHadOutput (
480
479
preparationStepName,
481
480
output: result. compilerOutput,
482
481
verboseOnly: false
483
482
)
484
483
}
485
- self . buildSystemDelegate ? . preparationStepFinished ( preparationStepName, result: ( result. succeeded ? . succeeded : . failed) )
484
+ self . progressTracker ? . preparationStepFinished ( preparationStepName, result: ( result. succeeded ? . succeeded : . failed) )
486
485
}
487
486
func skippedCompilingPlugin( cachedResult: PluginCompilationResult ) {
488
487
// Historically we have emitted log info about cached plugins that are used. We should reconsider whether this is the right thing to do.
489
- self . buildSystemDelegate ? . preparationStepStarted ( preparationStepName)
488
+ self . progressTracker ? . preparationStepStarted ( preparationStepName)
490
489
if !cachedResult. compilerOutput. isEmpty {
491
- self . buildSystemDelegate ? . preparationStepHadOutput (
490
+ self . progressTracker ? . preparationStepHadOutput (
492
491
preparationStepName,
493
492
output: cachedResult. compilerOutput,
494
493
verboseOnly: false
495
494
)
496
495
}
497
- self . buildSystemDelegate ? . preparationStepFinished ( preparationStepName, result: ( cachedResult. succeeded ? . succeeded : . failed) )
496
+ self . progressTracker ? . preparationStepFinished ( preparationStepName, result: ( cachedResult. succeeded ? . succeeded : . failed) )
498
497
}
499
498
}
500
- let delegate = Delegate ( preparationStepName: " Compiling plugin \( plugin. targetName) " , buildSystemDelegate: self . buildSystemDelegate)
499
+ let delegate = Delegate (
500
+ preparationStepName: " Compiling plugin \( plugin. targetName) " ,
501
+ progressTracker: self . current? . tracker
502
+ )
501
503
let result = try temp_await {
502
504
pluginConfiguration. scriptRunner. compilePluginScript (
503
505
sourceFiles: plugin. sources. paths,
@@ -746,8 +748,10 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
746
748
747
749
/// Build the package structure target.
748
750
private func buildPackageStructure( ) throws -> Bool {
749
- let buildSystem = try self . createBuildSystem ( buildDescription: . none)
750
- self . buildSystem = buildSystem
751
+ let ( buildSystem, tracker) = try self . createBuildSystem (
752
+ buildDescription: . none
753
+ )
754
+ self . current = ( buildSystem, tracker)
751
755
752
756
// Build the package structure target which will re-generate the llbuild manifest, if necessary.
753
757
return buildSystem. build ( target: " PackageStructure " )
@@ -757,7 +761,9 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
757
761
///
758
762
/// The build description should only be omitted when creating the build system for
759
763
/// building the package structure target.
760
- private func createBuildSystem( buildDescription: BuildDescription ? ) throws -> SPMLLBuild . BuildSystem {
764
+ private func createBuildSystem(
765
+ buildDescription: BuildDescription ?
766
+ ) throws -> ( buildSystem: SPMLLBuild . BuildSystem , tracker: LLBuildProgressTracker ) {
761
767
// Figure out which progress bar we have to use during the build.
762
768
let progressAnimation = ProgressAnimation . ninja (
763
769
stream: self . outputStream,
@@ -774,7 +780,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
774
780
)
775
781
776
782
// Create the build delegate.
777
- let buildSystemDelegate = BuildOperationBuildSystemDelegateHandler (
783
+ let progressTracker = LLBuildProgressTracker (
778
784
buildSystem: self ,
779
785
buildExecutionContext: buildExecutionContext,
780
786
outputStream: self . outputStream,
@@ -783,23 +789,17 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
783
789
observabilityScope: self . observabilityScope,
784
790
delegate: self . delegate
785
791
)
786
- self . buildSystemDelegate = buildSystemDelegate
787
792
788
793
let databasePath = self . scratchDirectory. appending ( " build.db " ) . pathString
789
- let buildSystem = SPMLLBuild . BuildSystem (
794
+
795
+ let llbuildSystem = SPMLLBuild . BuildSystem (
790
796
buildFile: self . productsBuildParameters. llbuildManifest. pathString,
791
797
databaseFile: databasePath,
792
- delegate: buildSystemDelegate ,
798
+ delegate: progressTracker ,
793
799
schedulerLanes: self . productsBuildParameters. workers
794
800
)
795
801
796
- // TODO: this seems fragile, perhaps we replace commandFailureHandler by adding relevant calls in the delegates chain
797
- buildSystemDelegate. commandFailureHandler = {
798
- buildSystem. cancel ( )
799
- self . delegate? . buildSystemDidCancel ( self )
800
- }
801
-
802
- return buildSystem
802
+ return ( buildSystem: llbuildSystem, tracker: progressTracker)
803
803
}
804
804
805
805
/// Runs any prebuild commands associated with the given list of plugin invocation results, in order, and returns the
0 commit comments