2004-08-29 19:20:41 +00:00
|
|
|
//===-- Program.cpp - Implement OS Program Concept --------------*- C++ -*-===//
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2004-08-29 19:20:41 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:55:34 +00:00
|
|
|
//
|
2004-08-29 19:20:41 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2014-06-20 01:36:00 +00:00
|
|
|
// This file implements the operating system Program concept.
|
2004-08-29 19:20:41 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "llvm/Support/Program.h"
|
2004-12-27 06:16:25 +00:00
|
|
|
#include "llvm/Config/config.h"
|
2014-06-12 17:38:55 +00:00
|
|
|
#include <system_error>
|
2010-04-18 03:33:55 +00:00
|
|
|
using namespace llvm;
|
2004-08-29 19:20:41 +00:00
|
|
|
using namespace sys;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//=== WARNING: Implementation here must contain only TRULY operating system
|
2005-04-21 22:55:34 +00:00
|
|
|
//=== independent code.
|
2004-08-29 19:20:41 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-10-01 14:28:18 +00:00
|
|
|
static bool Execute(ProcessInfo &PI, StringRef Program, const char **args,
|
2013-06-13 20:25:38 +00:00
|
|
|
const char **env, const StringRef **Redirects,
|
2013-06-14 19:38:45 +00:00
|
|
|
unsigned memoryLimit, std::string *ErrMsg);
|
2013-06-13 20:06:28 +00:00
|
|
|
|
2013-06-13 20:25:38 +00:00
|
|
|
int sys::ExecuteAndWait(StringRef Program, const char **args, const char **envp,
|
|
|
|
const StringRef **redirects, unsigned secondsToWait,
|
2013-06-12 20:58:35 +00:00
|
|
|
unsigned memoryLimit, std::string *ErrMsg,
|
2013-03-26 23:35:00 +00:00
|
|
|
bool *ExecutionFailed) {
|
2013-10-01 14:28:18 +00:00
|
|
|
ProcessInfo PI;
|
|
|
|
if (Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg)) {
|
|
|
|
if (ExecutionFailed)
|
|
|
|
*ExecutionFailed = false;
|
2014-05-31 01:36:02 +00:00
|
|
|
ProcessInfo Result = Wait(
|
|
|
|
PI, secondsToWait, /*WaitUntilTerminates=*/secondsToWait == 0, ErrMsg);
|
2013-10-01 14:28:18 +00:00
|
|
|
return Result.ReturnCode;
|
2013-03-26 23:35:00 +00:00
|
|
|
}
|
2013-10-01 14:28:18 +00:00
|
|
|
|
|
|
|
if (ExecutionFailed)
|
|
|
|
*ExecutionFailed = true;
|
|
|
|
|
2013-03-26 23:35:00 +00:00
|
|
|
return -1;
|
2009-07-18 21:43:12 +00:00
|
|
|
}
|
|
|
|
|
2013-10-01 14:28:18 +00:00
|
|
|
ProcessInfo sys::ExecuteNoWait(StringRef Program, const char **args,
|
|
|
|
const char **envp, const StringRef **redirects,
|
|
|
|
unsigned memoryLimit, std::string *ErrMsg,
|
|
|
|
bool *ExecutionFailed) {
|
|
|
|
ProcessInfo PI;
|
|
|
|
if (ExecutionFailed)
|
|
|
|
*ExecutionFailed = false;
|
|
|
|
if (!Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg))
|
|
|
|
if (ExecutionFailed)
|
|
|
|
*ExecutionFailed = true;
|
|
|
|
|
|
|
|
return PI;
|
2009-07-18 21:43:12 +00:00
|
|
|
}
|
|
|
|
|
2004-08-29 19:20:41 +00:00
|
|
|
// Include the platform-specific parts of this class.
|
2004-12-27 06:16:25 +00:00
|
|
|
#ifdef LLVM_ON_UNIX
|
2005-01-09 23:29:00 +00:00
|
|
|
#include "Unix/Program.inc"
|
2004-12-27 06:16:25 +00:00
|
|
|
#endif
|
|
|
|
#ifdef LLVM_ON_WIN32
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "Windows/Program.inc"
|
2004-12-27 06:16:25 +00:00
|
|
|
#endif
|