/home/arjun/llvm-project/llvm/lib/Support/Program.cpp
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | //===-- Program.cpp - Implement OS Program Concept --------------*- C++ -*-===// | 
| 2 |  | // | 
| 3 |  | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | 
| 4 |  | // See https://llvm.org/LICENSE.txt for license information. | 
| 5 |  | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | 
| 6 |  | // | 
| 7 |  | //===----------------------------------------------------------------------===// | 
| 8 |  | // | 
| 9 |  | //  This file implements the operating system Program concept. | 
| 10 |  | // | 
| 11 |  | //===----------------------------------------------------------------------===// | 
| 12 |  |  | 
| 13 |  | #include "llvm/Support/Program.h" | 
| 14 |  | #include "llvm/ADT/StringRef.h" | 
| 15 |  | #include "llvm/Config/llvm-config.h" | 
| 16 |  | #include <system_error> | 
| 17 |  | using namespace llvm; | 
| 18 |  | using namespace sys; | 
| 19 |  |  | 
| 20 |  | //===----------------------------------------------------------------------===// | 
| 21 |  | //=== WARNING: Implementation here must contain only TRULY operating system | 
| 22 |  | //===          independent code. | 
| 23 |  | //===----------------------------------------------------------------------===// | 
| 24 |  |  | 
| 25 |  | static bool Execute(ProcessInfo &PI, StringRef Program, | 
| 26 |  |                     ArrayRef<StringRef> Args, Optional<ArrayRef<StringRef>> Env, | 
| 27 |  |                     ArrayRef<Optional<StringRef>> Redirects, | 
| 28 |  |                     unsigned MemoryLimit, std::string *ErrMsg); | 
| 29 |  |  | 
| 30 |  | int sys::ExecuteAndWait(StringRef Program, ArrayRef<StringRef> Args, | 
| 31 |  |                         Optional<ArrayRef<StringRef>> Env, | 
| 32 |  |                         ArrayRef<Optional<StringRef>> Redirects, | 
| 33 |  |                         unsigned SecondsToWait, unsigned MemoryLimit, | 
| 34 | 0 |                         std::string *ErrMsg, bool *ExecutionFailed) { | 
| 35 | 0 |   assert(Redirects.empty() || Redirects.size() == 3); | 
| 36 | 0 |   ProcessInfo PI; | 
| 37 | 0 |   if (Execute(PI, Program, Args, Env, Redirects, MemoryLimit, ErrMsg)) { | 
| 38 | 0 |     if (ExecutionFailed) | 
| 39 | 0 |       *ExecutionFailed = false; | 
| 40 | 0 |     ProcessInfo Result = Wait( | 
| 41 | 0 |         PI, SecondsToWait, /*WaitUntilTerminates=*/SecondsToWait == 0, ErrMsg); | 
| 42 | 0 |     return Result.ReturnCode; | 
| 43 | 0 |   } | 
| 44 | 0 | 
 | 
| 45 | 0 |   if (ExecutionFailed) | 
| 46 | 0 |     *ExecutionFailed = true; | 
| 47 | 0 | 
 | 
| 48 | 0 |   return -1; | 
| 49 | 0 | } | 
| 50 |  |  | 
| 51 |  | ProcessInfo sys::ExecuteNoWait(StringRef Program, ArrayRef<StringRef> Args, | 
| 52 |  |                                Optional<ArrayRef<StringRef>> Env, | 
| 53 |  |                                ArrayRef<Optional<StringRef>> Redirects, | 
| 54 |  |                                unsigned MemoryLimit, std::string *ErrMsg, | 
| 55 | 0 |                                bool *ExecutionFailed) { | 
| 56 | 0 |   assert(Redirects.empty() || Redirects.size() == 3); | 
| 57 | 0 |   ProcessInfo PI; | 
| 58 | 0 |   if (ExecutionFailed) | 
| 59 | 0 |     *ExecutionFailed = false; | 
| 60 | 0 |   if (!Execute(PI, Program, Args, Env, Redirects, MemoryLimit, ErrMsg)) | 
| 61 | 0 |     if (ExecutionFailed) | 
| 62 | 0 |       *ExecutionFailed = true; | 
| 63 | 0 | 
 | 
| 64 | 0 |   return PI; | 
| 65 | 0 | } | 
| 66 |  |  | 
| 67 |  | bool sys::commandLineFitsWithinSystemLimits(StringRef Program, | 
| 68 | 0 |                                             ArrayRef<const char *> Args) { | 
| 69 | 0 |   SmallVector<StringRef, 8> StringRefArgs; | 
| 70 | 0 |   StringRefArgs.reserve(Args.size()); | 
| 71 | 0 |   for (const char *A : Args) | 
| 72 | 0 |     StringRefArgs.emplace_back(A); | 
| 73 | 0 |   return commandLineFitsWithinSystemLimits(Program, StringRefArgs); | 
| 74 | 0 | } | 
| 75 |  |  | 
| 76 |  | // Include the platform-specific parts of this class. | 
| 77 |  | #ifdef LLVM_ON_UNIX | 
| 78 |  | #include "Unix/Program.inc" | 
| 79 |  | #endif | 
| 80 |  | #ifdef _WIN32 | 
| 81 |  | #include "Windows/Program.inc" | 
| 82 |  | #endif |