Use llvm::sys::findProgramByName. NFC.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 4 Nov 2014 12:34:32 +0000 (12:34 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 4 Nov 2014 12:34:32 +0000 (12:34 +0000)
llvm-svn: 221257

lld/lib/Driver/WinLinkDriver.cpp
lld/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp

index 6375f59..940b4c0 100644 (file)
@@ -306,11 +306,12 @@ static bool convertResourceFiles(PECOFFLinkingContext &ctx,
 
   // 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(PECOFFLinkingContext &ctx,
 
   // 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, const char **argv, raw_ostream &diag) {
     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;
index 789dff7..74ca2bf 100644 (file)
@@ -69,30 +69,33 @@ static void writeTo(StringRef path, StringRef contents) {
 
 /// 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::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::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