Skip to content

Commit

Permalink
Resolve main executable symlink when looking up driver-adjacent subco…
Browse files Browse the repository at this point in the history
…mmand binaries

Resolves swiftlang/swift#70932
  • Loading branch information
artemcm committed Aug 13, 2024
1 parent 9954e95 commit ddec397
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Sources/swift-driver/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ import Dispatch
import WinSDK
#endif

import enum TSCBasic.ProcessEnv
import struct TSCBasic.AbsolutePath
import func TSCBasic.exec
import enum TSCBasic.ProcessEnv
import class TSCBasic.DiagnosticsEngine
import class TSCBasic.Process
import class TSCBasic.ProcessSet
import func TSCBasic.resolveSymlinks
import protocol TSCBasic.DiagnosticData
import var TSCBasic.localFileSystem

Expand Down Expand Up @@ -86,12 +88,17 @@ do {
}

let (mode, arguments) = try Driver.invocationRunMode(forArgs: CommandLine.arguments)

if case .subcommand(let subcommand) = mode {
// We are running as a subcommand, try to find the subcommand adjacent to the executable we are running as.
// If we didn't find the tool there, let the OS search for it.
let subcommandPath = Process.findExecutable(CommandLine.arguments[0])?.parentDirectory.appending(component: subcommand)
?? Process.findExecutable(subcommand)
let subcommandPath: AbsolutePath?
if let executablePath = Process.findExecutable(CommandLine.arguments[0]) {
// Attempt to resolve the executable symlink in order to be able to
// resolve compiler-adjacent library locations.
subcommandPath = try TSCBasic.resolveSymlinks(executablePath).parentDirectory.appending(component: subcommand)
} else {
subcommandPath = Process.findExecutable(subcommand)
}

guard let subcommandPath = subcommandPath,
localFileSystem.exists(subcommandPath) else {
Expand Down

0 comments on commit ddec397

Please sign in to comment.