@@ -19,135 +19,151 @@ import struct SWBLLBuild.Diagnostic
19
19
import Foundation
20
20
21
21
fileprivate class LoggingDelegate : BuildSystemDelegate {
22
- let queue = SWBQueue ( label: " LLBuildTests.LoggingDelegate.queue " , qos: UserDefaults . defaultRequestQoS)
23
22
var buildSystem : BuildSystem ? = nil
24
23
let fs : ( any SWBLLBuild . FileSystem ) ?
25
24
let fsProxy : any FSProxy
26
- var log : [ String ] = [ ]
27
- var errors : [ String ] = [ ]
25
+ private struct Output : Sendable {
26
+ var log : [ String ] = [ ]
27
+ var errors : [ String ] = [ ]
28
+ }
29
+ private let output = SWBMutex < Output > ( . init( ) )
28
30
let ignoreStatusChanges : Bool
29
31
32
+ var log : [ String ] {
33
+ output. withLock { $0. log }
34
+ }
35
+
36
+ var errors : [ String ] {
37
+ output. withLock { $0. errors }
38
+ }
39
+
30
40
init ( fs: any FSProxy , ignoreStatusChanges: Bool = false ) {
31
41
self . fs = SWBLLBuild . FileSystemImpl ( fs)
32
42
self . fsProxy = fs
33
43
self . ignoreStatusChanges = ignoreStatusChanges
34
44
}
35
45
46
+ func append( log: String ) {
47
+ output. withLock { output in
48
+ output. log. append ( log)
49
+ }
50
+ }
51
+
36
52
func lookupTool( _ name: String ) -> ( any Tool ) ? {
37
53
return nil
38
54
}
39
55
40
56
func hadCommandFailure( ) {
41
- queue . blocking_sync {
42
- self . log. append ( " had-command-failure " )
57
+ output . withLock { output in
58
+ output . log. append ( " had-command-failure " )
43
59
}
44
60
buildSystem? . cancel ( )
45
61
}
46
62
47
63
func handleDiagnostic( _ diagnostic: Diagnostic ) {
48
- queue . blocking_sync {
49
- self . log. append ( " \( diagnostic. kind) : \( diagnostic. message) " )
50
- self . errors. append ( " \( diagnostic. kind) : \( diagnostic. message) " )
64
+ output . withLock { output in
65
+ output . log. append ( " \( diagnostic. kind) : \( diagnostic. message) " )
66
+ output . errors. append ( " \( diagnostic. kind) : \( diagnostic. message) " )
51
67
}
52
68
}
53
69
54
70
func commandStatusChanged( _ command: Command , kind: CommandStatusKind ) {
55
71
if !ignoreStatusChanges {
56
- queue . blocking_sync {
57
- self . log. append ( " command-status-changed: \( command. name) , to: \( kind) " )
72
+ output . withLock { output in
73
+ output . log. append ( " command-status-changed: \( command. name) , to: \( kind) " )
58
74
}
59
75
}
60
76
}
61
77
func commandPreparing( _ command: Command ) {
62
- queue . blocking_sync {
63
- self . log. append ( " command-preparing: \( command. name) " )
78
+ output . withLock { output in
79
+ output . log. append ( " command-preparing: \( command. name) " )
64
80
}
65
81
}
66
82
func commandStarted( _ command: Command ) {
67
- queue . blocking_sync {
68
- self . log. append ( " command-started: \( command. name) " )
83
+ output . withLock { output in
84
+ output . log. append ( " command-started: \( command. name) " )
69
85
}
70
86
}
71
87
func shouldCommandStart( _ command: Command ) -> Bool {
72
- queue . blocking_sync {
73
- self . log. append ( " should-command-start: \( command. name) " )
88
+ output . withLock { output in
89
+ output . log. append ( " should-command-start: \( command. name) " )
74
90
}
75
91
return true
76
92
}
77
93
func commandFinished( _ command: Command , result: CommandResult ) {
78
- queue . blocking_sync {
79
- self . log. append ( " command-finished: \( command. name) " )
94
+ output . withLock { output in
95
+ output . log. append ( " command-finished: \( command. name) " )
80
96
}
81
97
}
82
98
func commandFoundDiscoveredDependency( _ command: Command , path: String , kind: DiscoveredDependencyKind ) {
83
- queue . blocking_sync {
84
- self . log. append ( " command-found-discovered-dependency: \( path) \( kind) " )
99
+ output . withLock { output in
100
+ output . log. append ( " command-found-discovered-dependency: \( path) \( kind) " )
85
101
}
86
102
}
87
103
func commandHadError( _ command: Command , message: String ) {
88
- queue . blocking_sync {
89
- self . log. append ( " command-had-error: \( command. name) : \( message) " )
90
- self . errors. append ( " command-had-error: \( command. name) : \( message) " )
104
+ output . withLock { output in
105
+ output . log. append ( " command-had-error: \( command. name) : \( message) " )
106
+ output . errors. append ( " command-had-error: \( command. name) : \( message) " )
91
107
}
92
108
}
93
109
func commandHadNote( _ command: Command , message: String ) {
94
- queue . blocking_sync {
95
- self . log. append ( " command-had-note: \( command. name) : \( message) " )
110
+ output . withLock { output in
111
+ output . log. append ( " command-had-note: \( command. name) : \( message) " )
96
112
}
97
113
}
98
114
func commandHadWarning( _ command: Command , message: String ) {
99
- queue . blocking_sync {
100
- self . log. append ( " command-had-warning: \( command. name) : \( message) " )
115
+ output . withLock { output in
116
+ output . log. append ( " command-had-warning: \( command. name) : \( message) " )
101
117
}
102
118
}
103
119
func commandProcessStarted( _ command: Command , process: ProcessHandle ) {
104
- queue . blocking_sync {
105
- self . log. append ( " command-process-started: \( command. name) -- \( command. description) " )
120
+ output . withLock { output in
121
+ output . log. append ( " command-process-started: \( command. name) -- \( command. description) " )
106
122
}
107
123
}
108
124
func commandProcessHadError( _ command: Command , process: ProcessHandle , message: String ) {
109
- queue . blocking_sync {
110
- self . log. append ( " command-process-error: \( message) " )
125
+ output . withLock { output in
126
+ output . log. append ( " command-process-error: \( message) " )
111
127
}
112
128
}
113
129
func commandProcessHadOutput( _ command: Command , process: ProcessHandle , data: [ UInt8 ] ) {
114
- queue . blocking_sync {
115
- self . log. append ( " command-process-output: \( command. name) : \( ByteString ( data) . bytes. asReadableString ( ) . debugDescription) " )
130
+ output . withLock { output in
131
+ output . log. append ( " command-process-output: \( command. name) : \( ByteString ( data) . bytes. asReadableString ( ) . debugDescription) " )
116
132
}
117
133
}
118
134
func commandProcessFinished( _ command: Command , process: ProcessHandle , result: CommandExtendedResult ) {
119
- queue . blocking_sync {
120
- self . log. append ( " command-process-finished: \( command. name) " )
135
+ output . withLock { output in
136
+ output . log. append ( " command-process-finished: \( command. name) " )
121
137
}
122
138
}
123
139
func determinedRuleNeedsToRun( _ rule: BuildKey , reason: RuleRunReason , inputRule: BuildKey ? ) {
124
- queue . blocking_sync {
125
- self . log. append ( " determined-rule-needs-to-run: \( rule. description) " )
140
+ output . withLock { output in
141
+ output . log. append ( " determined-rule-needs-to-run: \( rule. description) " )
126
142
}
127
143
}
128
144
func cycleDetected( rules: [ BuildKey ] ) {
129
- queue . blocking_sync {
130
- self . log. append ( " cycle-detected: \( rules. map { $0. key } ) " )
145
+ output . withLock { output in
146
+ output . log. append ( " cycle-detected: \( rules. map { $0. key } ) " )
131
147
}
132
148
}
133
149
func commandCannotBuildOutputDueToMissingInputs( _ command: Command , output: BuildKey , inputs: [ BuildKey ] ) {
134
- queue . blocking_sync {
150
+ self . output . withLock { outputBox in
135
151
let msg = " commandCannotBuildOutputDueToMissingInputs: \( command. name) \( output. key) \( inputs. map { $0. key } ) "
136
- self . log. append ( msg)
137
- self . errors. append ( msg)
152
+ outputBox . log. append ( msg)
153
+ outputBox . errors. append ( msg)
138
154
}
139
155
}
140
156
func cannotBuildNodeDueToMultipleProducers( output: BuildKey , commands: [ Command ] ) {
141
- queue . blocking_sync {
157
+ self . output . withLock { outputBox in
142
158
let msg = " cannotBuildNodeDueToMultipleProducers: \( output. key) \( commands. map { $0. name } ) "
143
- self . log. append ( msg)
144
- self . errors. append ( msg)
159
+ outputBox . log. append ( msg)
160
+ outputBox . errors. append ( msg)
145
161
}
146
162
}
147
163
148
164
func shouldResolveCycle( rules: [ BuildKey ] , candidate: BuildKey , action: CycleAction ) -> Bool {
149
- queue . blocking_sync {
150
- self . log. append ( " should-resolve-cycle: \( rules. map { $0. key } ) " )
165
+ output . withLock { output in
166
+ output . log. append ( " should-resolve-cycle: \( rules. map { $0. key } ) " )
151
167
}
152
168
return false ;
153
169
}
@@ -521,7 +537,7 @@ fileprivate class LoggingDelegate: BuildSystemDelegate {
521
537
}
522
538
523
539
func execute( _ command: Command , _ commandInterface: BuildSystemCommandInterface ) -> Bool {
524
- delegate. log . append ( " write-command: execute " )
540
+ delegate. append ( log : " write-command: execute " )
525
541
do {
526
542
try delegate. fsProxy. write ( Static . outputPath, contents: [ ] )
527
543
return true
0 commit comments