Skip to content

Commit 75a69f1

Browse files
committed
Attempt to recover from in-process TargetInfo query failures.
Catch thrown exceptions and fallback to the previous mechanism of shelling out a `swift-frontend -print-target-info` task. We are seeing spurious failures here and this will help potential users while we investigate the root cause. Workaround for rdar://105559904
1 parent 6a83fd4 commit 75a69f1

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,6 +2924,7 @@ extension Driver {
29242924
swiftCompilerPrefixArgs: frontendOverride.prefixArgsForTargetInfo,
29252925
toolchain: toolchain, fileSystem: fileSystem,
29262926
workingDirectory: workingDirectory,
2927+
diagnosticsEngine: diagnosticsEngine,
29272928
executor: executor).target.triple
29282929
}
29292930

@@ -2988,6 +2989,7 @@ extension Driver {
29882989
swiftCompilerPrefixArgs: frontendOverride.prefixArgsForTargetInfo,
29892990
toolchain: toolchain, fileSystem: fileSystem,
29902991
workingDirectory: workingDirectory,
2992+
diagnosticsEngine: diagnosticsEngine,
29912993
executor: executor)
29922994

29932995
// Parse the runtime compatibility version. If present, it will override

Sources/SwiftDriver/Jobs/PrintTargetInfoJob.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import protocol TSCBasic.FileSystem
1414
import class Foundation.JSONDecoder
1515
import struct TSCBasic.AbsolutePath
16+
import class TSCBasic.DiagnosticsEngine
1617

1718
/// Swift versions are major.minor.
1819
struct SwiftVersion {
@@ -232,6 +233,7 @@ extension Driver {
232233
toolchain: Toolchain,
233234
fileSystem: FileSystem,
234235
workingDirectory: AbsolutePath?,
236+
diagnosticsEngine: DiagnosticsEngine,
235237
executor: DriverExecutor) throws -> FrontendTargetInfo {
236238
let frontendTargetInfoJob =
237239
try toolchain.printTargetInfoJob(target: target, targetVariant: targetVariant,
@@ -244,11 +246,16 @@ extension Driver {
244246
useResponseFiles: .disabled,
245247
using: executor.resolver)
246248
Self.sanitizeCommandForLibScanInvocation(&command)
247-
if let targetInfo =
248-
try Self.queryTargetInfoInProcess(of: toolchain, fileSystem: fileSystem,
249-
workingDirectory: workingDirectory,
250-
invocationCommand: command) {
251-
return targetInfo
249+
250+
do {
251+
if let targetInfo =
252+
try Self.queryTargetInfoInProcess(of: toolchain, fileSystem: fileSystem,
253+
workingDirectory: workingDirectory,
254+
invocationCommand: command) {
255+
return targetInfo
256+
}
257+
} catch {
258+
diagnosticsEngine.emit(.warning_inprocess_target_info_query_failed(error.localizedDescription))
252259
}
253260

254261
// Fallback: Invoke `swift-frontend -print-target-info` and decode the output

Sources/SwiftDriver/Utilities/Diagnostics.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ extension Diagnostic.Message {
5151
.warning("inferring simulator environment for target '\(originalTriple.triple)'; use '-target \(inferredTriple.triple)' instead")
5252
}
5353

54+
static func warning_inprocess_target_info_query_failed(_ error: String) -> Diagnostic.Message {
55+
.warning("In-process target-info query failed (\(error)). Using fallback mechanism.")
56+
}
57+
5458
static func error_argument_not_allowed_with(arg: String, other: String) -> Diagnostic.Message {
5559
.error("argument '\(arg)' is not allowed with '\(other)'")
5660
}

0 commit comments

Comments
 (0)