|
14 | 14 |
|
15 | 15 | import func Foundation.strdup |
16 | 16 | import func Foundation.free |
| 17 | +import class Foundation.JSONDecoder |
| 18 | +import struct Foundation.Data |
17 | 19 |
|
18 | 20 | import protocol TSCBasic.DiagnosticData |
19 | 21 | import struct TSCBasic.AbsolutePath |
@@ -81,7 +83,7 @@ internal extension swiftscan_diagnostic_severity_t { |
81 | 83 | } |
82 | 84 |
|
83 | 85 | /// Wrapper for libSwiftScan, taking care of initialization, shutdown, and dispatching dependency scanning queries. |
84 | | -internal final class SwiftScan { |
| 86 | +@_spi(Testing) public final class SwiftScan { |
85 | 87 | /// The path to the libSwiftScan dylib. |
86 | 88 | let path: AbsolutePath |
87 | 89 |
|
@@ -308,6 +310,26 @@ internal final class SwiftScan { |
308 | 310 | throw DependencyScanningError.argumentQueryFailed |
309 | 311 | } |
310 | 312 | } |
| 313 | + |
| 314 | + @_spi(Testing) public func canQueryTargetInfo() -> Bool { |
| 315 | + return api.swiftscan_compiler_target_info_query != nil && |
| 316 | + api.swiftscan_string_set_dispose != nil |
| 317 | + } |
| 318 | + |
| 319 | + @_spi(Testing) public func queryTargetInfo(invocationCommand: [String]) |
| 320 | + throws -> FrontendTargetInfo { |
| 321 | + // Create and configure the scanner invocation |
| 322 | + let invocation = api.swiftscan_scan_invocation_create() |
| 323 | + defer { api.swiftscan_scan_invocation_dispose(invocation) } |
| 324 | + withArrayOfCStrings(invocationCommand) { invocationStringArray in |
| 325 | + api.swiftscan_scan_invocation_set_argv(invocation, |
| 326 | + Int32(invocationCommand.count), |
| 327 | + invocationStringArray) |
| 328 | + } |
| 329 | + let targetInfoString = try toSwiftString(api.swiftscan_compiler_target_info_query(invocation)) |
| 330 | + let targetInfoData = Data(targetInfoString.utf8) |
| 331 | + return try JSONDecoder().decode(FrontendTargetInfo.self, from: targetInfoData) |
| 332 | + } |
311 | 333 | } |
312 | 334 |
|
313 | 335 | // Used for testing purposes only |
@@ -347,6 +369,10 @@ private extension swiftscan_functions_t { |
347 | 369 | self.swiftscan_compiler_supported_features_query = |
348 | 370 | try loadOptional("swiftscan_compiler_supported_features_query") |
349 | 371 |
|
| 372 | + // Target Info query |
| 373 | + self.swiftscan_compiler_target_info_query = |
| 374 | + try loadOptional("swiftscan_compiler_target_info_query") |
| 375 | + |
350 | 376 | // Dependency scanner serialization/deserialization features |
351 | 377 | self.swiftscan_scanner_cache_serialize = |
352 | 378 | try loadOptional("swiftscan_scanner_cache_serialize") |
|
0 commit comments