Skip to content

Commit dc63fac

Browse files
committed
Switch over to using V2 of the swiftscan_compiler_target_info_query API
This new version takes the path to the compiler executable as a parameter, in order for libSwiftScan to compute compiler-relative portions of runtimeLibraryPaths, runtimeResourcePath, etc.
1 parent f9e905d commit dc63fac

File tree

5 files changed

+30
-44
lines changed

5 files changed

+30
-44
lines changed

Sources/CSwiftScan/include/swiftscan_header.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ typedef struct {
211211

212212
//=== Target Info Functions-------- ---------------------------------------===//
213213
swiftscan_string_ref_t
214-
(*swiftscan_compiler_target_info_query)(swiftscan_scan_invocation_t);
214+
(*swiftscan_compiler_target_info_query_v2)(swiftscan_scan_invocation_t,
215+
const char *);
215216

216217
//=== Functionality Query Functions ---------------------------------------===//
217218
swiftscan_string_set_t *

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2906,18 +2906,11 @@ extension Driver {
29062906
let frontendOverride = try FrontendOverride(&parsedOptions, diagnosticsEngine)
29072907
frontendOverride.setUpForTargetInfo(toolchain)
29082908
defer { frontendOverride.setUpForCompilation(toolchain) }
2909-
return try executor.execute(
2910-
job: toolchain.printTargetInfoJob(target: nil, targetVariant: nil,
2911-
swiftCompilerPrefixArgs:
2912-
frontendOverride.prefixArgsForTargetInfo),
2913-
capturingJSONOutputAs: FrontendTargetInfo.self,
2914-
forceResponseFiles: false,
2915-
recordedInputModificationDates: [:]).target.triple
2916-
// return try Self.computeTargetInfo(target: nil, targetVariant: nil,
2917-
// swiftCompilerPrefixArgs: frontendOverride.prefixArgsForTargetInfo,
2918-
// toolchain: toolchain, fileSystem: fileSystem,
2919-
// workingDirectory: workingDirectory,
2920-
// executor: executor).target.triple
2909+
return try Self.computeTargetInfo(target: nil, targetVariant: nil,
2910+
swiftCompilerPrefixArgs: frontendOverride.prefixArgsForTargetInfo,
2911+
toolchain: toolchain, fileSystem: fileSystem,
2912+
workingDirectory: workingDirectory,
2913+
executor: executor).target.triple
29212914
}
29222915

29232916
static func computeToolchain(
@@ -2972,28 +2965,16 @@ extension Driver {
29722965

29732966
// Query the frontend for target information.
29742967
do {
2975-
var info: FrontendTargetInfo = try executor.execute(
2976-
job: toolchain.printTargetInfoJob(
2977-
target: explicitTarget, targetVariant: explicitTargetVariant,
2978-
sdkPath: sdkPath, resourceDirPath: resourceDirPath,
2979-
runtimeCompatibilityVersion:
2980-
parsedOptions.getLastArgument(.runtimeCompatibilityVersion)?.asSingle,
2981-
useStaticResourceDir: useStaticResourceDir,
2982-
swiftCompilerPrefixArgs: frontendOverride.prefixArgsForTargetInfo
2983-
),
2984-
capturingJSONOutputAs: FrontendTargetInfo.self,
2985-
forceResponseFiles: false,
2986-
recordedInputModificationDates: [:])
2987-
// var info: FrontendTargetInfo =
2988-
// try Self.computeTargetInfo(target: explicitTarget, targetVariant: explicitTargetVariant,
2989-
// sdkPath: sdkPath, resourceDirPath: resourceDirPath,
2990-
// runtimeCompatibilityVersion:
2991-
// parsedOptions.getLastArgument(.runtimeCompatibilityVersion)?.asSingle,
2992-
// useStaticResourceDir: useStaticResourceDir,
2993-
// swiftCompilerPrefixArgs: frontendOverride.prefixArgsForTargetInfo,
2994-
// toolchain: toolchain, fileSystem: fileSystem,
2995-
// workingDirectory: workingDirectory,
2996-
// executor: executor)
2968+
var info: FrontendTargetInfo =
2969+
try Self.computeTargetInfo(target: explicitTarget, targetVariant: explicitTargetVariant,
2970+
sdkPath: sdkPath, resourceDirPath: resourceDirPath,
2971+
runtimeCompatibilityVersion:
2972+
parsedOptions.getLastArgument(.runtimeCompatibilityVersion)?.asSingle,
2973+
useStaticResourceDir: useStaticResourceDir,
2974+
swiftCompilerPrefixArgs: frontendOverride.prefixArgsForTargetInfo,
2975+
toolchain: toolchain, fileSystem: fileSystem,
2976+
workingDirectory: workingDirectory,
2977+
executor: executor)
29972978

29982979
// Parse the runtime compatibility version. If present, it will override
29992980
// what is reported by the frontend.

Sources/SwiftDriver/Execution/DriverExecutor.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ extension DriverExecutor {
8787
capturingJSONOutputAs outputType: T.Type,
8888
forceResponseFiles: Bool,
8989
recordedInputModificationDates: [TypedVirtualPath: TimePoint]) throws -> T {
90-
//print(">>> EXEC: \(try self.description(of: job, forceResponseFiles: false))")
9190
let result = try execute(job: job,
9291
forceResponseFiles: forceResponseFiles,
9392
recordedInputModificationDates: recordedInputModificationDates)

Sources/SwiftDriver/Jobs/PrintTargetInfoJob.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,11 @@ extension Driver {
188188
fileSystem.exists(swiftScanLibPath) {
189189
let libSwiftScanInstance = try SwiftScan(dylib: swiftScanLibPath)
190190
if libSwiftScanInstance.canQueryTargetInfo() {
191-
let cwd = workingDirectory ?? fileSystem.currentWorkingDirectory!
191+
let cwd = try workingDirectory ?? fileSystem.currentWorkingDirectory ?? fileSystem.tempDirectory
192+
let compilerExecutablePath = try toolchain.resolvedTool(.swiftCompiler).path
192193
let targetInfoData =
193194
try libSwiftScanInstance.queryTargetInfoJSON(workingDirectory: cwd,
195+
compilerExecutablePath: compilerExecutablePath,
194196
invocationCommand: invocationCommand)
195197
do {
196198
return try JSONDecoder().decode(FrontendTargetInfo.self, from: targetInfoData)

Sources/SwiftDriver/SwiftScan/SwiftScan.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,12 @@ internal extension swiftscan_diagnostic_severity_t {
319319
}
320320

321321
@_spi(Testing) public func canQueryTargetInfo() -> Bool {
322-
return api.swiftscan_compiler_target_info_query != nil &&
322+
return api.swiftscan_compiler_target_info_query_v2 != nil &&
323323
api.swiftscan_string_set_dispose != nil
324324
}
325325

326326
func queryTargetInfoJSON(workingDirectory: AbsolutePath,
327+
compilerExecutablePath: AbsolutePath,
327328
invocationCommand: [String]) throws -> Data {
328329
// Create and configure the scanner invocation
329330
let invocation = api.swiftscan_scan_invocation_create()
@@ -337,11 +338,13 @@ internal extension swiftscan_diagnostic_severity_t {
337338
Int32(invocationCommand.count),
338339
invocationStringArray)
339340
}
340-
let targetInfoStringRef = api.swiftscan_compiler_target_info_query(invocation)
341-
let targetInfoString = try toSwiftString(targetInfoStringRef)
342-
if supportsStringDispose() {
343-
api.swiftscan_string_dispose(targetInfoStringRef)
341+
342+
let targetInfoString: String = try compilerExecutablePath.description.withCString { cstring in
343+
let targetInfoStringRef = api.swiftscan_compiler_target_info_query_v2(invocation, cstring)
344+
defer { api.swiftscan_string_dispose(targetInfoStringRef) }
345+
return try toSwiftString(targetInfoStringRef)
344346
}
347+
345348
let targetInfoData = Data(targetInfoString.utf8)
346349
return targetInfoData
347350
}
@@ -382,8 +385,8 @@ private extension swiftscan_functions_t {
382385
try loadOptional("swiftscan_compiler_supported_features_query")
383386

384387
// Target Info query
385-
self.swiftscan_compiler_target_info_query =
386-
try loadOptional("swiftscan_compiler_target_info_query")
388+
self.swiftscan_compiler_target_info_query_v2 =
389+
try loadOptional("swiftscan_compiler_target_info_query_v2")
387390

388391
// Dependency scanner serialization/deserialization features
389392
self.swiftscan_scanner_cache_serialize =

0 commit comments

Comments
 (0)