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