1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

Use findProgramByName.

llvm-svn: 221221
This commit is contained in:
Michael J. Spencer 2014-11-04 01:29:59 +00:00
parent 5dc02583f8
commit 17a3ab5413
4 changed files with 52 additions and 21 deletions

View File

@ -105,9 +105,11 @@ struct GraphSession {
SmallVector<StringRef, 8> parts; SmallVector<StringRef, 8> parts;
Names.split(parts, "|"); Names.split(parts, "|");
for (auto Name : parts) { for (auto Name : parts) {
ProgramPath = sys::FindProgramByName(Name); auto P = sys::findProgramByName(Name);
if (!ProgramPath.empty()) if (P) {
ProgramPath = *P;
return true; return true;
}
Log << " Tried '" << Name << "'\n"; Log << " Tried '" << Name << "'\n";
} }
return false; return false;

View File

@ -159,12 +159,33 @@ bool BugDriver::runPasses(Module *Program,
return 1; 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 (tool.empty()) { if (tool.empty()) {
errs() << "Cannot find `opt' in PATH!\n"; errs() << "Cannot find `opt' in PATH!\n";
return 1; return 1;
} }
std::string Prog;
if (UseValgrind) {
auto Path = sys::findProgramByName("valgrind");
if (!Path)
errs() << Path.getError().message() << "\n";
else
Prog = *Path;
} 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. // Ok, everything that could go wrong before running opt is done.
InFile.keep(); InFile.keep();
@ -204,12 +225,6 @@ bool BugDriver::runPasses(Module *Program,
errs() << "\n"; errs() << "\n";
); );
std::string Prog;
if (UseValgrind)
Prog = sys::FindProgramByName("valgrind");
else
Prog = tool;
// Redirect stdout and stderr to nowhere if SilencePasses is given // Redirect stdout and stderr to nowhere if SilencePasses is given
StringRef Nowhere; StringRef Nowhere;
const StringRef *Redirects[3] = {nullptr, &Nowhere, &Nowhere}; const StringRef *Redirects[3] = {nullptr, &Nowhere, &Nowhere};

View File

@ -427,13 +427,14 @@ static void lexCommand(std::string &Message, const std::string &CommandLine,
pos = CommandLine.find_first_of(delimiters, lastPos); pos = CommandLine.find_first_of(delimiters, lastPos);
} }
CmdPath = sys::FindProgramByName(Command); auto Path = sys::findProgramByName(Command);
if (CmdPath.empty()) { if (!Path) {
Message = Message =
std::string("Cannot find '") + Command + std::string("Cannot find '") + Command +
"' in PATH!\n"; "' in PATH: " + Path.getError().message() + "\n";
return; return;
} }
CmdPath = *Path;
Message = "Found command in: " + CmdPath + "\n"; Message = "Found command in: " + CmdPath + "\n";
} }
@ -907,16 +908,24 @@ int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
GCC *GCC::create(std::string &Message, GCC *GCC::create(std::string &Message,
const std::string &GCCBinary, const std::string &GCCBinary,
const std::vector<std::string> *Args) { const std::vector<std::string> *Args) {
std::string GCCPath = sys::FindProgramByName(GCCBinary); auto GCCPath = sys::findProgramByName(GCCBinary);
if (GCCPath.empty()) { if (!GCCPath) {
Message = "Cannot find `"+ GCCBinary +"' in PATH!\n"; Message = "Cannot find `" + GCCBinary + "' in PATH: " +
GCCPath.getError().message() + "\n";
return nullptr; return nullptr;
} }
std::string RemoteClientPath; std::string RemoteClientPath;
if (!RemoteClient.empty()) if (!RemoteClient.empty()) {
RemoteClientPath = sys::FindProgramByName(RemoteClient); 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"; Message = "Found gcc: " + *GCCPath + "\n";
return new GCC(GCCPath, RemoteClientPath, Args); return new GCC(*GCCPath, RemoteClientPath, Args);
} }

View File

@ -27,10 +27,15 @@ int main(int argc, const char **argv) {
if (argc == 0) if (argc == 0)
return 1; 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; std::string ErrMsg;
int Result = sys::ExecuteAndWait(Program, argv, nullptr, nullptr, 0, 0, int Result = sys::ExecuteAndWait(*Program, argv, nullptr, nullptr, 0, 0,
&ErrMsg); &ErrMsg);
#ifdef _WIN32 #ifdef _WIN32
// Handle abort() in msvcrt -- It has exit code as 3. abort(), aka // Handle abort() in msvcrt -- It has exit code as 3. abort(), aka