@@ -55,7 +55,7 @@ public enum DependencyScanningError: Error, DiagnosticData {
5555}
5656
5757/// 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 {
5959 /// The path to the libSwiftScan dylib.
6060 let path : AbsolutePath
6161
@@ -250,6 +250,26 @@ internal final class SwiftScan {
250250 throw DependencyScanningError . argumentQueryFailed
251251 }
252252 }
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+ }
253273}
254274
255275// Used for testing purposes only
@@ -289,6 +309,10 @@ private extension swiftscan_functions_t {
289309 self . swiftscan_compiler_supported_features_query =
290310 try loadOptional ( " swiftscan_compiler_supported_features_query " )
291311
312+ // Target Info query
313+ self . swiftscan_compiler_target_info_query =
314+ try loadOptional ( " swiftscan_compiler_target_info_query " )
315+
292316 // Dependency scanner serialization/deserialization features
293317 self . swiftscan_scanner_cache_serialize =
294318 try loadOptional ( " swiftscan_scanner_cache_serialize " )
0 commit comments