@@ -24,21 +24,21 @@ struct CMakeSmokeTest: CommandPlugin {
24
24
}
25
25
26
26
guard let cmakePath = args. extractOption ( named: " cmake-path " ) . last else { throw Errors . missingRequiredOption ( " --cmake-path " ) }
27
- print ( " using cmake at \( cmakePath) " )
27
+ Diagnostics . progress ( " using cmake at \( cmakePath) " )
28
28
let cmakeURL = URL ( filePath: cmakePath)
29
29
guard let ninjaPath = args. extractOption ( named: " ninja-path " ) . last else { throw Errors . missingRequiredOption ( " --ninja-path " ) }
30
- print ( " using ninja at \( ninjaPath) " )
30
+ Diagnostics . progress ( " using ninja at \( ninjaPath) " )
31
31
let ninjaURL = URL ( filePath: ninjaPath)
32
32
let sysrootPath = args. extractOption ( named: " sysroot-path " ) . last
33
33
if let sysrootPath {
34
- print ( " using sysroot at \( sysrootPath) " )
34
+ Diagnostics . progress ( " using sysroot at \( sysrootPath) " )
35
35
}
36
36
37
37
let moduleCachePath = context. pluginWorkDirectoryURL. appending ( component: " module-cache " ) . path ( )
38
38
39
39
let swiftBuildURL = context. package . directoryURL
40
40
let swiftBuildBuildURL = context. pluginWorkDirectoryURL. appending ( component: " swift-build " )
41
- print ( " swift-build: \( swiftBuildURL. path ( ) ) " )
41
+ Diagnostics . progress ( " swift-build: \( swiftBuildURL. path ( ) ) " )
42
42
43
43
let swiftToolsSupportCoreURL = try findDependency ( " swift-tools-support-core " , pluginContext: context)
44
44
let swiftToolsSupportCoreBuildURL = context. pluginWorkDirectoryURL. appending ( component: " swift-tools-support-core " )
@@ -82,37 +82,37 @@ struct CMakeSmokeTest: CommandPlugin {
82
82
" -DCMAKE_Swift_FLAGS=' \( sharedSwiftFlags. joined ( separator: " " ) ) ' "
83
83
] + cMakeProjectArgs
84
84
85
- print ( " Building swift-tools-support-core " )
85
+ Diagnostics . progress ( " Building swift-tools-support-core " )
86
86
try await Process . checkNonZeroExit ( url: cmakeURL, arguments: sharedCMakeArgs + [ swiftToolsSupportCoreURL. path ( ) ] , workingDirectory: swiftToolsSupportCoreBuildURL)
87
87
try await Process . checkNonZeroExit ( url: ninjaURL, arguments: [ ] , workingDirectory: swiftToolsSupportCoreBuildURL)
88
- print ( " Built swift-tools-support-core " )
88
+ Diagnostics . progress ( " Built swift-tools-support-core " )
89
89
90
90
if hostOS != . macOS {
91
- print ( " Building swift-system " )
91
+ Diagnostics . progress ( " Building swift-system " )
92
92
try await Process . checkNonZeroExit ( url: cmakeURL, arguments: sharedCMakeArgs + [ swiftSystemURL. path ( ) ] , workingDirectory: swiftSystemBuildURL)
93
93
try await Process . checkNonZeroExit ( url: ninjaURL, arguments: [ ] , workingDirectory: swiftSystemBuildURL)
94
- print ( " Built swift-system " )
94
+ Diagnostics . progress ( " Built swift-system " )
95
95
}
96
96
97
- print ( " Building llbuild " )
97
+ Diagnostics . progress ( " Building llbuild " )
98
98
try await Process . checkNonZeroExit ( url: cmakeURL, arguments: sharedCMakeArgs + [ " -DLLBUILD_SUPPORT_BINDINGS:=Swift " , llbuildURL. path ( ) ] , workingDirectory: llbuildBuildURL)
99
99
try await Process . checkNonZeroExit ( url: ninjaURL, arguments: [ ] , workingDirectory: llbuildBuildURL)
100
- print ( " Built llbuild " )
100
+ Diagnostics . progress ( " Built llbuild " )
101
101
102
- print ( " Building swift-argument-parser " )
102
+ Diagnostics . progress ( " Building swift-argument-parser " )
103
103
try await Process . checkNonZeroExit ( url: cmakeURL, arguments: sharedCMakeArgs + [ " -DBUILD_TESTING=NO " , " -DBUILD_EXAMPLES=NO " , swiftArgumentParserURL. path ( ) ] , workingDirectory: swiftArgumentParserBuildURL)
104
104
try await Process . checkNonZeroExit ( url: ninjaURL, arguments: [ ] , workingDirectory: swiftArgumentParserBuildURL)
105
- print ( " Built swift-argument-parser " )
105
+ Diagnostics . progress ( " Built swift-argument-parser " )
106
106
107
- print ( " Building swift-driver " )
107
+ Diagnostics . progress ( " Building swift-driver " )
108
108
try await Process . checkNonZeroExit ( url: cmakeURL, arguments: sharedCMakeArgs + [ swiftDriverURL. path ( ) ] , workingDirectory: swiftDriverBuildURL)
109
109
try await Process . checkNonZeroExit ( url: ninjaURL, arguments: [ ] , workingDirectory: swiftDriverBuildURL)
110
- print ( " Built swift-driver " )
110
+ Diagnostics . progress ( " Built swift-driver " )
111
111
112
- print ( " Building swift-build in \( swiftBuildBuildURL) " )
112
+ Diagnostics . progress ( " Building swift-build in \( swiftBuildBuildURL) " )
113
113
try await Process . checkNonZeroExit ( url: cmakeURL, arguments: sharedCMakeArgs + [ swiftBuildURL. path ( ) ] , workingDirectory: swiftBuildBuildURL)
114
114
try await Process . checkNonZeroExit ( url: ninjaURL, arguments: [ ] , workingDirectory: swiftBuildBuildURL)
115
- print ( " Built swift-build " )
115
+ Diagnostics . progress ( " Built swift-build " )
116
116
}
117
117
118
118
func findDependency( _ name: String , pluginContext: PluginContext ) throws -> URL {
@@ -132,7 +132,7 @@ struct CMakeSmokeTest: CommandPlugin {
132
132
throw Errors . missingRepository ( name)
133
133
}
134
134
let dependencyURL = dependency. directoryURL
135
- print ( " \( name) : \( dependencyURL. path ( ) ) " )
135
+ Diagnostics . progress ( " \( name) : \( dependencyURL. path ( ) ) " )
136
136
guard FileManager . default. fileExists ( atPath: dependencyURL. path ( ) ) else {
137
137
throw Errors . missingRepository ( dependencyURL. path ( ) )
138
138
}
@@ -167,13 +167,19 @@ enum OS {
167
167
168
168
extension Process {
169
169
func run( ) async throws {
170
+ Diagnostics . progress ( " entered run " )
170
171
try await withCheckedThrowingContinuation { continuation in
172
+ Diagnostics . progress ( " continuation " )
171
173
terminationHandler = { _ in
174
+ Diagnostics . progress ( " termination handler " )
172
175
continuation. resume ( )
176
+ Diagnostics . progress ( " resumed continuation " )
173
177
}
174
178
175
179
do {
180
+ Diagnostics . progress ( " pre-run " )
176
181
try run ( )
182
+ Diagnostics . progress ( " post-run " )
177
183
} catch {
178
184
terminationHandler = nil
179
185
continuation. resume ( throwing: error)
@@ -182,12 +188,30 @@ extension Process {
182
188
}
183
189
184
190
static func checkNonZeroExit( url: URL , arguments: [ String ] , workingDirectory: URL , environment: [ String : String ] ? = nil ) async throws {
185
- print ( " \( url. path ( ) ) \( arguments. joined ( separator: " " ) ) " )
191
+ Diagnostics . progress ( " \( url. path ( ) ) \( arguments. joined ( separator: " " ) ) " )
186
192
let process = Process ( )
187
193
process. executableURL = url
188
194
process. arguments = arguments
189
195
process. currentDirectoryURL = workingDirectory
190
196
process. environment = environment
197
+ let outputPipe = Pipe ( )
198
+ let errorPipe = Pipe ( )
199
+ outputPipe. fileHandleForReading. readabilityHandler = { ( fh : FileHandle ) -> Void in
200
+ Diagnostics . progress ( " output " )
201
+ let data = ( try ? fh. read ( upToCount: Int . max) ) ?? Data ( )
202
+ if !data. isEmpty {
203
+ Diagnostics . progress ( String ( decoding: data, as: UTF8 . self) )
204
+ }
205
+ }
206
+ errorPipe. fileHandleForReading. readabilityHandler = { ( fh : FileHandle ) -> Void in
207
+ Diagnostics . progress ( " error " )
208
+ let data = ( try ? fh. read ( upToCount: Int . max) ) ?? Data ( )
209
+ if !data. isEmpty {
210
+ Diagnostics . progress ( String ( decoding: data, as: UTF8 . self) )
211
+ }
212
+ }
213
+ process. standardOutput = nil
214
+ process. standardError = nil
191
215
try await process. run ( )
192
216
if process. terminationStatus != 0 {
193
217
throw Errors . processError ( terminationReason: process. terminationReason, terminationStatus: process. terminationStatus)
0 commit comments