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