llvm.org GIT mirror llvm / 675e0ac
Avoid using PathV1.h in Program.h. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183940 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
9 changed file(s) with 68 addition(s) and 75 deletion(s). Raw diff Collapse all Expand all
1515
1616 #include "llvm/ADT/ArrayRef.h"
1717 #include "llvm/Support/Path.h"
18 #include "llvm/Support/PathV1.h"
1918 #include "llvm/Support/system_error.h"
2019
2120 namespace llvm {
4746 /// -1 indicates failure to execute
4847 /// -2 indicates a crash during execution or timeout
4948 int ExecuteAndWait(
50 const Path &path, ///< sys::Path object providing the path of the
51 ///< program to be executed. It is presumed this is the result of
52 ///< the FindProgramByName method.
49 StringRef Program, ///< Path of the program to be executed. It is
50 /// presumed this is the result of the FindProgramByName method.
5351 const char **args, ///< A vector of strings that are passed to the
5452 ///< program. The first element should be the name of the program.
5553 ///< The list *must* be terminated by a null char* entry.
5654 const char **env = 0, ///< An optional vector of strings to use for
5755 ///< the program's environment. If not provided, the current program's
5856 ///< environment will be used.
59 const sys::Path **redirects = 0, ///< An optional array of pointers to
60 ///< Paths. If the array is null, no redirection is done. The array
61 ///< should have a size of at least three. If the pointer in the array
62 ///< are not null, then the inferior process's stdin(0), stdout(1),
63 ///< and stderr(2) will be redirected to the corresponding Paths.
64 ///< When an empty Path is passed in, the corresponding file
57 const StringRef **redirects = 0, ///< An optional array of pointers to
58 ///< paths. If the array is null, no redirection is done. The array
59 ///< should have a size of at least three. The inferior process's
60 ///< stdin(0), stdout(1), and stderr(2) will be redirected to the
61 ///< corresponding paths.
62 ///< When an empty path is passed in, the corresponding file
6563 ///< descriptor will be disconnected (ie, /dev/null'd) in a portable
6664 ///< way.
6765 unsigned secondsToWait = 0, ///< If non-zero, this specifies the amount
7977 ///< program.
8078 bool *ExecutionFailed = 0);
8179
82 int ExecuteAndWait(StringRef path, const char **args, const char **env = 0,
83 const StringRef **redirects = 0,
84 unsigned secondsToWait = 0, unsigned memoryLimit = 0,
85 std::string *ErrMsg = 0, bool *ExecutionFailed = 0);
86
8780 /// Similar to ExecuteAndWait, but return immediately.
88 void ExecuteNoWait(const Path &path, const char **args, const char **env = 0,
89 const sys::Path **redirects = 0, unsigned memoryLimit = 0,
81 void ExecuteNoWait(StringRef Program, const char **args, const char **env = 0,
82 const StringRef **redirects = 0, unsigned memoryLimit = 0,
9083 std::string *ErrMsg = 0);
9184
9285 // Return true if the given arguments fit within system-specific
1515 #include "llvm/Support/CommandLine.h"
1616 #include "llvm/Support/FileSystem.h"
1717 #include "llvm/Support/Path.h"
18 #include "llvm/Support/PathV1.h"
1819 #include "llvm/Support/Program.h"
1920 using namespace llvm;
2021
8485 ExecGraphViewer(StringRef ExecPath, std::vector &args,
8586 StringRef Filename, bool wait, std::string &ErrMsg) {
8687 if (wait) {
87 if (sys::ExecuteAndWait(sys::Path(ExecPath), &args[0],0,0,0,0,&ErrMsg)) {
88 if (sys::ExecuteAndWait(ExecPath, &args[0],0,0,0,0,&ErrMsg)) {
8889 errs() << "Error: " << ErrMsg << "\n";
8990 return false;
9091 }
9394 errs() << " done. \n";
9495 }
9596 else {
96 sys::ExecuteNoWait(sys::Path(ExecPath), &args[0],0,0,0,&ErrMsg);
97 sys::ExecuteNoWait(ExecPath, &args[0],0,0,0,&ErrMsg);
9798 errs() << "Remember to erase graph file: " << Filename.str() << "\n";
9899 }
99100 return true;
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "llvm/Support/Program.h"
14 #include "llvm/Support/PathV1.h"
1415 #include "llvm/Config/config.h"
1516 #include "llvm/Support/system_error.h"
1617 using namespace llvm;
2829 static int Wait(void *&Data, const Path &path, unsigned secondsToWait,
2930 std::string *ErrMsg);
3031
31 int sys::ExecuteAndWait(StringRef path, const char **args, const char **env,
32
33 static bool Execute(void **Data, StringRef Program, const char **args,
34 const char **env, const StringRef **Redirects,
35 unsigned memoryLimit, std::string *ErrMsg) {
36 Path P(Program);
37 if (!Redirects)
38 return Execute(Data, P, args, env, 0, memoryLimit, ErrMsg);
39 Path IO[3];
40 const Path *IOP[3];
41 for (int I = 0; I < 3; ++I) {
42 if (Redirects[I]) {
43 IO[I] = *Redirects[I];
44 IOP[I] = &IO[I];
45 } else {
46 IOP[I] = 0;
47 }
48 }
49
50 return Execute(Data, P, args, env, IOP, memoryLimit, ErrMsg);
51 }
52
53 static int Wait(void *&Data, StringRef Program, unsigned secondsToWait,
54 std::string *ErrMsg) {
55 Path P(Program);
56 return Wait(Data, P, secondsToWait, ErrMsg);
57 }
58
59 int sys::ExecuteAndWait(StringRef Program, const char **args, const char **envp,
3260 const StringRef **redirects, unsigned secondsToWait,
3361 unsigned memoryLimit, std::string *ErrMsg,
3462 bool *ExecutionFailed) {
35 Path P(path);
36 if (!redirects)
37 return ExecuteAndWait(P, args, env, 0, secondsToWait, memoryLimit, ErrMsg,
38 ExecutionFailed);
39 Path IO[3];
40 const Path *IOP[3];
41 for (int I = 0; I < 3; ++I) {
42 if (redirects[I]) {
43 IO[I] = *redirects[I];
44 IOP[I] = &IO[I];
45 } else {
46 IOP[I] = 0;
47 }
48 }
49
50 return ExecuteAndWait(P, args, env, IOP, secondsToWait, memoryLimit, ErrMsg,
51 ExecutionFailed);
52 }
53
54 int sys::ExecuteAndWait(const Path &path, const char **args, const char **envp,
55 const Path **redirects, unsigned secondsToWait,
56 unsigned memoryLimit, std::string *ErrMsg,
57 bool *ExecutionFailed) {
5863 void *Data = 0;
59 if (Execute(&Data, path, args, envp, redirects, memoryLimit, ErrMsg)) {
64 if (Execute(&Data, Program, args, envp, redirects, memoryLimit, ErrMsg)) {
6065 if (ExecutionFailed) *ExecutionFailed = false;
61 return Wait(Data, path, secondsToWait, ErrMsg);
66 return Wait(Data, Program, secondsToWait, ErrMsg);
6267 }
6368 if (ExecutionFailed) *ExecutionFailed = true;
6469 return -1;
6570 }
6671
67 void sys::ExecuteNoWait(const Path &path, const char **args, const char **envp,
68 const Path **redirects, unsigned memoryLimit,
72 void sys::ExecuteNoWait(StringRef Program, const char **args, const char **envp,
73 const StringRef **redirects, unsigned memoryLimit,
6974 std::string *ErrMsg) {
70 Execute(/*Data*/ 0, path, args, envp, redirects, memoryLimit, ErrMsg);
75 Execute(/*Data*/ 0, Program, args, envp, redirects, memoryLimit, ErrMsg);
7176 }
7277
7378 // Include the platform-specific parts of this class.
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "llvm/Support/SystemUtils.h"
15 #include "llvm/Support/PathV1.h"
1516 #include "llvm/Support/Process.h"
1617 #include "llvm/Support/Program.h"
1718 #include "llvm/Support/raw_ostream.h"
199199 prog = tool;
200200
201201 // Redirect stdout and stderr to nowhere if SilencePasses is given
202 sys::Path Nowhere;
203 const sys::Path *Redirects[3] = {0, &Nowhere, &Nowhere};
204
205 int result =
206 sys::ExecuteAndWait(prog, Args.data(), 0, (SilencePasses ? Redirects : 0),
207 Timeout, MemoryLimit, &ErrMsg);
202 StringRef Nowhere;
203 const StringRef *Redirects[3] = {0, &Nowhere, &Nowhere};
204
205 int result = sys::ExecuteAndWait(prog.str(), Args.data(), 0,
206 (SilencePasses ? Redirects : 0), Timeout,
207 MemoryLimit, &ErrMsg);
208208
209209 // If we are supposed to delete the bitcode file or if the passes crashed,
210210 // remove it now. This may fail if the file was never created, but that's ok.
6060 unsigned NumSeconds = 0,
6161 unsigned MemoryLimit = 0,
6262 std::string *ErrMsg = 0) {
63 const sys::Path P[3] = { sys::Path(StdInFile), sys::Path(StdOutFile),
64 sys::Path(StdErrFile) };
65 const sys::Path* redirects[3];
66 for (int I = 0; I < 3; ++I)
67 redirects[I] = &P[I];
63 const StringRef *Redirects[3] = { &StdInFile, &StdOutFile, &StdErrFile };
6864
6965 #if 0 // For debug purposes
7066 {
7571 }
7672 #endif
7773
78 return sys::ExecuteAndWait(sys::Path(ProgramPath), Args, 0, redirects,
74 return sys::ExecuteAndWait(ProgramPath, Args, 0, Redirects,
7975 NumSeconds, MemoryLimit, ErrMsg);
8076 }
8177
9288 StringRef StdErrFile,
9389 unsigned NumSeconds = 0,
9490 unsigned MemoryLimit = 0) {
95 const sys::Path P[3] = { sys::Path(StdInFile), sys::Path(StdOutFile),
96 sys::Path(StdErrFile) };
97 const sys::Path* redirects[3];
98 for (int I = 0; I < 3; ++I)
99 redirects[I] = &P[I];
91 const StringRef *Redirects[3] = { &StdInFile, &StdOutFile, &StdErrFile };
10092
10193 #if 0 // For debug purposes
10294 {
108100 #endif
109101
110102 // Run the program remotely with the remote client
111 int ReturnCode = sys::ExecuteAndWait(sys::Path(RemoteClientPath), Args, 0,
112 redirects, NumSeconds, MemoryLimit);
103 int ReturnCode = sys::ExecuteAndWait(RemoteClientPath, Args, 0,
104 Redirects, NumSeconds, MemoryLimit);
113105
114106 // Has the remote client fail?
115107 if (255 == ReturnCode) {
1818 #include "llvm/Support/Errno.h"
1919 #include "llvm/Support/MemoryBuffer.h"
2020 #include "llvm/Support/Path.h"
21 #include "llvm/Support/PathV1.h"
2122 #include "llvm/Support/Program.h"
2223 #include "llvm/Support/ToolOutputFile.h"
2324 #include "llvm/Support/system_error.h"
88
99 #include "llvm/Support/CommandLine.h"
1010 #include "llvm/Support/Path.h"
11 #include "llvm/Support/PathV1.h"
1112 #include "llvm/Support/Program.h"
1213 #include "gtest/gtest.h"
1314
7374 bool ExecutionFailed;
7475 // Redirect stdout and stdin to NUL, but let stderr through.
7576 #ifdef LLVM_ON_WIN32
76 Path nul("NUL");
77 StringRef nul("NUL");
7778 #else
78 Path nul("/dev/null");
79 StringRef nul("/dev/null");
7980 #endif
80 const Path *redirects[] = { &nul, &nul, 0 };
81 int rc =
82 ExecuteAndWait(my_exe, argv, &envp[0], redirects, /*secondsToWait=*/ 10,
83 /*memoryLimit=*/ 0, &error, &ExecutionFailed);
81 const StringRef *redirects[] = { &nul, &nul, 0 };
82 int rc = ExecuteAndWait(my_exe.str(), argv, &envp[0], redirects,
83 /*secondsToWait=*/ 10, /*memoryLimit=*/ 0, &error,
84 &ExecutionFailed);
8485 EXPECT_FALSE(ExecutionFailed) << error;
8586 EXPECT_EQ(0, rc);
8687 }
1515 std::string Program = sys::FindProgramByName(argv[1]);
1616
1717 std::string ErrMsg;
18 int Result =
19 sys::ExecuteAndWait(sys::Path(Program), argv + 1, 0, 0, 0, 0, &ErrMsg);
18 int Result = sys::ExecuteAndWait(Program, argv + 1, 0, 0, 0, 0, &ErrMsg);
2019 if (Result < 0) {
2120 errs() << "Error: " << ErrMsg << "\n";
2221 return 1;