From e58957d6491a08ec212958457c29a14eec787279 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 11 Mar 2016 16:24:37 +0200 Subject: Implement --config-{guess,sub} options --- build2/utility | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'build2/utility') diff --git a/build2/utility b/build2/utility index 47eaf7d..0c442b0 100644 --- a/build2/utility +++ b/build2/utility @@ -67,6 +67,61 @@ namespace build2 next_word (const string&, size_t n, size_t& b, size_t& e, char d1 = ' ', char d2 = '\0'); + // Basic process utilities. + // + + // Start a process with the specified arguments printing the command at + // verbosity level 3 and higher. Redirect STDOUT to a pipe. If error is + // false, then redirecting STDERR to STDOUT (this can used to suppress + // diagnostics from the child process). Issue diagnostics and throw failed + // in case of an error. + // + process + start_run (const char* const* args, bool error); + + bool + finish_run (const char* const* args, bool error, process&, const string&); + + // Start the process as above and then call the specified function on each + // trimmed line of the output until it returns a non-empty object T (tested + // with T::empty()) which is then returned to the caller. + // + // The predicate can move the value out of the passed string but, if error + // is false, only in case of a "content match" (so that any diagnostics + // lines are left intact). + // + // If checksum is not NULL, then feed it the content of each line. + // + template + T + run (const char* const* args, + T (*) (string&), + bool error = true, + sha256* checksum = nullptr); + + template + inline T + run (const path& prog, + T (*f) (string&), + bool error = true, + sha256* checksum = nullptr) + { + const char* args[] = {prog.string ().c_str (), nullptr}; + return run (args, f, error, checksum); + } + + template + inline T + run (const path& prog, + const char* arg, + T (*f) (string&), + bool error = true, + sha256* checksum = nullptr) + { + const char* args[] = {prog.string ().c_str (), arg, nullptr}; + return run (args, f, error, checksum); + } + // Empty string and path. // extern const std::string empty_string; @@ -197,5 +252,6 @@ namespace build2 } #include +#include #endif // BUILD2_UTILITY -- cgit v1.1