[llvm] r221221 - Use findProgramByName.
David Blaikie
dblaikie at gmail.com
Thu Nov 6 08:23:23 PST 2014
On Mon, Nov 3, 2014 at 5:29 PM, Michael J. Spencer <bigcheesegs at gmail.com>
wrote:
> Author: mspencer
> Date: Mon Nov 3 19:29:59 2014
> New Revision: 221221
>
> URL: http://llvm.org/viewvc/llvm-project?rev=221221&view=rev
> Log:
> Use findProgramByName.
>
> Modified:
> llvm/trunk/lib/Support/GraphWriter.cpp
> llvm/trunk/tools/bugpoint/OptimizerDriver.cpp
> llvm/trunk/tools/bugpoint/ToolRunner.cpp
> llvm/trunk/utils/not/not.cpp
>
> Modified: llvm/trunk/lib/Support/GraphWriter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/GraphWriter.cpp?rev=221221&r1=221220&r2=221221&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Support/GraphWriter.cpp (original)
> +++ llvm/trunk/lib/Support/GraphWriter.cpp Mon Nov 3 19:29:59 2014
> @@ -105,9 +105,11 @@ struct GraphSession {
> SmallVector<StringRef, 8> parts;
> Names.split(parts, "|");
> for (auto Name : parts) {
> - ProgramPath = sys::FindProgramByName(Name);
> - if (!ProgramPath.empty())
> + auto P = sys::findProgramByName(Name);
> + if (P) {
>
Roll the declaration into the condition:
if (auto P = sys::findProgramByName(Name)) {
(& I tend to agree with Rafael, that auto might be a bit too opaque for
ErrorOr<string>)
> + ProgramPath = *P;
> return true;
> + }
> Log << " Tried '" << Name << "'\n";
> }
> return false;
>
> Modified: llvm/trunk/tools/bugpoint/OptimizerDriver.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/OptimizerDriver.cpp?rev=221221&r1=221220&r2=221221&view=diff
>
> ==============================================================================
> --- llvm/trunk/tools/bugpoint/OptimizerDriver.cpp (original)
> +++ llvm/trunk/tools/bugpoint/OptimizerDriver.cpp Mon Nov 3 19:29:59 2014
> @@ -159,12 +159,33 @@ bool BugDriver::runPasses(Module *Progra
> return 1;
> }
>
> - std::string tool = OptCmd.empty()? sys::FindProgramByName("opt") :
> OptCmd;
> + std::string tool = OptCmd;
> + if (OptCmd.empty()) {
> + auto Path = sys::findProgramByName("opt");
> + if (!Path)
+ errs() << Path.getError().message() << "\n";
> + else
> + tool = *Path;
>
if (auto Path = sys::findProgramByName("opt"))
tool = *Path;
else
errs() << Path.getError().message() << "\n";
(not entirely convinced on this - having the error path first feels a bit
nicer, but when each is only one line, I'm not sure it's a huge deal)
> + }
> if (tool.empty()) {
> errs() << "Cannot find `opt' in PATH!\n";
> return 1;
> }
>
> + std::string Prog;
> + if (UseValgrind) {
> + auto Path = sys::findProgramByName("valgrind");
> + if (!Path)
> + errs() << Path.getError().message() << "\n";
> + else
> + Prog = *Path;
>
same again.
> + } else
> + Prog = tool;
> + if (Prog.empty()) {
> + errs() << "Cannot find `valgrind' in PATH!\n";
> + return 1;
> + }
> +
> // Ok, everything that could go wrong before running opt is done.
> InFile.keep();
>
> @@ -204,12 +225,6 @@ bool BugDriver::runPasses(Module *Progra
> errs() << "\n";
> );
>
> - std::string Prog;
> - if (UseValgrind)
> - Prog = sys::FindProgramByName("valgrind");
> - else
> - Prog = tool;
> -
> // Redirect stdout and stderr to nowhere if SilencePasses is given
> StringRef Nowhere;
> const StringRef *Redirects[3] = {nullptr, &Nowhere, &Nowhere};
>
> Modified: llvm/trunk/tools/bugpoint/ToolRunner.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/ToolRunner.cpp?rev=221221&r1=221220&r2=221221&view=diff
>
> ==============================================================================
> --- llvm/trunk/tools/bugpoint/ToolRunner.cpp (original)
> +++ llvm/trunk/tools/bugpoint/ToolRunner.cpp Mon Nov 3 19:29:59 2014
> @@ -427,13 +427,14 @@ static void lexCommand(std::string &Mess
> pos = CommandLine.find_first_of(delimiters, lastPos);
> }
>
> - CmdPath = sys::FindProgramByName(Command);
> - if (CmdPath.empty()) {
> + auto Path = sys::findProgramByName(Command);
> + if (!Path) {
Message =
> std::string("Cannot find '") + Command +
> - "' in PATH!\n";
> + "' in PATH: " + Path.getError().message() + "\n";
> return;
> }
> + CmdPath = *Path;
>
> Message = "Found command in: " + CmdPath + "\n";
> }
> @@ -907,16 +908,24 @@ int GCC::MakeSharedObject(const std::str
> GCC *GCC::create(std::string &Message,
> const std::string &GCCBinary,
> const std::vector<std::string> *Args) {
> - std::string GCCPath = sys::FindProgramByName(GCCBinary);
> - if (GCCPath.empty()) {
> - Message = "Cannot find `"+ GCCBinary +"' in PATH!\n";
> + auto GCCPath = sys::findProgramByName(GCCBinary);
> + if (!GCCPath) {
+ Message = "Cannot find `" + GCCBinary + "' in PATH: " +
> + GCCPath.getError().message() + "\n";
> return nullptr;
> }
>
> std::string RemoteClientPath;
> - if (!RemoteClient.empty())
> - RemoteClientPath = sys::FindProgramByName(RemoteClient);
> + if (!RemoteClient.empty()) {
> + auto Path = sys::findProgramByName(RemoteClient);
> + if (!Path) {
> + Message = "Cannot find `" + RemoteClient + "' in PATH: " +
> + Path.getError().message() + "\n";
> + return nullptr;
> + }
> + RemoteClientPath = *Path;
> + }
>
> - Message = "Found gcc: " + GCCPath + "\n";
> - return new GCC(GCCPath, RemoteClientPath, 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=221221&r1=221220&r2=221221&view=diff
>
> ==============================================================================
> --- llvm/trunk/utils/not/not.cpp (original)
> +++ llvm/trunk/utils/not/not.cpp Mon Nov 3 19:29:59 2014
> @@ -27,10 +27,15 @@ int main(int argc, const char **argv) {
> if (argc == 0)
> return 1;
>
> - std::string Program = sys::FindProgramByName(argv[0]);
> + auto Program = sys::findProgramByName(argv[0]);
> + if (!Program) {
> + errs() << "Error: Unable to find `" << argv[0]
> + << "' in PATH: " << Program.getError().message() << "\n";
> + return 1;
> + }
>
> std::string ErrMsg;
> - int Result = sys::ExecuteAndWait(Program, argv, nullptr, nullptr, 0, 0,
> + int Result = sys::ExecuteAndWait(*Program, argv, nullptr, nullptr, 0, 0,
> &ErrMsg);
> #ifdef _WIN32
> // Handle abort() in msvcrt -- It has exit code as 3. abort(), aka
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141106/336f3663/attachment.html>
More information about the llvm-commits
mailing list