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
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This header file implements the operating system Program concept.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
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"
|
2011-12-13 23:16:49 +00:00
|
|
|
#include "llvm/Support/system_error.h"
|
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-06-13 15:27:17 +00:00
|
|
|
static bool Execute(void **Data, const Path &path, const char **args,
|
2013-06-12 20:58:35 +00:00
|
|
|
const char **env, const sys::Path **redirects,
|
|
|
|
unsigned memoryLimit, std::string *ErrMsg);
|
|
|
|
|
|
|
|
static int Wait(void *&Data, const Path &path, unsigned secondsToWait,
|
|
|
|
std::string *ErrMsg);
|
|
|
|
|
2013-06-13 20:06:28 +00:00
|
|
|
int sys::ExecuteAndWait(StringRef path, const char **args, const char **env,
|
|
|
|
const StringRef **redirects, unsigned secondsToWait,
|
|
|
|
unsigned memoryLimit, std::string *ErrMsg,
|
|
|
|
bool *ExecutionFailed) {
|
|
|
|
Path P(path);
|
|
|
|
if (!redirects)
|
|
|
|
return ExecuteAndWait(P, args, env, 0, secondsToWait, memoryLimit, ErrMsg,
|
|
|
|
ExecutionFailed);
|
|
|
|
Path IO[3];
|
|
|
|
const Path *IOP[3];
|
|
|
|
for (int I = 0; I < 3; ++I) {
|
|
|
|
if (redirects[I]) {
|
|
|
|
IO[I] = *redirects[I];
|
|
|
|
IOP[I] = &IO[I];
|
|
|
|
} else {
|
|
|
|
IOP[I] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ExecuteAndWait(P, args, env, IOP, secondsToWait, memoryLimit, ErrMsg,
|
|
|
|
ExecutionFailed);
|
|
|
|
}
|
|
|
|
|
2013-06-12 20:58:35 +00:00
|
|
|
int sys::ExecuteAndWait(const Path &path, const char **args, const char **envp,
|
|
|
|
const Path **redirects, unsigned secondsToWait,
|
|
|
|
unsigned memoryLimit, std::string *ErrMsg,
|
2013-03-26 23:35:00 +00:00
|
|
|
bool *ExecutionFailed) {
|
2013-06-13 14:39:07 +00:00
|
|
|
void *Data = 0;
|
2013-06-13 15:27:17 +00:00
|
|
|
if (Execute(&Data, path, args, envp, redirects, memoryLimit, ErrMsg)) {
|
2013-03-26 23:35:00 +00:00
|
|
|
if (ExecutionFailed) *ExecutionFailed = false;
|
2013-06-12 20:58:35 +00:00
|
|
|
return Wait(Data, path, secondsToWait, ErrMsg);
|
2013-03-26 23:35:00 +00:00
|
|
|
}
|
|
|
|
if (ExecutionFailed) *ExecutionFailed = true;
|
|
|
|
return -1;
|
2009-07-18 21:43:12 +00:00
|
|
|
}
|
|
|
|
|
2013-06-12 20:58:35 +00:00
|
|
|
void sys::ExecuteNoWait(const Path &path, const char **args, const char **envp,
|
|
|
|
const Path **redirects, unsigned memoryLimit,
|
|
|
|
std::string *ErrMsg) {
|
2013-06-13 15:27:17 +00:00
|
|
|
Execute(/*Data*/ 0, path, args, envp, redirects, memoryLimit, ErrMsg);
|
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
|