mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 10:42:39 +01:00
Avoid using PathV1.h in Program.h.
llvm-svn: 183940
This commit is contained in:
parent
fac3a79629
commit
ef0d0d8b0b
@ -16,7 +16,6 @@
|
||||
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/PathV1.h"
|
||||
#include "llvm/Support/system_error.h"
|
||||
|
||||
namespace llvm {
|
||||
@ -48,21 +47,20 @@ namespace sys {
|
||||
/// -1 indicates failure to execute
|
||||
/// -2 indicates a crash during execution or timeout
|
||||
int ExecuteAndWait(
|
||||
const Path &path, ///< sys::Path object providing the path of the
|
||||
///< program to be executed. It is presumed this is the result of
|
||||
///< the FindProgramByName method.
|
||||
StringRef Program, ///< Path of the program to be executed. It is
|
||||
/// presumed this is the result of the FindProgramByName method.
|
||||
const char **args, ///< A vector of strings that are passed to the
|
||||
///< program. The first element should be the name of the program.
|
||||
///< The list *must* be terminated by a null char* entry.
|
||||
const char **env = 0, ///< An optional vector of strings to use for
|
||||
///< the program's environment. If not provided, the current program's
|
||||
///< environment will be used.
|
||||
const sys::Path **redirects = 0, ///< An optional array of pointers to
|
||||
///< Paths. If the array is null, no redirection is done. The array
|
||||
///< should have a size of at least three. If the pointer in the array
|
||||
///< are not null, then the inferior process's stdin(0), stdout(1),
|
||||
///< and stderr(2) will be redirected to the corresponding Paths.
|
||||
///< When an empty Path is passed in, the corresponding file
|
||||
const StringRef **redirects = 0, ///< An optional array of pointers to
|
||||
///< paths. If the array is null, no redirection is done. The array
|
||||
///< should have a size of at least three. The inferior process's
|
||||
///< stdin(0), stdout(1), and stderr(2) will be redirected to the
|
||||
///< corresponding paths.
|
||||
///< When an empty path is passed in, the corresponding file
|
||||
///< descriptor will be disconnected (ie, /dev/null'd) in a portable
|
||||
///< way.
|
||||
unsigned secondsToWait = 0, ///< If non-zero, this specifies the amount
|
||||
@ -80,14 +78,9 @@ namespace sys {
|
||||
///< program.
|
||||
bool *ExecutionFailed = 0);
|
||||
|
||||
int ExecuteAndWait(StringRef path, const char **args, const char **env = 0,
|
||||
const StringRef **redirects = 0,
|
||||
unsigned secondsToWait = 0, unsigned memoryLimit = 0,
|
||||
std::string *ErrMsg = 0, bool *ExecutionFailed = 0);
|
||||
|
||||
/// Similar to ExecuteAndWait, but return immediately.
|
||||
void ExecuteNoWait(const Path &path, const char **args, const char **env = 0,
|
||||
const sys::Path **redirects = 0, unsigned memoryLimit = 0,
|
||||
void ExecuteNoWait(StringRef Program, const char **args, const char **env = 0,
|
||||
const StringRef **redirects = 0, unsigned memoryLimit = 0,
|
||||
std::string *ErrMsg = 0);
|
||||
|
||||
// Return true if the given arguments fit within system-specific
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/PathV1.h"
|
||||
#include "llvm/Support/Program.h"
|
||||
using namespace llvm;
|
||||
|
||||
@ -85,7 +86,7 @@ static bool LLVM_ATTRIBUTE_UNUSED
|
||||
ExecGraphViewer(StringRef ExecPath, std::vector<const char*> &args,
|
||||
StringRef Filename, bool wait, std::string &ErrMsg) {
|
||||
if (wait) {
|
||||
if (sys::ExecuteAndWait(sys::Path(ExecPath), &args[0],0,0,0,0,&ErrMsg)) {
|
||||
if (sys::ExecuteAndWait(ExecPath, &args[0],0,0,0,0,&ErrMsg)) {
|
||||
errs() << "Error: " << ErrMsg << "\n";
|
||||
return false;
|
||||
}
|
||||
@ -94,7 +95,7 @@ ExecGraphViewer(StringRef ExecPath, std::vector<const char*> &args,
|
||||
errs() << " done. \n";
|
||||
}
|
||||
else {
|
||||
sys::ExecuteNoWait(sys::Path(ExecPath), &args[0],0,0,0,&ErrMsg);
|
||||
sys::ExecuteNoWait(ExecPath, &args[0],0,0,0,&ErrMsg);
|
||||
errs() << "Remember to erase graph file: " << Filename.str() << "\n";
|
||||
}
|
||||
return true;
|
||||
|
@ -12,6 +12,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Support/Program.h"
|
||||
#include "llvm/Support/PathV1.h"
|
||||
#include "llvm/Config/config.h"
|
||||
#include "llvm/Support/system_error.h"
|
||||
using namespace llvm;
|
||||
@ -29,46 +30,50 @@ static bool Execute(void **Data, const Path &path, const char **args,
|
||||
static int Wait(void *&Data, const Path &path, unsigned secondsToWait,
|
||||
std::string *ErrMsg);
|
||||
|
||||
int sys::ExecuteAndWait(StringRef path, const char **args, const char **env,
|
||||
const StringRef **redirects, unsigned secondsToWait,
|
||||
unsigned memoryLimit, std::string *ErrMsg,
|
||||
bool *ExecutionFailed) {
|
||||
Path P(path);
|
||||
if (!redirects)
|
||||
return ExecuteAndWait(P, args, env, 0, secondsToWait, memoryLimit, ErrMsg,
|
||||
ExecutionFailed);
|
||||
|
||||
static bool Execute(void **Data, StringRef Program, const char **args,
|
||||
const char **env, const StringRef **Redirects,
|
||||
unsigned memoryLimit, std::string *ErrMsg) {
|
||||
Path P(Program);
|
||||
if (!Redirects)
|
||||
return Execute(Data, P, args, env, 0, memoryLimit, ErrMsg);
|
||||
Path IO[3];
|
||||
const Path *IOP[3];
|
||||
for (int I = 0; I < 3; ++I) {
|
||||
if (redirects[I]) {
|
||||
IO[I] = *redirects[I];
|
||||
if (Redirects[I]) {
|
||||
IO[I] = *Redirects[I];
|
||||
IOP[I] = &IO[I];
|
||||
} else {
|
||||
IOP[I] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ExecuteAndWait(P, args, env, IOP, secondsToWait, memoryLimit, ErrMsg,
|
||||
ExecutionFailed);
|
||||
return Execute(Data, P, args, env, IOP, memoryLimit, ErrMsg);
|
||||
}
|
||||
|
||||
int sys::ExecuteAndWait(const Path &path, const char **args, const char **envp,
|
||||
const Path **redirects, unsigned secondsToWait,
|
||||
static int Wait(void *&Data, StringRef Program, unsigned secondsToWait,
|
||||
std::string *ErrMsg) {
|
||||
Path P(Program);
|
||||
return Wait(Data, P, secondsToWait, ErrMsg);
|
||||
}
|
||||
|
||||
int sys::ExecuteAndWait(StringRef Program, const char **args, const char **envp,
|
||||
const StringRef **redirects, unsigned secondsToWait,
|
||||
unsigned memoryLimit, std::string *ErrMsg,
|
||||
bool *ExecutionFailed) {
|
||||
void *Data = 0;
|
||||
if (Execute(&Data, path, args, envp, redirects, memoryLimit, ErrMsg)) {
|
||||
if (Execute(&Data, Program, args, envp, redirects, memoryLimit, ErrMsg)) {
|
||||
if (ExecutionFailed) *ExecutionFailed = false;
|
||||
return Wait(Data, path, secondsToWait, ErrMsg);
|
||||
return Wait(Data, Program, secondsToWait, ErrMsg);
|
||||
}
|
||||
if (ExecutionFailed) *ExecutionFailed = true;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void sys::ExecuteNoWait(const Path &path, const char **args, const char **envp,
|
||||
const Path **redirects, unsigned memoryLimit,
|
||||
void sys::ExecuteNoWait(StringRef Program, const char **args, const char **envp,
|
||||
const StringRef **redirects, unsigned memoryLimit,
|
||||
std::string *ErrMsg) {
|
||||
Execute(/*Data*/ 0, path, args, envp, redirects, memoryLimit, ErrMsg);
|
||||
Execute(/*Data*/ 0, Program, args, envp, redirects, memoryLimit, ErrMsg);
|
||||
}
|
||||
|
||||
// Include the platform-specific parts of this class.
|
||||
|
@ -13,6 +13,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Support/SystemUtils.h"
|
||||
#include "llvm/Support/PathV1.h"
|
||||
#include "llvm/Support/Process.h"
|
||||
#include "llvm/Support/Program.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
@ -200,12 +200,12 @@ bool BugDriver::runPasses(Module *Program,
|
||||
prog = tool;
|
||||
|
||||
// Redirect stdout and stderr to nowhere if SilencePasses is given
|
||||
sys::Path Nowhere;
|
||||
const sys::Path *Redirects[3] = {0, &Nowhere, &Nowhere};
|
||||
StringRef Nowhere;
|
||||
const StringRef *Redirects[3] = {0, &Nowhere, &Nowhere};
|
||||
|
||||
int result =
|
||||
sys::ExecuteAndWait(prog, Args.data(), 0, (SilencePasses ? Redirects : 0),
|
||||
Timeout, MemoryLimit, &ErrMsg);
|
||||
int result = sys::ExecuteAndWait(prog.str(), Args.data(), 0,
|
||||
(SilencePasses ? Redirects : 0), Timeout,
|
||||
MemoryLimit, &ErrMsg);
|
||||
|
||||
// If we are supposed to delete the bitcode file or if the passes crashed,
|
||||
// remove it now. This may fail if the file was never created, but that's ok.
|
||||
|
@ -61,11 +61,7 @@ static int RunProgramWithTimeout(StringRef ProgramPath,
|
||||
unsigned NumSeconds = 0,
|
||||
unsigned MemoryLimit = 0,
|
||||
std::string *ErrMsg = 0) {
|
||||
const sys::Path P[3] = { sys::Path(StdInFile), sys::Path(StdOutFile),
|
||||
sys::Path(StdErrFile) };
|
||||
const sys::Path* redirects[3];
|
||||
for (int I = 0; I < 3; ++I)
|
||||
redirects[I] = &P[I];
|
||||
const StringRef *Redirects[3] = { &StdInFile, &StdOutFile, &StdErrFile };
|
||||
|
||||
#if 0 // For debug purposes
|
||||
{
|
||||
@ -76,7 +72,7 @@ static int RunProgramWithTimeout(StringRef ProgramPath,
|
||||
}
|
||||
#endif
|
||||
|
||||
return sys::ExecuteAndWait(sys::Path(ProgramPath), Args, 0, redirects,
|
||||
return sys::ExecuteAndWait(ProgramPath, Args, 0, Redirects,
|
||||
NumSeconds, MemoryLimit, ErrMsg);
|
||||
}
|
||||
|
||||
@ -93,11 +89,7 @@ static int RunProgramRemotelyWithTimeout(StringRef RemoteClientPath,
|
||||
StringRef StdErrFile,
|
||||
unsigned NumSeconds = 0,
|
||||
unsigned MemoryLimit = 0) {
|
||||
const sys::Path P[3] = { sys::Path(StdInFile), sys::Path(StdOutFile),
|
||||
sys::Path(StdErrFile) };
|
||||
const sys::Path* redirects[3];
|
||||
for (int I = 0; I < 3; ++I)
|
||||
redirects[I] = &P[I];
|
||||
const StringRef *Redirects[3] = { &StdInFile, &StdOutFile, &StdErrFile };
|
||||
|
||||
#if 0 // For debug purposes
|
||||
{
|
||||
@ -109,8 +101,8 @@ static int RunProgramRemotelyWithTimeout(StringRef RemoteClientPath,
|
||||
#endif
|
||||
|
||||
// Run the program remotely with the remote client
|
||||
int ReturnCode = sys::ExecuteAndWait(sys::Path(RemoteClientPath), Args, 0,
|
||||
redirects, NumSeconds, MemoryLimit);
|
||||
int ReturnCode = sys::ExecuteAndWait(RemoteClientPath, Args, 0,
|
||||
Redirects, NumSeconds, MemoryLimit);
|
||||
|
||||
// Has the remote client fail?
|
||||
if (255 == ReturnCode) {
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "llvm/Support/Errno.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/PathV1.h"
|
||||
#include "llvm/Support/Program.h"
|
||||
#include "llvm/Support/ToolOutputFile.h"
|
||||
#include "llvm/Support/system_error.h"
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
#include "llvm/Support/PathV1.h"
|
||||
#include "llvm/Support/Program.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@ -74,14 +75,14 @@ TEST(ProgramTest, CreateProcessTrailingSlash) {
|
||||
bool ExecutionFailed;
|
||||
// Redirect stdout and stdin to NUL, but let stderr through.
|
||||
#ifdef LLVM_ON_WIN32
|
||||
Path nul("NUL");
|
||||
StringRef nul("NUL");
|
||||
#else
|
||||
Path nul("/dev/null");
|
||||
StringRef nul("/dev/null");
|
||||
#endif
|
||||
const Path *redirects[] = { &nul, &nul, 0 };
|
||||
int rc =
|
||||
ExecuteAndWait(my_exe, argv, &envp[0], redirects, /*secondsToWait=*/ 10,
|
||||
/*memoryLimit=*/ 0, &error, &ExecutionFailed);
|
||||
const StringRef *redirects[] = { &nul, &nul, 0 };
|
||||
int rc = ExecuteAndWait(my_exe.str(), argv, &envp[0], redirects,
|
||||
/*secondsToWait=*/ 10, /*memoryLimit=*/ 0, &error,
|
||||
&ExecutionFailed);
|
||||
EXPECT_FALSE(ExecutionFailed) << error;
|
||||
EXPECT_EQ(0, rc);
|
||||
}
|
||||
|
@ -16,8 +16,7 @@ int main(int argc, const char **argv) {
|
||||
std::string Program = sys::FindProgramByName(argv[1]);
|
||||
|
||||
std::string ErrMsg;
|
||||
int Result =
|
||||
sys::ExecuteAndWait(sys::Path(Program), argv + 1, 0, 0, 0, 0, &ErrMsg);
|
||||
int Result = sys::ExecuteAndWait(Program, argv + 1, 0, 0, 0, 0, &ErrMsg);
|
||||
if (Result < 0) {
|
||||
errs() << "Error: " << ErrMsg << "\n";
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user