From 675e0ac0bfd6fb78423d9fbee9f50c1dec62c111 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 13 Jun 2013 20:25:38 +0000 Subject: Avoid using PathV1.h in Program.h. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183940 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/Program.h | 27 +++++++++-------------- lib/Support/GraphWriter.cpp | 5 +++-- lib/Support/Program.cpp | 45 +++++++++++++++++++++----------------- lib/Support/SystemUtils.cpp | 1 + tools/bugpoint/OptimizerDriver.cpp | 10 ++++----- tools/bugpoint/ToolRunner.cpp | 18 +++++---------- tools/gold/gold-plugin.cpp | 1 + unittests/Support/ProgramTest.cpp | 13 ++++++----- utils/not/not.cpp | 3 +-- 9 files changed, 58 insertions(+), 65 deletions(-) diff --git a/include/llvm/Support/Program.h b/include/llvm/Support/Program.h index c8729c7f16..64a7e55da1 100644 --- a/include/llvm/Support/Program.h +++ b/include/llvm/Support/Program.h @@ -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 diff --git a/lib/Support/GraphWriter.cpp b/lib/Support/GraphWriter.cpp index 2d1a146fe7..f651e25e76 100644 --- a/lib/Support/GraphWriter.cpp +++ b/lib/Support/GraphWriter.cpp @@ -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 &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 &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; diff --git a/lib/Support/Program.cpp b/lib/Support/Program.cpp index 165972610d..52208b047d 100644 --- a/lib/Support/Program.cpp +++ b/lib/Support/Program.cpp @@ -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. diff --git a/lib/Support/SystemUtils.cpp b/lib/Support/SystemUtils.cpp index 54b5e97bfe..b13b57114b 100644 --- a/lib/Support/SystemUtils.cpp +++ b/lib/Support/SystemUtils.cpp @@ -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" diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp index 4c9219a71b..6d96330c9e 100644 --- a/tools/bugpoint/OptimizerDriver.cpp +++ b/tools/bugpoint/OptimizerDriver.cpp @@ -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. diff --git a/tools/bugpoint/ToolRunner.cpp b/tools/bugpoint/ToolRunner.cpp index 30db4b59dc..0fea9788a6 100644 --- a/tools/bugpoint/ToolRunner.cpp +++ b/tools/bugpoint/ToolRunner.cpp @@ -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) { diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp index 40f5fd6086..0ccaa3e5ed 100644 --- a/tools/gold/gold-plugin.cpp +++ b/tools/gold/gold-plugin.cpp @@ -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" diff --git a/unittests/Support/ProgramTest.cpp b/unittests/Support/ProgramTest.cpp index f132c03304..1cf53d50b0 100644 --- a/unittests/Support/ProgramTest.cpp +++ b/unittests/Support/ProgramTest.cpp @@ -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); } diff --git a/utils/not/not.cpp b/utils/not/not.cpp index 45322ecffc..13803dc867 100644 --- a/utils/not/not.cpp +++ b/utils/not/not.cpp @@ -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; -- cgit v1.2.3