/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/Support/Program.cpp
Line | Count | Source |
1 | | //===-- Program.cpp - Implement OS Program Concept --------------*- C++ -*-===// |
2 | | // |
3 | | // The LLVM Compiler Infrastructure |
4 | | // |
5 | | // This file is distributed under the University of Illinois Open Source |
6 | | // License. See LICENSE.TXT for details. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | // |
10 | | // This file implements the operating system Program concept. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | #include "llvm/Support/Program.h" |
15 | | #include "llvm/ADT/StringRef.h" |
16 | | #include "llvm/Config/config.h" |
17 | | #include <system_error> |
18 | | using namespace llvm; |
19 | | using namespace sys; |
20 | | |
21 | | //===----------------------------------------------------------------------===// |
22 | | //=== WARNING: Implementation here must contain only TRULY operating system |
23 | | //=== independent code. |
24 | | //===----------------------------------------------------------------------===// |
25 | | |
26 | | static bool Execute(ProcessInfo &PI, StringRef Program, const char **Args, |
27 | | const char **Env, ArrayRef<Optional<StringRef>> Redirects, |
28 | | unsigned MemoryLimit, std::string *ErrMsg); |
29 | | |
30 | | int sys::ExecuteAndWait(StringRef Program, const char **Args, const char **Envp, |
31 | | ArrayRef<Optional<StringRef>> Redirects, |
32 | | unsigned SecondsToWait, unsigned MemoryLimit, |
33 | 24.1k | std::string *ErrMsg, bool *ExecutionFailed) { |
34 | 24.1k | assert(Redirects.empty() || Redirects.size() == 3); |
35 | 24.1k | ProcessInfo PI; |
36 | 24.1k | if (Execute(PI, Program, Args, Envp, Redirects, MemoryLimit, ErrMsg)24.1k ) { |
37 | 24.1k | if (ExecutionFailed) |
38 | 23.9k | *ExecutionFailed = false; |
39 | 24.1k | ProcessInfo Result = Wait( |
40 | 24.1k | PI, SecondsToWait, /*WaitUntilTerminates=*/SecondsToWait == 0, ErrMsg); |
41 | 24.1k | return Result.ReturnCode; |
42 | 24.1k | } |
43 | 3 | |
44 | 3 | if (3 ExecutionFailed3 ) |
45 | 2 | *ExecutionFailed = true; |
46 | 24.1k | |
47 | 24.1k | return -1; |
48 | 24.1k | } |
49 | | |
50 | | ProcessInfo sys::ExecuteNoWait(StringRef Program, const char **Args, |
51 | | const char **Envp, |
52 | | ArrayRef<Optional<StringRef>> Redirects, |
53 | | unsigned MemoryLimit, std::string *ErrMsg, |
54 | 3 | bool *ExecutionFailed) { |
55 | 3 | assert(Redirects.empty() || Redirects.size() == 3); |
56 | 3 | ProcessInfo PI; |
57 | 3 | if (ExecutionFailed) |
58 | 3 | *ExecutionFailed = false; |
59 | 3 | if (!Execute(PI, Program, Args, Envp, Redirects, MemoryLimit, ErrMsg)) |
60 | 1 | if (1 ExecutionFailed1 ) |
61 | 1 | *ExecutionFailed = true; |
62 | 3 | |
63 | 3 | return PI; |
64 | 3 | } |
65 | | |
66 | | // Include the platform-specific parts of this class. |
67 | | #ifdef LLVM_ON_UNIX |
68 | | #include "Unix/Program.inc" |
69 | | #endif |
70 | | #ifdef LLVM_ON_WIN32 |
71 | | #include "Windows/Program.inc" |
72 | | #endif |