From 609baa376a6f3e0c3930555c5055e6da193fd8a8 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 12 Jun 2013 20:42:59 +0000 Subject: Add global versions of some Program static methods. This is a temporary stepping stone for moving them out of Program. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183860 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/Program.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'include/llvm/Support/Program.h') diff --git a/include/llvm/Support/Program.h b/include/llvm/Support/Program.h index 08a64de..db12a15 100644 --- a/include/llvm/Support/Program.h +++ b/include/llvm/Support/Program.h @@ -17,6 +17,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/Support/Path.h" #include "llvm/Support/PathV1.h" +#include "llvm/Support/system_error.h" namespace llvm { class error_code; @@ -143,6 +144,24 @@ namespace sys { }; + inline int ExecuteAndWait(const Path &path, const char **args, + const char **env = 0, + const sys::Path **redirects = 0, + unsigned secondsToWait = 0, + unsigned memoryLimit = 0, std::string *ErrMsg = 0, + bool *ExecutionFailed = 0) { + return Program::ExecuteAndWait(path, args, env, redirects, secondsToWait, + memoryLimit, ErrMsg, ExecutionFailed); + } + + inline Path FindProgramByName(const std::string& name) { + return Program::FindProgramByName(name); + } + + inline error_code ChangeStdoutToBinary() { + return Program::ChangeStdoutToBinary(); + } + // Return true if the given arguments fit within system-specific // argument length limits. bool argumentsFitWithinSystemLimits(ArrayRef Args); -- cgit v1.1 From 9f1d9fd1964d82f3e801efb71518144492cdf290 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 12 Jun 2013 20:58:35 +0000 Subject: Remove the program class. It was only used to implement ExecuteAndWait and ExecuteNoWait. Expose just those two functions and make Execute and Wait implementations details. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183864 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/Program.h | 159 +++++++++++------------------------------ 1 file changed, 41 insertions(+), 118 deletions(-) (limited to 'include/llvm/Support/Program.h') diff --git a/include/llvm/Support/Program.h b/include/llvm/Support/Program.h index db12a15..dac377a 100644 --- a/include/llvm/Support/Program.h +++ b/include/llvm/Support/Program.h @@ -22,49 +22,42 @@ namespace llvm { class error_code; namespace sys { - - // TODO: Add operations to communicate with the process, redirect its I/O, - // etc. - - /// This class provides an abstraction for programs that are executable by the - /// operating system. It provides a platform generic way to find executable - /// programs from the path and to execute them in various ways. The sys::Path - /// class is used to specify the location of the Program. - /// @since 1.4 - /// @brief An abstraction for finding and executing programs. - class Program { - /// Opaque handle for target specific data. - void *Data_; - - // Noncopyable. - Program(const Program& other) LLVM_DELETED_FUNCTION; - Program& operator=(const Program& other) LLVM_DELETED_FUNCTION; - - /// @name Methods - /// @{ - - Program(); - ~Program(); - - /// This function executes the program using the \p arguments provided. The - /// invoked program will inherit the stdin, stdout, and stderr file - /// descriptors, the environment and other configuration settings of the - /// invoking program. If Path::executable() does not return true when this - /// function is called then a std::string is thrown. - /// @returns false in case of error, true otherwise. - /// @see FindProgramByName - /// @brief Executes the program with the given set of \p args. - bool Execute - ( const Path& path, ///< sys::Path object providing the path of the + /// This static constructor (factory) will attempt to locate a program in + /// the operating system's file system using some pre-determined set of + /// locations to search (e.g. the PATH on Unix). Paths with slashes are + /// returned unmodified. + /// @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. + /// @brief Construct a Program by finding it by name. + Path FindProgramByName(const std::string& name); + + // These functions change the specified standard stream (stdin, stdout, or + // stderr) to binary mode. They return errc::success if the specified stream + // was changed. Otherwise a platform dependent error is returned. + error_code ChangeStdinToBinary(); + error_code ChangeStdoutToBinary(); + error_code ChangeStderrToBinary(); + + /// This function executes the program using the arguments provided. The + /// invoked program will inherit the stdin, stdout, and stderr file + /// descriptors, the environment and other configuration settings of the + /// invoking program. + /// This function waits the program to finish. + /// @returns an integer result code indicating the status of the program. + /// A zero or positive value indicates the result code of the program. + /// -1 indicates failure to execute + /// -2 indicates a crash during execution or timeout + int ExecuteAndWait( + 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. - const char** args, ///< A vector of strings that are passed to the + const char **args, ///< A vector of strings that are passed to the ///< program. The first element should be the name of the program. ///< The list *must* be terminated by a null char* entry. - const char ** env = 0, ///< An optional vector of strings to use for + const char **env = 0, ///< An optional vector of strings to use for ///< the program's environment. If not provided, the current program's ///< environment will be used. - const sys::Path** redirects = 0, ///< An optional array of pointers to + const sys::Path **redirects = 0, ///< An optional array of pointers to ///< Paths. If the array is null, no redirection is done. The array ///< should have a size of at least three. If the pointer in the array ///< are not null, then the inferior process's stdin(0), stdout(1), @@ -72,95 +65,25 @@ namespace sys { ///< When an empty Path is passed in, the corresponding file ///< descriptor will be disconnected (ie, /dev/null'd) in a portable ///< way. + 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 + ///< it doesn't. unsigned memoryLimit = 0, ///< If non-zero, this specifies max. amount ///< of memory can be allocated by process. If memory usage will be ///< higher limit, the child is killed and this call returns. If zero ///< - no memory limit. - std::string* ErrMsg = 0 ///< If non-zero, provides a pointer to a string + 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. - ); - - /// This function waits for the program to exit. This function will block - /// the current program until the invoked program exits. - /// @returns an integer result code indicating the status of the program. - /// A zero or positive value indicates the result code of the program. - /// -1 indicates failure to execute - /// -2 indicates a crash during execution or timeout - /// @see Execute - /// @brief Waits for the program to exit. - int Wait - ( const Path& path, ///< The path to the child process executable. - unsigned secondsToWait, ///< 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 - ///< it doesn't. - std::string* ErrMsg ///< 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 waiting. - ); - - public: - /// This static constructor (factory) will attempt to locate a program in - /// the operating system's file system using some pre-determined set of - /// locations to search (e.g. the PATH on Unix). Paths with slashes are - /// returned unmodified. - /// @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. - /// @brief Construct a Program by finding it by name. - static Path FindProgramByName(const std::string& name); - - // These methods change the specified standard stream (stdin, stdout, or - // stderr) to binary mode. They return errc::success if the specified stream - // was changed. Otherwise a platform dependent error is returned. - static error_code ChangeStdinToBinary(); - static error_code ChangeStdoutToBinary(); - static error_code ChangeStderrToBinary(); - - /// A convenience function equivalent to Program prg; prg.Execute(..); - /// prg.Wait(..); - /// @see Execute, Wait - static int ExecuteAndWait(const Path& path, - const char** args, - const char ** env = 0, - const sys::Path** redirects = 0, - unsigned secondsToWait = 0, - unsigned memoryLimit = 0, - std::string* ErrMsg = 0, - bool *ExecutionFailed = 0); - - /// A convenience function equivalent to Program prg; prg.Execute(..); - /// @see Execute - static void ExecuteNoWait(const Path& path, - const char** args, - const char ** env = 0, - const sys::Path** redirects = 0, - unsigned memoryLimit = 0, - std::string* ErrMsg = 0); - - /// @} - - }; - - inline int ExecuteAndWait(const Path &path, const char **args, - const char **env = 0, - const sys::Path **redirects = 0, - unsigned secondsToWait = 0, - unsigned memoryLimit = 0, std::string *ErrMsg = 0, - bool *ExecutionFailed = 0) { - return Program::ExecuteAndWait(path, args, env, redirects, secondsToWait, - memoryLimit, ErrMsg, ExecutionFailed); - } - - inline Path FindProgramByName(const std::string& name) { - return Program::FindProgramByName(name); - } + bool *ExecutionFailed = 0); - inline error_code ChangeStdoutToBinary() { - return Program::ChangeStdoutToBinary(); - } + /// Similar to ExecuteAndWait, but return immediately. + void ExecuteNoWait(const Path &path, const char **args, const char **env = 0, + const sys::Path **redirects = 0, unsigned memoryLimit = 0, + std::string *ErrMsg = 0); // Return true if the given arguments fit within system-specific // argument length limits. -- cgit v1.1 From 6585b388cb7bfc623adb9e4dd910423f838e5d96 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 13 Jun 2013 19:25:37 +0000 Subject: Have sys::FindProgramByName return a std::string. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183928 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/Program.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/llvm/Support/Program.h') diff --git a/include/llvm/Support/Program.h b/include/llvm/Support/Program.h index dac377a..38fc8c2 100644 --- a/include/llvm/Support/Program.h +++ b/include/llvm/Support/Program.h @@ -29,7 +29,7 @@ namespace sys { /// @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. /// @brief Construct a Program by finding it by name. - Path FindProgramByName(const std::string& name); + std::string FindProgramByName(const std::string& name); // These functions change the specified standard stream (stdin, stdout, or // stderr) to binary mode. They return errc::success if the specified stream -- cgit v1.1 From a29ece1693ff16ff991e184f6e073c9fb30fcb4b Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 13 Jun 2013 20:06:28 +0000 Subject: Add a version of sys::ExecuteAndWait that takes StringRefs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183934 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/Program.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include/llvm/Support/Program.h') diff --git a/include/llvm/Support/Program.h b/include/llvm/Support/Program.h index 38fc8c2..c8729c7 100644 --- a/include/llvm/Support/Program.h +++ b/include/llvm/Support/Program.h @@ -80,6 +80,11 @@ namespace sys { ///< program. bool *ExecutionFailed = 0); + int ExecuteAndWait(StringRef path, const char **args, const char **env = 0, + const StringRef **redirects = 0, + unsigned secondsToWait = 0, unsigned memoryLimit = 0, + std::string *ErrMsg = 0, bool *ExecutionFailed = 0); + /// Similar to ExecuteAndWait, but return immediately. void ExecuteNoWait(const Path &path, const char **args, const char **env = 0, const sys::Path **redirects = 0, unsigned memoryLimit = 0, -- cgit v1.1 From 675e0ac0bfd6fb78423d9fbee9f50c1dec62c111 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 13 Jun 2013 20:25:38 +0000 Subject: Avoid using PathV1.h in Program.h. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183940 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/Program.h | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'include/llvm/Support/Program.h') diff --git a/include/llvm/Support/Program.h b/include/llvm/Support/Program.h index c8729c7..64a7e55 100644 --- a/include/llvm/Support/Program.h +++ b/include/llvm/Support/Program.h @@ -16,7 +16,6 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/Support/Path.h" -#include "llvm/Support/PathV1.h" #include "llvm/Support/system_error.h" namespace llvm { @@ -48,21 +47,20 @@ namespace sys { /// -1 indicates failure to execute /// -2 indicates a crash during execution or timeout int ExecuteAndWait( - 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. + StringRef Program, ///< Path of the program to be executed. It is + /// presumed this is the result of the FindProgramByName method. const char **args, ///< A vector of strings that are passed to the ///< program. The first element should be the name of the program. ///< The list *must* be terminated by a null char* entry. const char **env = 0, ///< An optional vector of strings to use for ///< the program's environment. If not provided, the current program's ///< environment will be used. - const sys::Path **redirects = 0, ///< An optional array of pointers to - ///< Paths. If the array is null, no redirection is done. The array - ///< should have a size of at least three. If the pointer in the array - ///< are not null, then the inferior process's stdin(0), stdout(1), - ///< and stderr(2) will be redirected to the corresponding Paths. - ///< When an empty Path is passed in, the corresponding file + const StringRef **redirects = 0, ///< An optional array of pointers to + ///< paths. If the array is null, no redirection is done. The array + ///< should have a size of at least three. The inferior process's + ///< stdin(0), stdout(1), and stderr(2) will be redirected to the + ///< corresponding paths. + ///< When an empty path is passed in, the corresponding file ///< descriptor will be disconnected (ie, /dev/null'd) in a portable ///< way. unsigned secondsToWait = 0, ///< If non-zero, this specifies the amount @@ -80,14 +78,9 @@ namespace sys { ///< program. bool *ExecutionFailed = 0); - int ExecuteAndWait(StringRef path, const char **args, const char **env = 0, - const StringRef **redirects = 0, - unsigned secondsToWait = 0, unsigned memoryLimit = 0, - std::string *ErrMsg = 0, bool *ExecutionFailed = 0); - /// Similar to ExecuteAndWait, but return immediately. - void ExecuteNoWait(const Path &path, const char **args, const char **env = 0, - const sys::Path **redirects = 0, unsigned memoryLimit = 0, + void ExecuteNoWait(StringRef Program, const char **args, const char **env = 0, + const StringRef **redirects = 0, unsigned memoryLimit = 0, std::string *ErrMsg = 0); // Return true if the given arguments fit within system-specific -- cgit v1.1 From 593fcb56b37857d64e58ac3be5277d3cfccb9492 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 25 Jun 2013 01:10:36 +0000 Subject: Create a replacement for sys::Path::PathSeparator. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184806 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/Program.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include/llvm/Support/Program.h') diff --git a/include/llvm/Support/Program.h b/include/llvm/Support/Program.h index 64a7e55..5134351 100644 --- a/include/llvm/Support/Program.h +++ b/include/llvm/Support/Program.h @@ -21,6 +21,15 @@ namespace llvm { class error_code; namespace sys { + + /// This is the OS-specific separator for PATH like environment variables: + // a colon on Unix or a semicolon on Windows. +#if defined(LLVM_ON_UNIX) + const char EnvPathSeparator = ':'; +#elif defined (LLVM_ON_WIN32) + const char EnvPathSeparator = ';'; +#endif + /// This static constructor (factory) will attempt to locate a program in /// the operating system's file system using some pre-determined set of /// locations to search (e.g. the PATH on Unix). Paths with slashes are -- cgit v1.1