Skip to content

Commit 17873dc

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 17873dc

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Sources/swift-driver/main.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,16 @@ 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+
// 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.
93+
if !executable.pathExtension.isEmpty {
94+
legacyExecutablePath.appendPathExtension(executable.pathExtension)
95+
}
9096
let path: String = legacyExecutablePath.withUnsafeFileSystemRepresentation { String(cString: $0!) }
9197

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

0 commit comments

Comments
 (0)