[llvm] r183928 - Have sys::FindProgramByName return a std::string.

Rafael Espindola rafael.espindola at gmail.com
Thu Jun 13 12:25:37 PDT 2013


Author: rafael
Date: Thu Jun 13 14:25:37 2013
New Revision: 183928

URL: http://llvm.org/viewvc/llvm-project?rev=183928&view=rev
Log:
Have sys::FindProgramByName return a std::string.

Modified:
    llvm/trunk/include/llvm/Support/Program.h
    llvm/trunk/lib/Support/Unix/Program.inc
    llvm/trunk/lib/Support/Windows/Program.inc
    llvm/trunk/tools/bugpoint/OptimizerDriver.cpp
    llvm/trunk/tools/bugpoint/ToolRunner.cpp
    llvm/trunk/utils/not/not.cpp

Modified: llvm/trunk/include/llvm/Support/Program.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Program.h?rev=183928&r1=183927&r2=183928&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Program.h (original)
+++ llvm/trunk/include/llvm/Support/Program.h Thu Jun 13 14:25:37 2013
@@ -29,7 +29,7 @@ namespace sys {
   /// @returns A Path object initialized to the path of the program or a
   /// Path object that is empty (invalid) if the program could not be found.
   /// @brief Construct a Program by finding it by name.
-  Path FindProgramByName(const std::string& name);
+  std::string FindProgramByName(const std::string& name);
 
   // These functions change the specified standard stream (stdin, stdout, or
   // stderr) to binary mode. They return errc::success if the specified stream

Modified: llvm/trunk/lib/Support/Unix/Program.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Program.inc?rev=183928&r1=183927&r2=183928&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Program.inc (original)
+++ llvm/trunk/lib/Support/Unix/Program.inc Thu Jun 13 14:25:37 2013
@@ -48,19 +48,19 @@ namespace llvm {
 using namespace sys;
 
 // This function just uses the PATH environment variable to find the program.
-Path
+std::string
 sys::FindProgramByName(const std::string& progName) {
 
   // Check some degenerate cases
   if (progName.length() == 0) // no program
-    return Path();
+    return "";
   Path temp;
   if (!temp.set(progName)) // invalid name
-    return Path();
+    return "";
   // Use the given path verbatim if it contains any slashes; this matches
   // the behavior of sh(1) and friends.
   if (progName.find('/') != std::string::npos)
-    return temp;
+    return temp.str();
 
   // At this point, the file name is valid and does not contain slashes. Search
   // for it through the directories specified in the PATH environment variable.
@@ -68,7 +68,7 @@ sys::FindProgramByName(const std::string
   // Get the path. If its empty, we can't do anything to find it.
   const char *PathStr = getenv("PATH");
   if (PathStr == 0)
-    return Path();
+    return "";
 
   // Now we have a colon separated list of directories to search; try them.
   size_t PathLen = strlen(PathStr);
@@ -81,7 +81,7 @@ sys::FindProgramByName(const std::string
     if (FilePath.set(std::string(PathStr,Colon))) {
       FilePath.appendComponent(progName);
       if (FilePath.canExecute())
-        return FilePath;                    // Found the executable!
+        return FilePath.str();                    // Found the executable!
     }
 
     // Nope it wasn't in this directory, check the next path in the list!
@@ -94,7 +94,7 @@ sys::FindProgramByName(const std::string
       PathLen--;
     }
   }
-  return Path();
+  return "";
 }
 
 static bool RedirectIO(const Path *Path, int FD, std::string* ErrMsg) {

Modified: llvm/trunk/lib/Support/Windows/Program.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Program.inc?rev=183928&r1=183927&r2=183928&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Program.inc (original)
+++ llvm/trunk/lib/Support/Windows/Program.inc Thu Jun 13 14:25:37 2013
@@ -33,17 +33,17 @@ namespace llvm {
 using namespace sys;
 
 // This function just uses the PATH environment variable to find the program.
-Path sys::FindProgramByName(const std::string& progName) {
+std::string sys::FindProgramByName(const std::string &progName) {
   // Check some degenerate cases
   if (progName.length() == 0) // no program
-    return Path();
+    return "";
   Path temp;
   if (!temp.set(progName)) // invalid name
-    return Path();
+    return "";
   // Return paths with slashes verbatim.
   if (progName.find('\\') != std::string::npos ||
       progName.find('/') != std::string::npos)
-    return temp;
+    return temp.str();
 
   // At this point, the file name is valid and does not contain slashes.
   // Let Windows search for it.
@@ -54,11 +54,11 @@ Path sys::FindProgramByName(const std::s
 
   // See if it wasn't found.
   if (len == 0)
-    return Path();
+    return "";
 
   // See if we got the entire path.
   if (len < MAX_PATH)
-    return Path(buffer);
+    return std::string(buffer);
 
   // Buffer was too small; grow and retry.
   while (true) {
@@ -68,9 +68,9 @@ Path sys::FindProgramByName(const std::s
     // It is unlikely the search failed, but it's always possible some file
     // was added or removed since the last search, so be paranoid...
     if (len2 == 0)
-      return Path();
+      return "";
     else if (len2 <= len)
-      return Path(b);
+      return std::string(b);
 
     len = len2;
   }

Modified: llvm/trunk/tools/bugpoint/OptimizerDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/OptimizerDriver.cpp?rev=183928&r1=183927&r2=183928&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/OptimizerDriver.cpp (original)
+++ llvm/trunk/tools/bugpoint/OptimizerDriver.cpp Thu Jun 13 14:25:37 2013
@@ -148,7 +148,7 @@ bool BugDriver::runPasses(Module *Progra
     return 1;
   }
 
-  sys::Path tool = sys::FindProgramByName("opt");
+  std::string tool = sys::FindProgramByName("opt");
   if (tool.empty()) {
     errs() << "Cannot find `opt' in PATH!\n";
     return 1;
@@ -159,14 +159,13 @@ bool BugDriver::runPasses(Module *Progra
 
   // setup the child process' arguments
   SmallVector<const char*, 8> Args;
-  std::string Opt = tool.str();
   if (UseValgrind) {
     Args.push_back("valgrind");
     Args.push_back("--error-exitcode=1");
     Args.push_back("-q");
     Args.push_back(tool.c_str());
   } else
-    Args.push_back(Opt.c_str());
+    Args.push_back(tool.c_str());
 
   Args.push_back("-o");
   Args.push_back(OutputFilename.c_str());

Modified: llvm/trunk/tools/bugpoint/ToolRunner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/ToolRunner.cpp?rev=183928&r1=183927&r2=183928&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/ToolRunner.cpp (original)
+++ llvm/trunk/tools/bugpoint/ToolRunner.cpp Thu Jun 13 14:25:37 2013
@@ -400,7 +400,7 @@ static void lexCommand(std::string &Mess
     pos = CommandLine.find_first_of(delimiters, lastPos);
   }
 
-  CmdPath = sys::FindProgramByName(Command).str();
+  CmdPath = sys::FindProgramByName(Command);
   if (CmdPath.empty()) {
     Message =
       std::string("Cannot find '") + Command +
@@ -875,16 +875,16 @@ int GCC::MakeSharedObject(const std::str
 GCC *GCC::create(std::string &Message,
                  const std::string &GCCBinary,
                  const std::vector<std::string> *Args) {
-  sys::Path GCCPath = sys::FindProgramByName(GCCBinary);
-  if (GCCPath.isEmpty()) {
+  std::string GCCPath = sys::FindProgramByName(GCCBinary);
+  if (GCCPath.empty()) {
     Message = "Cannot find `"+ GCCBinary +"' in PATH!\n";
     return 0;
   }
 
-  sys::Path RemoteClientPath;
+  std::string RemoteClientPath;
   if (!RemoteClient.empty())
     RemoteClientPath = sys::FindProgramByName(RemoteClient);
 
-  Message = "Found gcc: " + GCCPath.str() + "\n";
-  return new GCC(GCCPath.str(), RemoteClientPath.str(), Args);
+  Message = "Found gcc: " + GCCPath + "\n";
+  return new GCC(GCCPath, RemoteClientPath, Args);
 }

Modified: llvm/trunk/utils/not/not.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/not/not.cpp?rev=183928&r1=183927&r2=183928&view=diff
==============================================================================
--- llvm/trunk/utils/not/not.cpp (original)
+++ llvm/trunk/utils/not/not.cpp Thu Jun 13 14:25:37 2013
@@ -13,10 +13,11 @@
 using namespace llvm;
 
 int main(int argc, const char **argv) {
-  sys::Path Program = sys::FindProgramByName(argv[1]);
+  std::string Program = sys::FindProgramByName(argv[1]);
 
   std::string ErrMsg;
-  int Result = sys::ExecuteAndWait(Program, argv + 1, 0, 0, 0, 0, &ErrMsg);
+  int Result =
+      sys::ExecuteAndWait(sys::Path(Program), argv + 1, 0, 0, 0, 0, &ErrMsg);
   if (Result < 0) {
     errs() << "Error: " << ErrMsg << "\n";
     return 1;





More information about the llvm-commits mailing list