2004-08-29 05:29:35 +00:00
|
|
|
//===- llvm/System/Program.h ------------------------------------*- C++ -*-===//
|
2005-04-21 20:48:15 +00:00
|
|
|
//
|
2004-08-29 05:29:35 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2005-04-21 20:48:15 +00:00
|
|
|
// This file was developed by Reid Spencer and is distributed under the
|
2004-08-29 05:29:35 +00:00
|
|
|
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 20:48:15 +00:00
|
|
|
//
|
2004-08-29 05:29:35 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares the llvm::sys::Program class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_SYSTEM_PROGRAM_H
|
|
|
|
#define LLVM_SYSTEM_PROGRAM_H
|
|
|
|
|
|
|
|
#include "llvm/System/Path.h"
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace sys {
|
|
|
|
|
|
|
|
/// This class provides an abstraction for programs that are executable by the
|
2004-09-13 21:48:44 +00:00
|
|
|
/// operating system. It provides a platform generic way to find executable
|
2004-12-14 04:17:12 +00: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 05:29:35 +00:00
|
|
|
/// @since 1.4
|
2004-09-13 21:48:44 +00:00
|
|
|
/// @brief An abstraction for finding and executing programs.
|
|
|
|
class Program {
|
|
|
|
/// @name Methods
|
2004-08-29 05:29:35 +00:00
|
|
|
/// @{
|
|
|
|
public:
|
|
|
|
/// This static constructor (factory) will attempt to locate a program in
|
2005-04-21 20:48:15 +00: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 05:29:35 +00: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 21:48:44 +00:00
|
|
|
static Path FindProgramByName(const std::string& name);
|
2004-08-29 05:29:35 +00: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 20:48:15 +00:00
|
|
|
/// program until the invoked program exits. The invoked program will
|
2004-08-29 05:29:35 +00:00
|
|
|
/// inherit the stdin, stdout, and stderr file descriptors, the
|
2004-12-14 04:17:12 +00:00
|
|
|
/// environment and other configuration settings of the invoking program.
|
2004-08-29 05:29:35 +00:00
|
|
|
/// If Path::executable() does not return true when this function is
|
2005-04-21 20:48:15 +00:00
|
|
|
/// called then a std::string is thrown.
|
2004-09-13 21:48:44 +00:00
|
|
|
/// @param path A sys::Path object providing the path of the program to be
|
|
|
|
/// executed. It is presumed this is the result of the FindProgramByName
|
|
|
|
/// method.
|
2004-08-29 05:29:35 +00:00
|
|
|
/// @returns an integer result code indicating the status of the program.
|
2004-12-14 04:17:12 +00:00
|
|
|
/// @throws std::string on a variety of error conditions or if the invoked
|
2004-08-29 05:29:35 +00:00
|
|
|
/// program aborted abnormally.
|
2004-09-13 21:48:44 +00:00
|
|
|
/// @see FindProgrambyName
|
2004-12-14 04:17:12 +00:00
|
|
|
/// @brief Executes the program with the given set of \p args.
|
|
|
|
static int ExecuteAndWait(
|
|
|
|
const Path& path, ///< The path to the program to execute
|
2005-04-21 20:48:15 +00: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 06:37:27 +00:00
|
|
|
///< The list *must* be terminated by a null char* entry.
|
2005-04-21 20:48:15 +00:00
|
|
|
const char ** env = 0, ///< An optional vector of strings to use for
|
2005-01-11 06:37:27 +00:00
|
|
|
///< the program's environment. If not provided, the current program's
|
|
|
|
///< environment will be used.
|
2005-04-21 20:48:15 +00: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 06:37:27 +00:00
|
|
|
///< should have a size of at least three. If the pointer in the array
|
2005-04-21 20:48:15 +00:00
|
|
|
///< are not null, then the inferior process's stdin(0), stdout(1),
|
|
|
|
///< and stderr(2) will be redirected to the corresponding Paths.
|
|
|
|
unsigned secondsToWait = 0 ///< If non-zero, this specifies the amount
|
|
|
|
///< 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 06:37:27 +00:00
|
|
|
///< it doesn't.
|
2004-12-14 04:17:12 +00:00
|
|
|
);
|
2004-08-29 05:29:35 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|