2004-08-29 07:29:35 +02:00
|
|
|
//===- llvm/System/Program.h ------------------------------------*- C++ -*-===//
|
2005-04-21 22:48:15 +02:00
|
|
|
//
|
2004-08-29 07:29:35 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2005-04-21 22:48:15 +02:00
|
|
|
// This file was developed by Reid Spencer and is distributed under the
|
2004-08-29 07:29:35 +02:00
|
|
|
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 22:48:15 +02:00
|
|
|
//
|
2004-08-29 07:29:35 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares the llvm::sys::Program class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_SYSTEM_PROGRAM_H
|
|
|
|
#define LLVM_SYSTEM_PROGRAM_H
|
|
|
|
|
|
|
|
#include "llvm/System/Path.h"
|
2006-07-26 18:55:39 +02:00
|
|
|
#include "llvm/System/IncludeFile.h"
|
2004-08-29 07:29:35 +02:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace sys {
|
|
|
|
|
|
|
|
/// This class provides an abstraction for programs that are executable by the
|
2004-09-13 23:48:44 +02:00
|
|
|
/// operating system. It provides a platform generic way to find executable
|
2004-12-14 05:17:12 +01:00
|
|
|
/// programs from the path and to execute them in various ways. The sys::Path
|
|
|
|
/// class is used to specify the location of the Program.
|
2004-08-29 07:29:35 +02:00
|
|
|
/// @since 1.4
|
2004-09-13 23:48:44 +02:00
|
|
|
/// @brief An abstraction for finding and executing programs.
|
|
|
|
class Program {
|
|
|
|
/// @name Methods
|
2004-08-29 07:29:35 +02:00
|
|
|
/// @{
|
|
|
|
public:
|
|
|
|
/// This static constructor (factory) will attempt to locate a program in
|
2005-04-21 22:48:15 +02:00
|
|
|
/// the operating system's file system using some pre-determined set of
|
|
|
|
/// locations to search (e.g. the PATH on Unix).
|
2004-08-29 07:29:35 +02:00
|
|
|
/// @returns A Path object initialized to the path of the program or a
|
|
|
|
/// Path object that is empty (invalid) if the program could not be found.
|
|
|
|
/// @throws nothing
|
|
|
|
/// @brief Construct a Program by finding it by name.
|
2004-09-13 23:48:44 +02:00
|
|
|
static Path FindProgramByName(const std::string& name);
|
2004-08-29 07:29:35 +02:00
|
|
|
|
|
|
|
/// This function executes the program using the \p arguments provided and
|
|
|
|
/// waits for the program to exit. This function will block the current
|
2005-04-21 22:48:15 +02:00
|
|
|
/// program until the invoked program exits. The invoked program will
|
2004-08-29 07:29:35 +02:00
|
|
|
/// inherit the stdin, stdout, and stderr file descriptors, the
|
2004-12-14 05:17:12 +01:00
|
|
|
/// environment and other configuration settings of the invoking program.
|
2004-08-29 07:29:35 +02:00
|
|
|
/// If Path::executable() does not return true when this function is
|
2005-04-21 22:48:15 +02:00
|
|
|
/// called then a std::string is thrown.
|
2004-08-29 07:29:35 +02:00
|
|
|
/// @returns an integer result code indicating the status of the program.
|
2006-01-08 23:41:22 +01:00
|
|
|
/// A zero or positive value indicates the result code of the program. A
|
2006-08-21 08:00:58 +02:00
|
|
|
/// negative value is the signal number on which it terminated.
|
2004-09-13 23:48:44 +02:00
|
|
|
/// @see FindProgrambyName
|
2004-12-14 05:17:12 +01:00
|
|
|
/// @brief Executes the program with the given set of \p args.
|
|
|
|
static int ExecuteAndWait(
|
2006-05-19 21:07:54 +02:00
|
|
|
const Path& path, ///< sys::Path object providing the path of the
|
|
|
|
///< program to be executed. It is presumed this is the result of
|
|
|
|
///< the FindProgramByName method.
|
2005-04-21 22:48:15 +02:00
|
|
|
const char** args, ///< A vector of strings that are passed to the
|
|
|
|
///< program. The first element should be the name of the program.
|
2005-01-11 07:37:27 +01:00
|
|
|
///< The list *must* be terminated by a null char* entry.
|
2005-04-21 22:48:15 +02:00
|
|
|
const char ** env = 0, ///< An optional vector of strings to use for
|
2005-01-11 07:37:27 +01:00
|
|
|
///< the program's environment. If not provided, the current program's
|
|
|
|
///< environment will be used.
|
2005-04-21 22:48:15 +02:00
|
|
|
const sys::Path** redirects = 0, ///< An optional array of pointers to
|
|
|
|
///< Paths. If the array is null, no redirection is done. The array
|
2005-01-11 07:37:27 +01:00
|
|
|
///< should have a size of at least three. If the pointer in the array
|
2005-04-21 22:48:15 +02:00
|
|
|
///< are not null, then the inferior process's stdin(0), stdout(1),
|
|
|
|
///< and stderr(2) will be redirected to the corresponding Paths.
|
2006-08-21 08:00:58 +02:00
|
|
|
unsigned secondsToWait = 0, ///< If non-zero, this specifies the amount
|
2005-04-21 22:48:15 +02:00
|
|
|
///< of time to wait for the child process to exit. If the time
|
|
|
|
///< expires, the child is killed and this call returns. If zero,
|
|
|
|
///< this function will wait until the child finishes or forever if
|
2005-01-11 07:37:27 +01:00
|
|
|
///< it doesn't.
|
2006-08-21 08:00:58 +02:00
|
|
|
std::string* ErrMsg = 0 ///< If non-zero, provides a pointer to a string
|
|
|
|
///< instance in which error messages will be returned. If the string
|
|
|
|
///< is non-empty upon return an error occurred while invoking the
|
|
|
|
///< program.
|
2004-12-14 05:17:12 +01:00
|
|
|
);
|
2006-06-08 01:18:34 +02:00
|
|
|
// These methods change the specified standard stream (stdin or stdout) to
|
2006-08-21 08:00:58 +02:00
|
|
|
// binary mode. They return true if an error occurred
|
|
|
|
static bool ChangeStdinToBinary();
|
|
|
|
static bool ChangeStdoutToBinary();
|
|
|
|
/// @}
|
2004-08-29 07:29:35 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-26 18:55:39 +02:00
|
|
|
FORCE_DEFINING_FILE_TO_BE_LINKED(SystemProgram)
|
2004-08-29 07:29:35 +02:00
|
|
|
|
|
|
|
#endif
|