Skip to content

Commit 3e19adc

Browse files
committed
remove draw and clear api
1 parent 421e56a commit 3e19adc

10 files changed

+52
-70
lines changed

Sources/Basics/ProgressAnimation/Concrete/BlastProgressAnimation.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,21 @@ extension BlastProgressAnimation: ProgressAnimationProtocol2 {
9090
self._flush()
9191
}
9292

93-
func draw() {
94-
guard self.interactive else { return }
95-
self._draw()
93+
func interleave(_ bytes: some Collection<UInt8>) {
94+
if self.interactive {
95+
self._clear()
96+
}
97+
self.terminal.write(bytes)
98+
if self.interactive {
99+
self._draw()
100+
}
96101
self._flush()
97102
}
98103

99104
func complete() {
100105
self._complete()
101106
self._flush()
102107
}
103-
104-
func clear() {
105-
guard self.interactive else { return }
106-
self._clear()
107-
self._flush()
108-
}
109108
}
110109

111110
extension BlastProgressAnimation {

Sources/Basics/ProgressAnimation/Concrete/NinjaMultiLineProgressAnimation.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ final class NinjaMultiLineProgressAnimation {
3737
}
3838

3939
extension NinjaMultiLineProgressAnimation: ProgressAnimationProtocol2 {
40-
41-
4240
func update(
4341
id: Int,
4442
name: String,
@@ -60,9 +58,10 @@ extension NinjaMultiLineProgressAnimation: ProgressAnimationProtocol2 {
6058
self.terminal.flush()
6159
}
6260

63-
func draw() {}
61+
func interleave(_ bytes: some Collection<UInt8>) {
62+
self.terminal.write(bytes)
63+
self.terminal.flush()
64+
}
6465

6566
func complete() {}
66-
67-
func clear() {}
6867
}

Sources/Basics/ProgressAnimation/Concrete/NinjaRedrawingProgressAnimation.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ extension NinjaRedrawingProgressAnimation: ProgressAnimationProtocol2 {
5656
self._flush()
5757
}
5858

59-
func draw() {
59+
func interleave(_ bytes: some Collection<UInt8>) {
60+
self._clear()
61+
self.terminal.write(bytes)
6062
self._draw()
6163
self._flush()
6264
}
@@ -65,11 +67,6 @@ extension NinjaRedrawingProgressAnimation: ProgressAnimationProtocol2 {
6567
self._complete()
6668
self._flush()
6769
}
68-
69-
func clear() {
70-
self._clear()
71-
self._flush()
72-
}
7370
}
7471

7572
extension NinjaRedrawingProgressAnimation {

Sources/Basics/ProgressAnimation/Concrete/PercentMultiLineProgressAnimation.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ extension PercentMultiLineProgressAnimation: ProgressAnimationProtocol2 {
6767
self.terminal.flush()
6868
}
6969

70-
func draw() {}
70+
func interleave(_ bytes: some Collection<UInt8>) {
71+
self.terminal.write(bytes)
72+
self.terminal.flush()
73+
}
7174

7275
func complete() {}
73-
74-
func clear() {}
7576
}

Sources/Basics/ProgressAnimation/Concrete/PercentRedrawingProgressAnimation.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ extension PercentRedrawingProgressAnimation: ProgressAnimationProtocol2 {
6565
self._flush()
6666
}
6767

68-
func draw() {
68+
func interleave(_ bytes: some Collection<UInt8>) {
69+
self._clear()
70+
self.terminal.write(bytes)
6971
self._draw()
7072
self._flush()
7173
}
@@ -74,11 +76,6 @@ extension PercentRedrawingProgressAnimation: ProgressAnimationProtocol2 {
7476
self._complete()
7577
self._flush()
7678
}
77-
78-
func clear() {
79-
self._clear()
80-
self._flush()
81-
}
8279
}
8380

8481
extension PercentRedrawingProgressAnimation {

Sources/Basics/ProgressAnimation/Concrete/PercentSingleLineProgressAnimation.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ extension PercentSingleLineProgressAnimation: ProgressAnimationProtocol2 {
7171
self.terminal.flush()
7272
}
7373

74-
func draw() {}
74+
func interleave(_ bytes: some Collection<UInt8>) {
75+
self.terminal.write(bytes)
76+
self.terminal.flush()
77+
}
7578

7679
func complete() {}
77-
78-
func clear() {}
7980
}

Sources/Basics/ProgressAnimation/Misc/ProgressAnimationProtocol2.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ package protocol ProgressAnimationProtocol2 {
2727
event: ProgressTaskState,
2828
at time: ContinuousClock.Instant)
2929

30+
/// Interleave some other output with the progress animation.
31+
func interleave(_ bytes: some Collection<UInt8>)
32+
3033
/// Complete the animation.
3134
func complete()
32-
33-
/// Draw the animation.
34-
func draw()
35-
36-
/// Clear the animation.
37-
func clear()
3835
}
36+
37+
extension ProgressAnimationProtocol2 {
38+
/// Interleave some other output with the progress animation.
39+
package func interleave(_ text: String) {
40+
self.interleave(text.utf8)
41+
}
42+
}

Sources/Basics/ProgressAnimation/Terminal/BlastTerminalController.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ struct BlastTerminalController {
2626

2727
/// Writes a string to the stream.
2828
mutating func write(_ text: String) {
29-
self.buffer.write(text)
29+
self.buffer.write(text.utf8)
30+
}
31+
32+
/// Writes bytes to the stream.
33+
mutating func write(_ bytes: some Collection<UInt8>) {
34+
self.buffer.write(bytes)
3035
}
3136

3237
mutating func newLine() {

Sources/Build/BuildOperation.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,6 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
828828
let progressTracker = LLBuildProgressTracker(
829829
buildSystem: self,
830830
buildExecutionContext: buildExecutionContext,
831-
outputStream: config.outputStream,
832831
progressAnimation: progressAnimation,
833832
logLevel: config.logLevel,
834833
observabilityScope: config.observabilityScope,

Sources/Build/LLBuildProgressTracker.swift

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ public protocol PackageStructureDelegate {
136136

137137
/// Convenient llbuild build system delegate implementation
138138
final class LLBuildProgressTracker: LLBuildBuildSystemDelegate, SwiftCompilerOutputParserDelegate {
139-
private let outputStream: ThreadSafeOutputByteStream
140139
private let progressAnimation: ProgressAnimationProtocol2
141140
private let logLevel: Basics.Diagnostic.Severity
142141
private weak var delegate: SPMBuildCore.BuildSystemDelegate?
@@ -159,17 +158,13 @@ final class LLBuildProgressTracker: LLBuildBuildSystemDelegate, SwiftCompilerOut
159158
init(
160159
buildSystem: SPMBuildCore.BuildSystem,
161160
buildExecutionContext: BuildExecutionContext,
162-
outputStream: OutputByteStream,
163161
progressAnimation: ProgressAnimationProtocol2,
164162
logLevel: Basics.Diagnostic.Severity,
165163
observabilityScope: ObservabilityScope,
166164
delegate: SPMBuildCore.BuildSystemDelegate?
167165
) {
168166
self.buildSystem = buildSystem
169167
self.buildExecutionContext = buildExecutionContext
170-
// FIXME: Implement a class convenience initializer that does this once they are supported
171-
// https://forums.swift.org/t/allow-self-x-in-class-convenience-initializers/15924
172-
self.outputStream = outputStream as? ThreadSafeOutputByteStream ?? ThreadSafeOutputByteStream(outputStream)
173168
self.progressAnimation = progressAnimation
174169
self.taskTracker = .init(progressAnimation: progressAnimation)
175170
self.logLevel = logLevel
@@ -256,9 +251,7 @@ final class LLBuildProgressTracker: LLBuildBuildSystemDelegate, SwiftCompilerOut
256251
self.delegate?.buildSystem(self.buildSystem, didStartCommand: BuildSystemCommand(command))
257252

258253
if self.logLevel.isVerbose {
259-
self.progressAnimation.clear()
260-
self.outputStream.send("\(command.verboseDescription)\n")
261-
self.outputStream.flush()
254+
self.progressAnimation.interleave("\(command.verboseDescription)\n")
262255
}
263256

264257
self.taskTracker.commandStarted(
@@ -341,9 +334,7 @@ final class LLBuildProgressTracker: LLBuildBuildSystemDelegate, SwiftCompilerOut
341334
.result != .failed
342335
self.queue.async {
343336
if let buffer = self.nonSwiftMessageBuffers[command.name], !shouldFilterOutput {
344-
self.progressAnimation.clear()
345-
self.outputStream.send(buffer)
346-
self.outputStream.flush()
337+
self.progressAnimation.interleave(buffer)
347338
self.nonSwiftMessageBuffers[command.name] = nil
348339
}
349340
}
@@ -365,8 +356,7 @@ final class LLBuildProgressTracker: LLBuildBuildSystemDelegate, SwiftCompilerOut
365356
command: command.name,
366357
message: errorMessage
367358
) {
368-
self.outputStream.send("note: \(adviceMessage)\n")
369-
self.outputStream.flush()
359+
self.progressAnimation.interleave("note: \(adviceMessage)\n")
370360
}
371361
}
372362
}
@@ -400,11 +390,9 @@ final class LLBuildProgressTracker: LLBuildBuildSystemDelegate, SwiftCompilerOut
400390
/// Invoked when an action taken before building emits output.
401391
/// when verboseOnly is set to true, the output will only be printed in verbose logging mode
402392
func preparationStepHadOutput(_ name: String, output: String, verboseOnly: Bool) {
403-
self.queue.async {
404-
if !verboseOnly || self.logLevel.isVerbose {
405-
self.progressAnimation.clear()
406-
self.outputStream.send("\(output.spm_chomp())\n")
407-
self.outputStream.flush()
393+
if !verboseOnly || self.logLevel.isVerbose {
394+
self.queue.async {
395+
self.progressAnimation.interleave("\(output.spm_chomp())\n")
408396
}
409397
}
410398
}
@@ -423,15 +411,11 @@ final class LLBuildProgressTracker: LLBuildBuildSystemDelegate, SwiftCompilerOut
423411
let now = ContinuousClock.now
424412
self.queue.async {
425413
if self.logLevel.isVerbose, let text = message.verboseProgressText {
426-
self.progressAnimation.clear()
427-
self.outputStream.send("\(text)\n")
428-
self.outputStream.flush()
414+
self.progressAnimation.interleave("\(text)\n")
429415
}
430416

431417
if let output = message.standardOutput {
432-
self.progressAnimation.clear()
433-
self.outputStream.send(output)
434-
self.outputStream.flush()
418+
self.progressAnimation.interleave(output)
435419

436420
// next we want to try and scoop out any errors from the output (if reasonable size, otherwise this
437421
// will be very slow), so they can later be passed to the advice provider in case of failure.
@@ -462,9 +446,7 @@ final class LLBuildProgressTracker: LLBuildBuildSystemDelegate, SwiftCompilerOut
462446
action: String
463447
) {
464448
self.queue.sync {
465-
self.progressAnimation.clear()
466-
self.outputStream.send("\(action) for \(configuration == .debug ? "debugging" : "production")...\n")
467-
self.outputStream.flush()
449+
self.progressAnimation.interleave("\(action) for \(configuration == .debug ? "debugging" : "production")...\n")
468450
}
469451
}
470452

@@ -483,10 +465,8 @@ final class LLBuildProgressTracker: LLBuildBuildSystemDelegate, SwiftCompilerOut
483465
self.queue.sync {
484466
self.progressAnimation.complete()
485467
if success {
486-
self.progressAnimation.clear()
487468
let result = self.cancelled ? "cancelled" : "complete"
488-
self.outputStream.send("\(action) \(subsetString)\(result)! (\(duration.descriptionInSeconds))\n")
489-
self.outputStream.flush()
469+
self.progressAnimation.interleave("\(action) \(subsetString)\(result)! (\(duration.descriptionInSeconds))\n")
490470
}
491471
}
492472
}

0 commit comments

Comments
 (0)