@@ -56,7 +56,7 @@ public enum DependencyScanningError: Error, DiagnosticData {
5656}
5757
5858/// 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 {
6060 /// The path to the libSwiftScan dylib.
6161 let path : AbsolutePath
6262
@@ -251,6 +251,26 @@ internal final class SwiftScan {
251251 throw DependencyScanningError . argumentQueryFailed
252252 }
253253 }
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+ }
254274}
255275
256276// Used for testing purposes only
@@ -290,6 +310,10 @@ private extension swiftscan_functions_t {
290310 self . swiftscan_compiler_supported_features_query =
291311 try loadOptional ( " swiftscan_compiler_supported_features_query " )
292312
313+ // Target Info query
314+ self . swiftscan_compiler_target_info_query =
315+ try loadOptional ( " swiftscan_compiler_target_info_query " )
316+
293317 // Dependency scanner serialization/deserialization features
294318 self . swiftscan_scanner_cache_serialize =
295319 try loadOptional ( " swiftscan_scanner_cache_serialize " )
0 commit comments