From 5a899e332b5d8eb10fd11b88901f09a55b7e6ac4 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 4 Nov 2014 12:34:32 +0000 Subject: [PATCH] Use llvm::sys::findProgramByName. NFC. llvm-svn: 221257 --- lld/lib/Driver/WinLinkDriver.cpp | 15 ++++---- .../ReaderWriter/PECOFF/WriterImportLibrary.cpp | 41 ++++++++++++---------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/lld/lib/Driver/WinLinkDriver.cpp b/lld/lib/Driver/WinLinkDriver.cpp index 6375f59..940b4c0 100644 --- a/lld/lib/Driver/WinLinkDriver.cpp +++ b/lld/lib/Driver/WinLinkDriver.cpp @@ -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 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 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 programPathOrErr = llvm::sys::findProgramByName(program); + if (!programPathOrErr) { diag << "Unable to find " << program << " in PATH\n"; return false; } + const std::string &programPath = *programPathOrErr; std::vector 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 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 vec; diff --git a/lld/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp b/lld/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp index 789dff7..74ca2bf 100644 --- a/lld/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp +++ b/lld/lib/ReaderWriter/PECOFF/WriterImportLibrary.cpp @@ -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 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 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 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: is given, make a copy of the -- 2.7.4