blob: 201d5c0d3056a45779acab6ecd9e4c4ab54672e1 [file] [log] [blame]
Reid Spencer52a7efa2004-08-29 19:20:41 +00001//===-- Program.cpp - Implement OS Program Concept --------------*- C++ -*-===//
Misha Brukmanf976c852005-04-21 22:55:34 +00002//
Reid Spencer52a7efa2004-08-29 19:20:41 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanf976c852005-04-21 22:55:34 +00007//
Reid Spencer52a7efa2004-08-29 19:20:41 +00008//===----------------------------------------------------------------------===//
9//
10// This header file implements the operating system Program concept.
11//
12//===----------------------------------------------------------------------===//
13
Michael J. Spencer1f6efa32010-11-29 18:16:10 +000014#include "llvm/Support/Program.h"
Reid Spencer424ac892004-12-27 06:16:25 +000015#include "llvm/Config/config.h"
Michael J. Spencerb92cb302011-12-13 23:16:49 +000016#include "llvm/Support/system_error.h"
Chris Lattnerb221ecb2010-04-18 03:33:55 +000017using namespace llvm;
Reid Spencer52a7efa2004-08-29 19:20:41 +000018using namespace sys;
19
20//===----------------------------------------------------------------------===//
21//=== WARNING: Implementation here must contain only TRULY operating system
Misha Brukmanf976c852005-04-21 22:55:34 +000022//=== independent code.
Reid Spencer52a7efa2004-08-29 19:20:41 +000023//===----------------------------------------------------------------------===//
24
Mikhail Glushenkov31406192009-07-18 21:43:12 +000025int
26Program::ExecuteAndWait(const Path& path,
27 const char** args,
28 const char** envp,
29 const Path** redirects,
30 unsigned secondsToWait,
31 unsigned memoryLimit,
Chad Rosier847e36f2013-03-26 23:35:00 +000032 std::string* ErrMsg,
33 bool *ExecutionFailed) {
Mikhail Glushenkov31406192009-07-18 21:43:12 +000034 Program prg;
Chad Rosier847e36f2013-03-26 23:35:00 +000035 if (prg.Execute(path, args, envp, redirects, memoryLimit, ErrMsg)) {
36 if (ExecutionFailed) *ExecutionFailed = false;
Andrew Trickdc5948d2011-05-21 00:56:46 +000037 return prg.Wait(path, secondsToWait, ErrMsg);
Chad Rosier847e36f2013-03-26 23:35:00 +000038 }
39 if (ExecutionFailed) *ExecutionFailed = true;
40 return -1;
Mikhail Glushenkov31406192009-07-18 21:43:12 +000041}
42
43void
44Program::ExecuteNoWait(const Path& path,
45 const char** args,
46 const char** envp,
47 const Path** redirects,
48 unsigned memoryLimit,
49 std::string* ErrMsg) {
50 Program prg;
51 prg.Execute(path, args, envp, redirects, memoryLimit, ErrMsg);
52}
53
Reid Spencer52a7efa2004-08-29 19:20:41 +000054// Include the platform-specific parts of this class.
Reid Spencer424ac892004-12-27 06:16:25 +000055#ifdef LLVM_ON_UNIX
Reid Spencerbccc8ab2005-01-09 23:29:00 +000056#include "Unix/Program.inc"
Reid Spencer424ac892004-12-27 06:16:25 +000057#endif
58#ifdef LLVM_ON_WIN32
Michael J. Spencer1f6efa32010-11-29 18:16:10 +000059#include "Windows/Program.inc"
Reid Spencer424ac892004-12-27 06:16:25 +000060#endif