Skip to content

Commit a1df4ba

Browse files
committed
[Driver] More robust way of finding subcommand path
1 parent 029f0bc commit a1df4ba

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/DriverTool/driver.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -381,15 +381,16 @@ int swift::mainEntry(int argc_, const char **argv_) {
381381
subCommandArgs.erase(&subCommandArgs[1]);
382382
// We are running as a subcommand, try to find the subcommand adjacent to
383383
// the executable we are running as.
384-
SmallString<256> SubcommandPath(
385-
llvm::sys::path::parent_path(getExecutablePath(argv[0])));
386-
llvm::sys::path::append(SubcommandPath, SubcommandName);
387-
388-
// If we didn't find the tool there, let the OS search for it.
389-
if (!llvm::sys::fs::exists(SubcommandPath)) {
384+
SmallString<256> SubcommandPath(SubcommandName);
385+
auto result = llvm::sys::findProgramByName(SubcommandName,
386+
{ llvm::sys::path::parent_path(getExecutablePath(argv[0])) });
387+
if (!result.getError()) {
388+
SubcommandPath = *result;
389+
} else {
390+
// If we didn't find the tool there, let the OS search for it.
391+
result = llvm::sys::findProgramByName(SubcommandName);
390392
// Search for the program and use the path if found. If there was an
391393
// error, ignore it and just let the exec fail.
392-
auto result = llvm::sys::findProgramByName(SubcommandName);
393394
if (!result.getError())
394395
SubcommandPath = *result;
395396
}

0 commit comments

Comments
 (0)