Skip to content

Commit 58ea6e2

Browse files
author
David Ungar
committed
honor -driver-use-frontend-path
1 parent 8101d69 commit 58ea6e2

File tree

8 files changed

+59
-1
lines changed

8 files changed

+59
-1
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2055,6 +2055,9 @@ extension Driver {
20552055
} else {
20562056
swiftCompilerPrefixArgs = []
20572057
}
2058+
var hasFrontendBeenRedirectedForTesting: Bool {
2059+
return !swiftCompilerPrefixArgs.isEmpty
2060+
}
20582061

20592062
// Find the SDK, if any.
20602063
let sdkPath: VirtualPath? = Self.computeSDKPath(
@@ -2063,8 +2066,11 @@ extension Driver {
20632066
diagnosticsEngine: diagnosticsEngine, env: env)
20642067

20652068
// Query the frontend for target information.
2069+
// If there's a dummy frontend, don't query it.
20662070
do {
2067-
var info = try executor.execute(
2071+
var info = hasFrontendBeenRedirectedForTesting
2072+
? FrontendTargetInfo.dummyForTesting(toolchain)
2073+
: try executor.execute(
20682074
job: toolchain.printTargetInfoJob(
20692075
target: explicitTarget, targetVariant: explicitTargetVariant,
20702076
sdkPath: sdkPath, resourceDirPath: resourceDirPath,

Sources/SwiftDriver/Jobs/PrintTargetInfoJob.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ extension SwiftVersion: Codable {
9595
/// Whether the Swift libraries need to be referenced in their system
9696
/// location (/usr/lib/swift) via rpath.
9797
let librariesRequireRPath: Bool
98+
99+
static func dummyForTesting(_ toolchain: Toolchain) -> Self {
100+
let dummyForTestingTriple = Triple.dummyForTesting(toolchain)
101+
return Self(
102+
triple: dummyForTestingTriple,
103+
unversionedTriple: dummyForTestingTriple,
104+
moduleTriple: dummyForTestingTriple,
105+
swiftRuntimeCompatibilityVersion: nil,
106+
compatibilityLibraries: [],
107+
librariesRequireRPath: false)
108+
}
98109
}
99110

100111
@_spi(Testing) public struct Paths: Codable {
@@ -103,12 +114,25 @@ extension SwiftVersion: Codable {
103114
public let runtimeLibraryPaths: [TextualVirtualPath]
104115
public let runtimeLibraryImportPaths: [TextualVirtualPath]
105116
public let runtimeResourcePath: TextualVirtualPath
117+
118+
static let dummyForTesting = Paths(
119+
sdkPath: nil,
120+
runtimeLibraryPaths: [],
121+
runtimeLibraryImportPaths: [],
122+
runtimeResourcePath: .dummyForTesting)
106123
}
107124

108125
var compilerVersion: String
109126
var target: Target
110127
var targetVariant: Target?
111128
let paths: Paths
129+
130+
static func dummyForTesting(_ toolchain: Toolchain) -> Self {
131+
Self(compilerVersion: "dummy",
132+
target: .dummyForTesting(toolchain),
133+
targetVariant: nil,
134+
paths: .dummyForTesting)
135+
}
112136
}
113137

114138
// Make members of `FrontendTargetInfo.Paths` accessible on `FrontendTargetInfo`.

Sources/SwiftDriver/Toolchains/DarwinToolchain.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import SwiftOptions
3232
// An externally provided path from where we should find tools like ld
3333
public let toolDirectory: AbsolutePath?
3434

35+
public let dummyForTestingObjectFormat = Triple.ObjectFormat.macho
36+
3537
public init(env: [String: String], executor: DriverExecutor, fileSystem: FileSystem = localFileSystem, toolDirectory: AbsolutePath? = nil) {
3638
self.env = env
3739
self.executor = executor

Sources/SwiftDriver/Toolchains/GenericUnixToolchain.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import TSCBasic
2626

2727
public let toolDirectory: AbsolutePath?
2828

29+
public let dummyForTestingObjectFormat = Triple.ObjectFormat.elf
30+
2931
public init(env: [String: String], executor: DriverExecutor, fileSystem: FileSystem = localFileSystem, toolDirectory: AbsolutePath? = nil) {
3032
self.env = env
3133
self.executor = executor

Sources/SwiftDriver/Toolchains/Toolchain.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ public enum Tool: Hashable {
9090
inputs: inout [TypedVirtualPath],
9191
frontendTargetInfo: FrontendTargetInfo
9292
) throws
93+
94+
var dummyForTestingObjectFormat: Triple.ObjectFormat {get}
9395
}
9496

9597
extension Toolchain {

Sources/SwiftDriver/Toolchains/WebAssemblyToolchain.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ import SwiftOptions
4747

4848
public let toolDirectory: AbsolutePath?
4949

50+
public let dummyForTestingObjectFormat = Triple.ObjectFormat.wasm
51+
5052
public init(env: [String: String], executor: DriverExecutor, fileSystem: FileSystem = localFileSystem, toolDirectory: AbsolutePath? = nil) {
5153
self.env = env
5254
self.executor = executor

Sources/SwiftDriver/Utilities/Triple.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,20 @@ public struct Triple {
176176
os: parsedOS?.value)
177177
}
178178
}
179+
180+
private init(dummyForTesting toolchain: Toolchain) {
181+
self.triple = ""
182+
self.arch = nil
183+
self.subArch = nil
184+
self.vendor = nil
185+
self.os = nil
186+
self.environment = nil
187+
self.objectFormat = toolchain.dummyForTestingObjectFormat
188+
}
189+
190+
static func dummyForTesting(_ toolchain: Toolchain) -> Self {
191+
Self(dummyForTesting: toolchain)
192+
}
179193
}
180194

181195
extension Triple: Codable {

Sources/SwiftDriver/Utilities/VirtualPath.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ extension VirtualPath: Codable {
271271
path = try VirtualPath(path: container.decode(String.self))
272272
}
273273

274+
private init(path: VirtualPath) {
275+
self.path = path
276+
}
277+
278+
static let dummyForTesting = Self(path: try! .init(path: ""))
279+
274280
public func encode(to encoder: Encoder) throws {
275281
var container = encoder.singleValueContainer()
276282
switch path {

0 commit comments

Comments
 (0)