Skip to content

Commit d4ab627

Browse files
committed
Pass Swift compiler path to Toolchain.swiftCompilerVersion().
Allows overridden Swift compiler frontend paths to work.
1 parent 657f747 commit d4ab627

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ public struct Driver {
286286
moduleOutput: self.moduleOutput,
287287
inputFiles: inputFiles,
288288
diagnosticEngine: diagnosticEngine,
289-
actualSwiftVersion: try? toolchain.swiftCompilerVersion()
289+
actualSwiftVersion:
290+
try? toolchain.swiftCompilerVersion(self.swiftCompiler)
290291
)
291292

292293
self.sdkPath = Self.computeSDKPath(&parsedOptions, compilerMode: compilerMode, toolchain: toolchain, diagnosticsEngine: diagnosticEngine, env: env)

Sources/SwiftDriver/Toolchains/Toolchain.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ extension Toolchain {
7474
getEnvSearchPaths(pathString: env["PATH"], currentWorkingDirectory: localFileSystem.currentWorkingDirectory)
7575
}
7676

77-
public func swiftCompilerVersion() throws -> String {
77+
public func swiftCompilerVersion(_ swiftCompiler: VirtualPath) throws -> String {
7878
// FIXME: Thread the driver's swiftCompiler path here.
7979
try Process.checkNonZeroExit(
80-
args: getToolPath(.swiftCompiler).pathString, "-version",
80+
args: swiftCompiler.name, "-version",
8181
environment: env
8282
).split(separator: "\n").first.map(String.init) ?? ""
8383
}

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,8 +1168,12 @@ final class SwiftDriverTests: XCTestCase {
11681168
}
11691169

11701170
func testToolchainUtilities() throws {
1171-
let darwinSwiftVersion = try DarwinToolchain(env: ProcessEnv.vars).swiftCompilerVersion()
1172-
let unixSwiftVersion = try GenericUnixToolchain(env: ProcessEnv.vars).swiftCompilerVersion()
1171+
let darwinToolchain = DarwinToolchain(env: ProcessEnv.vars)
1172+
let darwinSwiftVersion = try darwinToolchain.swiftCompilerVersion(
1173+
.absolute(darwinToolchain.getToolPath(.swiftCompiler)))
1174+
let unixToolchain = GenericUnixToolchain(env: ProcessEnv.vars)
1175+
let unixSwiftVersion = try unixToolchain.swiftCompilerVersion(
1176+
.absolute(unixToolchain.getToolPath(.swiftCompiler)))
11731177
assertString(darwinSwiftVersion, contains: "Swift version ")
11741178
assertString(unixSwiftVersion, contains: "Swift version ")
11751179
}

0 commit comments

Comments
 (0)