[lld] r221257 - Use llvm::sys::findProgramByName. NFC.

Rafael Espindola rafael.espindola at gmail.com
Tue Nov 4 04:34:32 PST 2014


Author: rafael
Date: Tue Nov  4 06:34:32 2014
New Revision: 221257

URL: http://llvm.org/viewvc/llvm-project?rev=221257&view=rev
Log:
Use llvm::sys::findProgramByName. NFC.

Modified:
    lld/trunk/lib/Driver/WinLinkDriver.cpp
    lld/trunk/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp

Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=221257&r1=221256&r2=221257&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Tue Nov  4 06:34:32 2014
@@ -306,11 +306,12 @@ static bool convertResourceFiles(PECOFFL
 
   // Construct CVTRES.EXE command line and execute it.
   std::string program = "cvtres.exe";
-  std::string programPath = llvm::sys::FindProgramByName(program);
-  if (programPath.empty()) {
+  ErrorOr<std::string> programPathOrErr = llvm::sys::findProgramByName(program);
+  if (!programPathOrErr) {
     llvm::errs() << "Unable to find " << program << " in PATH\n";
     return false;
   }
+  const std::string &programPath = *programPathOrErr;
 
   std::vector<const char *> args;
   args.push_back(programPath.c_str());
@@ -562,11 +563,12 @@ static bool createManifestResourceFile(P
 
   // Run RC.EXE /fo tmp.res tmp.rc
   std::string program = "rc.exe";
-  std::string programPath = llvm::sys::FindProgramByName(program);
-  if (programPath.empty()) {
+  ErrorOr<std::string> programPathOrErr = llvm::sys::findProgramByName(program);
+  if (!programPathOrErr) {
     diag << "Unable to find " << program << " in PATH\n";
     return false;
   }
+  const std::string &programPath = *programPathOrErr;
   std::vector<const char *> args;
   args.push_back(programPath.c_str());
   args.push_back("/fo");
@@ -794,11 +796,12 @@ static bool maybeRunLibCommand(int argc,
     return false;
   if (!StringRef(argv[1]).equals_lower("/lib"))
     return false;
-  std::string path = llvm::sys::FindProgramByName("lib.exe");
-  if (path.empty()) {
+  ErrorOr<std::string> pathOrErr = llvm::sys::findProgramByName("lib.exe");
+  if (!pathOrErr) {
     diag << "Unable to find lib.exe in PATH\n";
     return true;
   }
+  const std::string &path = *pathOrErr;
 
   // Run lib.exe
   std::vector<const char *> vec;

Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp?rev=221257&r1=221256&r2=221257&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp Tue Nov  4 06:34:32 2014
@@ -69,30 +69,33 @@ static void writeTo(StringRef path, Stri
 
 /// Creates a .def file and runs lib.exe on it to create an import library.
 void writeImportLibrary(const PECOFFLinkingContext &ctx) {
+  std::string fileContents = createModuleDefinitionFile(ctx);
+
   std::string program = "lib.exe";
-  std::string programPath = llvm::sys::FindProgramByName(program);
+  ErrorOr<std::string> programPathOrErr = llvm::sys::findProgramByName(program);
+  if (!programPathOrErr) {
+    llvm::errs() << "Unable to find " << program << " in PATH\n";
+  } else {
+    const std::string &programPath = *programPathOrErr;
 
-  std::string fileContents = createModuleDefinitionFile(ctx);
-  std::string defPath = writeToTempFile(fileContents);
-  llvm::FileRemover tmpFile(defPath);
+    std::string defPath = writeToTempFile(fileContents);
+    llvm::FileRemover tmpFile(defPath);
 
-  std::string defArg = "/def:";
-  defArg.append(defPath);
-  std::string outputArg = "/out:";
-  outputArg.append(ctx.getOutputImportLibraryPath());
-
-  std::vector<const char *> args;
-  args.push_back(programPath.c_str());
-  args.push_back("/nologo");
-  args.push_back(ctx.is64Bit() ? "/machine:x64" : "/machine:x86");
-  args.push_back(defArg.c_str());
-  args.push_back(outputArg.c_str());
-  args.push_back(nullptr);
+    std::string defArg = "/def:";
+    defArg.append(defPath);
+    std::string outputArg = "/out:";
+    outputArg.append(ctx.getOutputImportLibraryPath());
+
+    std::vector<const char *> args;
+    args.push_back(programPath.c_str());
+    args.push_back("/nologo");
+    args.push_back(ctx.is64Bit() ? "/machine:x64" : "/machine:x86");
+    args.push_back(defArg.c_str());
+    args.push_back(outputArg.c_str());
+    args.push_back(nullptr);
 
-  if (programPath.empty()) {
-    llvm::errs() << "Unable to find " << program << " in PATH\n";
-  } else if (llvm::sys::ExecuteAndWait(programPath.c_str(), &args[0]) != 0) {
-    llvm::errs() << program << " failed\n";
+    if (llvm::sys::ExecuteAndWait(programPath.c_str(), &args[0]) != 0)
+      llvm::errs() << program << " failed\n";
   }
 
   // If /lldmoduledeffile:<filename> is given, make a copy of the





More information about the llvm-commits mailing list