Skip to content

Commit 89ad084

Browse files
committed
swift-driver: adjust the path computation for the legacy driver
When running on some platforms we may not have a resolved path given to the invocation. Separately handle the invocation and the executable path to compute the desired path.
1 parent 42e5c96 commit 89ad084

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
@@ -74,10 +74,18 @@ do {
7474
// Fallback to legacy driver if forced to
7575
if CommandLine.arguments.contains(Option.disallowForwardingDriver.spelling) ||
7676
ProcessEnv.vars["SWIFT_USE_OLD_DRIVER"] != nil {
77-
let executable: URL = URL(fileURLWithPath: CommandLine.arguments[0])
77+
// If CommandLine.argument[0] is not an absolute path, we would form a path
78+
// relative to the current directory rather than relative to the actual
79+
// location of the binary. Use the Founation `NSProcessInfo` type to compute
80+
// the executable that is being run and then form the invocation from the
81+
// `CommandLine.arguments[0]`. This allows us to merge both to form a path
82+
// relative to the location of the executable but with the desired
83+
// invocation for a multi-call binary.
84+
let executable: URL = URL(fileURLWithPath: ProcessInfo.processInfo.arguments[0])
85+
let invocation: URL = URL(fileURLWithPath: CommandLine.arguments[0])
7886
let legacyExecutablePath: URL =
7987
executable.deletingLastPathComponent()
80-
.appendingPathComponent("\(executable.deletingPathExtension().lastPathComponent)-legacy-driver")
88+
.appendingPathComponent("\(invocation.deletingPathExtension().lastPathComponent)-legacy-driver")
8189
.appendingPathExtension(executable.pathExtension)
8290
let path: String = legacyExecutablePath.withUnsafeFileSystemRepresentation { String(cString: $0!) }
8391

0 commit comments

Comments
 (0)