|
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 |
@@ -80,7 +82,7 @@ internal extension swiftscan_diagnostic_severity_t { |
80 | 82 | } |
81 | 83 |
|
82 | 84 | /// Wrapper for libSwiftScan, taking care of initialization, shutdown, and dispatching dependency scanning queries. |
83 | | -internal final class SwiftScan { |
| 85 | +@_spi(Testing) public final class SwiftScan { |
84 | 86 | /// The path to the libSwiftScan dylib. |
85 | 87 | let path: AbsolutePath |
86 | 88 |
|
@@ -311,6 +313,26 @@ internal final class SwiftScan { |
311 | 313 | throw DependencyScanningError.argumentQueryFailed |
312 | 314 | } |
313 | 315 | } |
| 316 | + |
| 317 | + @_spi(Testing) public func canQueryTargetInfo() -> Bool { |
| 318 | + return api.swiftscan_compiler_target_info_query != nil && |
| 319 | + api.swiftscan_string_set_dispose != nil |
| 320 | + } |
| 321 | + |
| 322 | + @_spi(Testing) public func queryTargetInfo(invocationCommand: [String]) |
| 323 | + throws -> FrontendTargetInfo { |
| 324 | + // Create and configure the scanner invocation |
| 325 | + let invocation = api.swiftscan_scan_invocation_create() |
| 326 | + defer { api.swiftscan_scan_invocation_dispose(invocation) } |
| 327 | + withArrayOfCStrings(invocationCommand) { invocationStringArray in |
| 328 | + api.swiftscan_scan_invocation_set_argv(invocation, |
| 329 | + Int32(invocationCommand.count), |
| 330 | + invocationStringArray) |
| 331 | + } |
| 332 | + let targetInfoString = try toSwiftString(api.swiftscan_compiler_target_info_query(invocation)) |
| 333 | + let targetInfoData = Data(targetInfoString.utf8) |
| 334 | + return try JSONDecoder().decode(FrontendTargetInfo.self, from: targetInfoData) |
| 335 | + } |
314 | 336 | } |
315 | 337 |
|
316 | 338 | // 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