Skip to content

Commit 4e924da

Browse files
authored
Merge pull request #1067 from stevapple/find-subcommand
Fix up self-discovery of Swift Driver and tools
2 parents 53e79b3 + 0c4c300 commit 4e924da

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Sources/swift-driver/main.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,20 @@ do {
7373
if case .subcommand(let subcommand) = mode {
7474
// We are running as a subcommand, try to find the subcommand adjacent to the executable we are running as.
7575
// If we didn't find the tool there, let the OS search for it.
76-
let subcommandPath = Process.findExecutable(arguments[0])?.parentDirectory.appending(component: subcommand)
76+
let subcommandPath = Process.findExecutable(CommandLine.arguments[0])?.parentDirectory.appending(component: subcommand)
7777
?? Process.findExecutable(subcommand)
7878

79-
if subcommandPath == nil || !localFileSystem.exists(subcommandPath!) {
79+
guard let subcommandPath = subcommandPath,
80+
localFileSystem.exists(subcommandPath) else {
8081
throw Driver.Error.unknownOrMissingSubcommand(subcommand)
8182
}
8283

84+
// Pass the full path to subcommand executable.
85+
var arguments = arguments
86+
arguments[0] = subcommandPath.pathString
87+
8388
// Execute the subcommand.
84-
try exec(path: subcommandPath?.pathString ?? "", args: arguments)
89+
try exec(path: subcommandPath.pathString, args: arguments)
8590
}
8691

8792
let executor = try SwiftDriverExecutor(diagnosticsEngine: diagnosticsEngine,

0 commit comments

Comments
 (0)