Skip to content

Commit 46cc429

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 46cc429

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Sources/swift-driver/main.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,26 @@ 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+
87+
#if compiler(>=6.2)
8688
let legacyExecutablePath: URL =
89+
executable.deletingLastPathComponent()
90+
.appendingPathComponent("\(invocation.deletingPathExtension().lastPathComponent)-legacy-driver")
91+
.appendingPathExtension(executable.pathExtension)
92+
#else
93+
// WORKAROUND: Check if the original path has a non-empty extension because
94+
// `url.deletingPathExtension().appendingPathExtension(url.pathExtension)`
95+
// will not be equal to `url` but be `\(url).` if `url` doesn't have an
96+
// extension on Swift 6.0. Remove this when we drop support for Swift 6.0
97+
// as a bootstrapping compiler.
98+
// See https://github.com/swiftlang/swift-foundation/issues/1080
99+
var legacyExecutablePath: URL =
87100
executable.deletingLastPathComponent()
88101
.appendingPathComponent("\(invocation.deletingPathExtension().lastPathComponent)-legacy-driver")
89-
.appendingPathExtension(executable.pathExtension)
102+
if !executable.pathExtension.isEmpty {
103+
legacyExecutablePath.appendPathExtension(executable.pathExtension)
104+
}
105+
#endif
90106
let path: String = legacyExecutablePath.withUnsafeFileSystemRepresentation { String(cString: $0!) }
91107

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

0 commit comments

Comments
 (0)