Skip to content

Commit 107b39b

Browse files
Fix the legacy driver path construction on non-Windows platforms
`swift-driver` tries to invoke `swiftc-legacy-driver.` (trailing dot) on non-Windows platforms when legacy driver is requested since #1746 This is because `URL.pathExtension` returns an empty string if the URL does not have an extension but `URL.appendPathExtension` appends a period before the extension even if given an empty string. Thus `url.deletingPathExtension().appendingPathExtension(url.pathExtension)` will not be equal to `url` if `url` does not have an extension.
1 parent 89ad084 commit 107b39b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Sources/swift-driver/main.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,18 @@ do {
8383
// invocation for a multi-call binary.
8484
let executable: URL = URL(fileURLWithPath: ProcessInfo.processInfo.arguments[0])
8585
let invocation: URL = URL(fileURLWithPath: CommandLine.arguments[0])
86-
let legacyExecutablePath: URL =
86+
var legacyExecutablePath: URL =
8787
executable.deletingLastPathComponent()
8888
.appendingPathComponent("\(invocation.deletingPathExtension().lastPathComponent)-legacy-driver")
89-
.appendingPathExtension(executable.pathExtension)
89+
// WORKAROUND: Check if the original path has a non-empty extension because
90+
// `url.deletingPathExtension().appendingPathExtension(url.pathExtension)`
91+
// will not be equal to `url` but be `\(url).` if `url` doesn't have an
92+
// extension.on Swift 6.0. Remove this when we drop support for Swift 6.0
93+
// as a bootstrapping compiler.
94+
// See https://github.com/swiftlang/swift-foundation/issues/1080
95+
if !executable.pathExtension.isEmpty {
96+
legacyExecutablePath.appendPathExtension(executable.pathExtension)
97+
}
9098
let path: String = legacyExecutablePath.withUnsafeFileSystemRepresentation { String(cString: $0!) }
9199

92100
if localFileSystem.exists(AbsolutePath(path)) {

0 commit comments

Comments
 (0)