Skip to content

Always fall back to $PATH-based subcommand resolution #1932

Open
@doinkythederp

Description

@doinkythederp

Currently, if the first argument (i.e. argv[0]) of swift-driver is any absolute path or is resolvable to an executable, subcommands (i.e. argv[1]) will only be resolved relative to the compiler.

// 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: 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)
}

For example, when running swift subcommand, since argv[0] is /usr/local/bin/swift and argv[1] is subcommand, swift-driver will launch /usr/local/bin/swift-subcommand.

However, it would be helpful if swift-driver read the $PATH environment variable to determine which executable to launch in the event that the binary is not adjacent to the compiler.

For example, I could then create ~/.bin/swift-subcommand, put that directory in my path, and then invoke it as swift subcommand, without needing to edit my Swift installation.

This seems like the intended behavior here based on the comment above the relevant code, so the fact that this is not happening might be a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions