Skip to content

Commit 950fc1e

Browse files
committed
Resolve main executable symlink when looking up driver-adjacent subcommand binaries
Resolves swiftlang/swift#70932
1 parent 6deb6fc commit 950fc1e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Sources/swift-driver/main.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ import Dispatch
2828
import WinSDK
2929
#endif
3030

31-
import enum TSCBasic.ProcessEnv
31+
import struct TSCBasic.AbsolutePath
3232
import func TSCBasic.exec
33+
import enum TSCBasic.ProcessEnv
3334
import class TSCBasic.DiagnosticsEngine
3435
import class TSCBasic.Process
3536
import class TSCBasic.ProcessSet
37+
import func TSCBasic.resolveSymlinks
3638
import protocol TSCBasic.DiagnosticData
3739
import var TSCBasic.localFileSystem
3840

@@ -84,12 +86,17 @@ do {
8486
}
8587

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

94101
guard let subcommandPath = subcommandPath,
95102
localFileSystem.exists(subcommandPath) else {

0 commit comments

Comments
 (0)