#include "llvm/ADT/ArrayRef.h"
#include "llvm/Support/Path.h"
-#include "llvm/Support/PathV1.h"
#include "llvm/Support/system_error.h"
namespace llvm {
/// -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
///< 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
#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;
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;
}
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;
//===----------------------------------------------------------------------===//
#include "llvm/Support/Program.h"
+#include "llvm/Support/PathV1.h"
#include "llvm/Config/config.h"
#include "llvm/Support/system_error.h"
using namespace llvm;
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.
//===----------------------------------------------------------------------===//
#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"
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.
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
{
}
#endif
- return sys::ExecuteAndWait(sys::Path(ProgramPath), Args, 0, redirects,
+ return sys::ExecuteAndWait(ProgramPath, Args, 0, Redirects,
NumSeconds, MemoryLimit, ErrMsg);
}
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
{
#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) {
#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"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/PathV1.h"
#include "llvm/Support/Program.h"
#include "gtest/gtest.h"
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);
}
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;