diff options
Diffstat (limited to 'libbuild2/utility.ixx')
-rw-r--r-- | libbuild2/utility.ixx | 177 |
1 files changed, 165 insertions, 12 deletions
diff --git a/libbuild2/utility.ixx b/libbuild2/utility.ixx index aedfc94..58ea8db 100644 --- a/libbuild2/utility.ixx +++ b/libbuild2/utility.ixx @@ -6,42 +6,195 @@ namespace build2 { inline bool - run_wait (cstrings& args, process& pr, const location& loc) + run_wait (const cstrings& args, process& pr, const location& loc) { return run_wait (args.data (), pr, loc); } - // Note: currently this function is also used in a run() implementations. + // Note: these functions are also used in the run() implementations. // LIBBUILD2_SYMEXPORT bool - run_finish_impl (const char*[], + run_finish_impl (const char* const*, process&, - bool error, + bool fail, const string&, - const location& = location ()); + uint16_t, + bool = false, + const location& = {}); + + LIBBUILD2_SYMEXPORT bool + run_finish_impl (diag_buffer&, + const char* const*, + process&, + bool fail, + uint16_t, + bool = false, + const location& = {}); inline void - run_finish (const char* args[], + run_finish (const char* const* args, process& pr, - const string& l, + uint16_t v, + bool on, const location& loc) { - run_finish_impl (args, pr, true /* error */, l, loc); + run_finish_impl (args, pr, true /* fail */, string (), v, on, loc); } inline void - run_finish (cstrings& args, process& pr, const location& loc) + run_finish (const cstrings& args, + process& pr, + uint16_t v, + bool on, + const location& loc) + { + run_finish (args.data (), pr, v, on, loc); + } + + inline void + run_finish (const char* const* args, + process& pr, + const string& l, + uint16_t v, + bool on, + const location& loc) + { + run_finish_impl (args, pr, true, l, v, on, loc); + } + + inline bool + run_finish_code (const char* const* args, + process& pr, + uint16_t v, + bool on, + const location& loc) + { + return run_finish_impl (args, pr, false, string (), v, on, loc); + } + + inline bool + run_finish_code (const cstrings& args, + process& pr, + uint16_t v, + bool on, + const location& loc) { - run_finish (args.data (), pr, string (), loc); + return run_finish_code (args.data (), pr, v, on, loc); } inline bool - run_finish_code (const char* args[], + run_finish_code (const char* const* args, process& pr, const string& l, + uint16_t v, + bool on, + const location& loc) + { + return run_finish_impl (args, pr, false, l, v, on, loc); + } + + inline void + run_finish (diag_buffer& dbuf, + const char* const* args, + process& pr, + uint16_t v, + bool on, + const location& loc) + { + run_finish_impl (dbuf, args, pr, true /* fail */, v, on, loc); + } + + inline void + run_finish (diag_buffer& dbuf, + const cstrings& args, + process& pr, + uint16_t v, + bool on, + const location& loc) + { + run_finish_impl (dbuf, args.data (), pr, true, v, on, loc); + } + + inline bool + run_finish_code (diag_buffer& dbuf, + const char* const* args, + process& pr, + uint16_t v, + bool on, + const location& loc) + { + return run_finish_impl (dbuf, args, pr, false, v, on, loc); + } + + inline bool + run_finish_code (diag_buffer& dbuf, + const cstrings& args, + process& pr, + uint16_t v, + bool on, const location& loc) { - return run_finish_impl (args, pr, false /* error */, l, loc); + return run_finish_impl (dbuf, args.data (), pr, false, v, on, loc); + } + + template <typename T, typename F> + inline T + run (context& ctx, + uint16_t verbosity, + const process_env& pe, + const char* const* args, + F&& f, + bool err, + bool ignore_exit, + sha256* checksum) + { + T r; + if (!run (ctx, + verbosity, + pe, args, + verbosity - 1, + [&r, &f] (string& l, bool last) // Small function optimmization. + { + r = f (l, last); + return r.empty (); + }, + true /* trim */, + err, + ignore_exit, + checksum)) + r = T (); + + return r; + } + + template <typename T, typename F> + inline T + run (context& ctx, + const process_env& pe, + const char* const* args, + uint16_t finish_verbosity, + F&& f, + bool err, + bool ignore_exit, + sha256* checksum) + { + T r; + if (!run (ctx, + verb_never, + pe, args, + finish_verbosity, + [&r, &f] (string& l, bool last) + { + r = f (l, last); + return r.empty (); + }, + true /* trim */, + err, + ignore_exit, + checksum)) + r = T (); + + return r; } inline void |