|
32 | 32 | #include "swift/FrontendTool/FrontendTool.h"
|
33 | 33 | #include "swift/DriverTool/DriverTool.h"
|
34 | 34 | #include "llvm/ADT/SmallVector.h"
|
| 35 | +#include "llvm/ADT/Triple.h" |
35 | 36 | #include "llvm/Support/CommandLine.h"
|
36 | 37 | #include "llvm/Support/ConvertUTF.h"
|
37 | 38 | #include "llvm/Support/Errno.h"
|
@@ -168,12 +169,13 @@ static bool appendSwiftDriverName(SmallString<256> &buffer) {
|
168 | 169 | return true;
|
169 | 170 | }
|
170 | 171 |
|
171 |
| - llvm::sys::path::append(buffer, "swift-driver"); |
| 172 | + StringRef execSuffix(llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows() ? ".exe" : ""); |
| 173 | + llvm::sys::path::append(buffer, "swift-driver" + execSuffix); |
172 | 174 | if (llvm::sys::fs::exists(buffer)) {
|
173 | 175 | return true;
|
174 | 176 | }
|
175 | 177 | llvm::sys::path::remove_filename(buffer);
|
176 |
| - llvm::sys::path::append(buffer, "swift-driver-new"); |
| 178 | + llvm::sys::path::append(buffer, "swift-driver-new" + execSuffix); |
177 | 179 | if (llvm::sys::fs::exists(buffer)) {
|
178 | 180 | return true;
|
179 | 181 | }
|
@@ -379,15 +381,16 @@ int swift::mainEntry(int argc_, const char **argv_) {
|
379 | 381 | subCommandArgs.erase(&subCommandArgs[1]);
|
380 | 382 | // We are running as a subcommand, try to find the subcommand adjacent to
|
381 | 383 | // the executable we are running as.
|
382 |
| - SmallString<256> SubcommandPath( |
383 |
| - llvm::sys::path::parent_path(getExecutablePath(argv[0]))); |
384 |
| - llvm::sys::path::append(SubcommandPath, SubcommandName); |
385 |
| - |
386 |
| - // If we didn't find the tool there, let the OS search for it. |
387 |
| - 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); |
388 | 392 | // Search for the program and use the path if found. If there was an
|
389 | 393 | // error, ignore it and just let the exec fail.
|
390 |
| - auto result = llvm::sys::findProgramByName(SubcommandName); |
391 | 394 | if (!result.getError())
|
392 | 395 | SubcommandPath = *result;
|
393 | 396 | }
|
|
0 commit comments