Fix FindExecutable to use sys::Path::GetMainExecutable instead of
just argv[0]. And remove the code for searching the current
working directory and for searching PATH; the point of FindExecutable
is not to find whatever version of the executable can be found by
searching around, but to find an executable that accompanies the
current executable.

Update the tools to use sys::Program::FindProgramByName when they
want PATH searching.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78240 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/bugpoint/ToolRunner.cpp b/tools/bugpoint/ToolRunner.cpp
index 9180c53..bce4d52 100644
--- a/tools/bugpoint/ToolRunner.cpp
+++ b/tools/bugpoint/ToolRunner.cpp
@@ -228,10 +228,12 @@
 }
 
 // LLI create method - Try to find the LLI executable
-AbstractInterpreter *AbstractInterpreter::createLLI(const std::string &ProgPath,
+AbstractInterpreter *AbstractInterpreter::createLLI(const char *Argv0,
                                                     std::string &Message,
                                      const std::vector<std::string> *ToolArgs) {
-  std::string LLIPath = FindExecutable("lli", ProgPath).toString();
+  std::string LLIPath =
+    FindExecutable("lli", Argv0,
+                   reinterpret_cast<void *>(&createLLI)).toString();
   if (!LLIPath.empty()) {
     Message = "Found lli: " + LLIPath + "\n";
     return new LLI(LLIPath, ToolArgs);
@@ -298,7 +300,6 @@
 // Custom execution environment create method, takes the execution command
 // as arguments
 AbstractInterpreter *AbstractInterpreter::createCustom(
-                    const std::string &ProgramPath,
                     std::string &Message,
                     const std::string &ExecCommandLine) {
 
@@ -332,7 +333,7 @@
     pos = ExecCommandLine.find_first_of(delimiters, lastPos);
   }
 
-  std::string CmdPath = FindExecutable(Command, ProgramPath).toString();
+  std::string CmdPath = sys::Program::FindProgramByName(Command).toString();
   if (CmdPath.empty()) {
     Message = 
       std::string("Cannot find '") + Command + 
@@ -414,18 +415,20 @@
 
 /// createLLC - Try to find the LLC executable
 ///
-LLC *AbstractInterpreter::createLLC(const std::string &ProgramPath,
+LLC *AbstractInterpreter::createLLC(const char *Argv0,
                                     std::string &Message,
                                     const std::vector<std::string> *Args,
                                     const std::vector<std::string> *GCCArgs) {
-  std::string LLCPath = FindExecutable("llc", ProgramPath).toString();
+  std::string LLCPath =
+    FindExecutable("llc", Argv0,
+                   reinterpret_cast<void *>(&createLLC)).toString();
   if (LLCPath.empty()) {
     Message = "Cannot find `llc' in executable directory or PATH!\n";
     return 0;
   }
 
   Message = "Found llc: " + LLCPath + "\n";
-  GCC *gcc = GCC::create(ProgramPath, Message, GCCArgs);
+  GCC *gcc = GCC::create(Message, GCCArgs);
   if (!gcc) {
     errs() << Message << "\n";
     exit(1);
@@ -501,9 +504,11 @@
 
 /// createJIT - Try to find the LLI executable
 ///
-AbstractInterpreter *AbstractInterpreter::createJIT(const std::string &ProgPath,
+AbstractInterpreter *AbstractInterpreter::createJIT(const char *Argv0,
                    std::string &Message, const std::vector<std::string> *Args) {
-  std::string LLIPath = FindExecutable("lli", ProgPath).toString();
+  std::string LLIPath =
+    FindExecutable("lli", Argv0,
+                   reinterpret_cast<void *>(&createJIT)).toString();
   if (!LLIPath.empty()) {
     Message = "Found lli: " + LLIPath + "\n";
     return new JIT(LLIPath, Args);
@@ -577,11 +582,13 @@
 
 /// createCBE - Try to find the 'llc' executable
 ///
-CBE *AbstractInterpreter::createCBE(const std::string &ProgramPath,
+CBE *AbstractInterpreter::createCBE(const char *Argv0,
                                     std::string &Message,
                                     const std::vector<std::string> *Args,
                                     const std::vector<std::string> *GCCArgs) {
-  sys::Path LLCPath = FindExecutable("llc", ProgramPath);
+  sys::Path LLCPath =
+    FindExecutable("llc", Argv0,
+                   reinterpret_cast<void *>(&createCBE));
   if (LLCPath.isEmpty()) {
     Message =
       "Cannot find `llc' in executable directory or PATH!\n";
@@ -589,7 +596,7 @@
   }
 
   Message = "Found llc: " + LLCPath.toString() + "\n";
-  GCC *gcc = GCC::create(ProgramPath, Message, GCCArgs);
+  GCC *gcc = GCC::create(Message, GCCArgs);
   if (!gcc) {
     errs() << Message << "\n";
     exit(1);
@@ -827,9 +834,9 @@
 
 /// create - Try to find the `gcc' executable
 ///
-GCC *GCC::create(const std::string &ProgramPath, std::string &Message,
+GCC *GCC::create(std::string &Message,
                  const std::vector<std::string> *Args) {
-  sys::Path GCCPath = FindExecutable("gcc", ProgramPath);
+  sys::Path GCCPath = sys::Program::FindProgramByName("gcc");
   if (GCCPath.isEmpty()) {
     Message = "Cannot find `gcc' in executable directory or PATH!\n";
     return 0;
@@ -837,7 +844,7 @@
 
   sys::Path RemoteClientPath;
   if (!RemoteClient.empty())
-    RemoteClientPath = FindExecutable(RemoteClient.c_str(), ProgramPath);
+    RemoteClientPath = sys::Program::FindProgramByName(RemoteClient);
 
   Message = "Found gcc: " + GCCPath.toString() + "\n";
   return new GCC(GCCPath, RemoteClientPath, Args);