Skip to content

Commit ddec397

Browse files
committed
Resolve main executable symlink when looking up driver-adjacent subcommand binaries
Resolves swiftlang/swift#70932
1 parent 9954e95 commit ddec397

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Sources/swift-driver/main.swift

+11-4
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ import Dispatch
3030
import WinSDK
3131
#endif
3232

33-
import enum TSCBasic.ProcessEnv
33+
import struct TSCBasic.AbsolutePath
3434
import func TSCBasic.exec
35+
import enum TSCBasic.ProcessEnv
3536
import class TSCBasic.DiagnosticsEngine
3637
import class TSCBasic.Process
3738
import class TSCBasic.ProcessSet
39+
import func TSCBasic.resolveSymlinks
3840
import protocol TSCBasic.DiagnosticData
3941
import var TSCBasic.localFileSystem
4042

@@ -86,12 +88,17 @@ do {
8688
}
8789

8890
let (mode, arguments) = try Driver.invocationRunMode(forArgs: CommandLine.arguments)
89-
9091
if case .subcommand(let subcommand) = mode {
9192
// We are running as a subcommand, try to find the subcommand adjacent to the executable we are running as.
9293
// If we didn't find the tool there, let the OS search for it.
93-
let subcommandPath = Process.findExecutable(CommandLine.arguments[0])?.parentDirectory.appending(component: subcommand)
94-
?? Process.findExecutable(subcommand)
94+
let subcommandPath: AbsolutePath?
95+
if let executablePath = Process.findExecutable(CommandLine.arguments[0]) {
96+
// Attempt to resolve the executable symlink in order to be able to
97+
// resolve compiler-adjacent library locations.
98+
subcommandPath = try TSCBasic.resolveSymlinks(executablePath).parentDirectory.appending(component: subcommand)
99+
} else {
100+
subcommandPath = Process.findExecutable(subcommand)
101+
}
95102

96103
guard let subcommandPath = subcommandPath,
97104
localFileSystem.exists(subcommandPath) else {

0 commit comments

Comments
 (0)