@@ -181,46 +181,39 @@ extension Toolchain {
181
181
}
182
182
183
183
extension Driver {
184
- @_spi ( Testing) public static func queryTargetInfoInProcess( of toolchain: Toolchain ,
184
+ @_spi ( Testing) public static func queryTargetInfoInProcess( libSwiftScanInstance: SwiftScan ,
185
+ toolchain: Toolchain ,
185
186
fileSystem: FileSystem ,
186
187
workingDirectory: AbsolutePath ? ,
187
- invocationCommand: [ String ] ) throws -> FrontendTargetInfo ? {
188
- let optionalSwiftScanLibPath = try toolchain. lookupSwiftScanLib ( )
189
- if let swiftScanLibPath = optionalSwiftScanLibPath,
190
- fileSystem. exists ( swiftScanLibPath) {
191
- let libSwiftScanInstance = try SwiftScan ( dylib: swiftScanLibPath)
192
- if libSwiftScanInstance. canQueryTargetInfo ( ) {
193
- let cwd = try workingDirectory ?? fileSystem. tempDirectory
194
- let compilerExecutablePath = try toolchain. resolvedTool ( . swiftCompiler) . path
195
- let targetInfoData =
196
- try libSwiftScanInstance. queryTargetInfoJSON ( workingDirectory: cwd,
197
- compilerExecutablePath: compilerExecutablePath,
198
- invocationCommand: invocationCommand)
199
- do {
200
- return try JSONDecoder ( ) . decode ( FrontendTargetInfo . self, from: targetInfoData)
201
- } catch let decodingError as DecodingError {
202
- let stringToDecode = String ( data: targetInfoData, encoding: . utf8)
203
- let errorDesc : String
204
- switch decodingError {
205
- case let . typeMismatch( type, context) :
206
- errorDesc = " type mismatch: \( type) , path: \( context. codingPath) "
207
- case let . valueNotFound( type, context) :
208
- errorDesc = " value missing: \( type) , path: \( context. codingPath) "
209
- case let . keyNotFound( key, context) :
210
- errorDesc = " key missing: \( key) , path: \( context. codingPath) "
211
- case let . dataCorrupted( context) :
212
- errorDesc = " data corrupted at path: \( context. codingPath) "
213
- @unknown default :
214
- errorDesc = " unknown decoding error "
215
- }
216
- throw Error . unableToDecodeFrontendTargetInfo (
217
- stringToDecode,
218
- invocationCommand,
219
- errorDesc)
220
- }
188
+ invocationCommand: [ String ] ) throws -> FrontendTargetInfo {
189
+ let cwd = try workingDirectory ?? fileSystem. tempDirectory
190
+ let compilerExecutablePath = try toolchain. resolvedTool ( . swiftCompiler) . path
191
+ let targetInfoData =
192
+ try libSwiftScanInstance. queryTargetInfoJSON ( workingDirectory: cwd,
193
+ compilerExecutablePath: compilerExecutablePath,
194
+ invocationCommand: invocationCommand)
195
+ do {
196
+ return try JSONDecoder ( ) . decode ( FrontendTargetInfo . self, from: targetInfoData)
197
+ } catch let decodingError as DecodingError {
198
+ let stringToDecode = String ( data: targetInfoData, encoding: . utf8)
199
+ let errorDesc : String
200
+ switch decodingError {
201
+ case let . typeMismatch( type, context) :
202
+ errorDesc = " type mismatch: \( type) , path: \( context. codingPath) "
203
+ case let . valueNotFound( type, context) :
204
+ errorDesc = " value missing: \( type) , path: \( context. codingPath) "
205
+ case let . keyNotFound( key, context) :
206
+ errorDesc = " key missing: \( key) , path: \( context. codingPath) "
207
+ case let . dataCorrupted( context) :
208
+ errorDesc = " data corrupted at path: \( context. codingPath) "
209
+ @unknown default :
210
+ errorDesc = " unknown decoding error "
221
211
}
212
+ throw Error . unableToDecodeFrontendTargetInfo (
213
+ stringToDecode,
214
+ invocationCommand,
215
+ errorDesc)
222
216
}
223
- return nil
224
217
}
225
218
226
219
static func computeTargetInfo( target: Triple ? ,
@@ -231,6 +224,7 @@ extension Driver {
231
224
requiresInPlaceExecution: Bool = false ,
232
225
useStaticResourceDir: Bool = false ,
233
226
swiftCompilerPrefixArgs: [ String ] ,
227
+ libSwiftScan: SwiftScan ? ,
234
228
toolchain: Toolchain ,
235
229
fileSystem: FileSystem ,
236
230
workingDirectory: AbsolutePath ? ,
@@ -243,20 +237,19 @@ extension Driver {
243
237
requiresInPlaceExecution: requiresInPlaceExecution,
244
238
useStaticResourceDir: useStaticResourceDir,
245
239
swiftCompilerPrefixArgs: swiftCompilerPrefixArgs)
246
- var command = try Self . itemizedJobCommand ( of: frontendTargetInfoJob,
247
- useResponseFiles: . disabled,
248
- using: executor. resolver)
249
- Self . sanitizeCommandForLibScanInvocation ( & command)
250
-
251
- do {
252
- if let targetInfo =
253
- try Self . queryTargetInfoInProcess ( of: toolchain, fileSystem: fileSystem,
254
- workingDirectory: workingDirectory,
255
- invocationCommand: command) {
256
- return targetInfo
240
+ if let libSwiftScanInstance = libSwiftScan,
241
+ libSwiftScanInstance. canQueryTargetInfo ( ) {
242
+ do {
243
+ var command = try Self . itemizedJobCommand ( of: frontendTargetInfoJob,
244
+ useResponseFiles: . disabled,
245
+ using: executor. resolver)
246
+ Self . sanitizeCommandForLibScanInvocation ( & command)
247
+ return try Self . queryTargetInfoInProcess ( libSwiftScanInstance: libSwiftScanInstance, toolchain: toolchain,
248
+ fileSystem: fileSystem, workingDirectory: workingDirectory,
249
+ invocationCommand: command)
250
+ } catch {
251
+ diagnosticsEngine. emit ( . remark_inprocess_target_info_query_failed( error. localizedDescription) )
257
252
}
258
- } catch {
259
- diagnosticsEngine. emit ( . remark_inprocess_target_info_query_failed( error. localizedDescription) )
260
253
}
261
254
262
255
// Fallback: Invoke `swift-frontend -print-target-info` and decode the output
0 commit comments