@@ -56,7 +56,7 @@ public enum DependencyScanningError: Error, DiagnosticData {
56
56
}
57
57
58
58
/// Wrapper for libSwiftScan, taking care of initialization, shutdown, and dispatching dependency scanning queries.
59
- internal final class SwiftScan {
59
+ @ _spi ( Testing ) public final class SwiftScan {
60
60
/// The path to the libSwiftScan dylib.
61
61
let path : AbsolutePath
62
62
@@ -251,6 +251,26 @@ internal final class SwiftScan {
251
251
throw DependencyScanningError . argumentQueryFailed
252
252
}
253
253
}
254
+
255
+ @_spi ( Testing) public func canQueryTargetInfo( ) -> Bool {
256
+ return api. swiftscan_compiler_target_info_query != nil &&
257
+ api. swiftscan_string_set_dispose != nil
258
+ }
259
+
260
+ @_spi ( Testing) public func queryTargetInfo( invocationCommand: [ String ] )
261
+ throws -> FrontendTargetInfo {
262
+ // Create and configure the scanner invocation
263
+ let invocation = api. swiftscan_scan_invocation_create ( )
264
+ defer { api. swiftscan_scan_invocation_dispose ( invocation) }
265
+ withArrayOfCStrings ( invocationCommand) { invocationStringArray in
266
+ api. swiftscan_scan_invocation_set_argv ( invocation,
267
+ Int32 ( invocationCommand. count) ,
268
+ invocationStringArray)
269
+ }
270
+ let targetInfoString = try toSwiftString ( api. swiftscan_compiler_target_info_query ( invocation) )
271
+ let targetInfoData = Data ( targetInfoString. utf8)
272
+ return try JSONDecoder ( ) . decode ( FrontendTargetInfo . self, from: targetInfoData)
273
+ }
254
274
}
255
275
256
276
// Used for testing purposes only
@@ -290,6 +310,10 @@ private extension swiftscan_functions_t {
290
310
self . swiftscan_compiler_supported_features_query =
291
311
try loadOptional ( " swiftscan_compiler_supported_features_query " )
292
312
313
+ // Target Info query
314
+ self . swiftscan_compiler_target_info_query =
315
+ try loadOptional ( " swiftscan_compiler_target_info_query " )
316
+
293
317
// Dependency scanner serialization/deserialization features
294
318
self . swiftscan_scanner_cache_serialize =
295
319
try loadOptional ( " swiftscan_scanner_cache_serialize " )
0 commit comments