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