aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/utility.ixx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-11-08 10:34:22 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-11-08 11:08:03 +0200
commit3bc0fc4c4496c345c79734dcd6dc56d44119aebf (patch)
treed058018aaf35641e461e51c2c20d374fd0d1684c /libbuild2/utility.ixx
parent84e6c7e62c9d1613af3cad81787b3f277d276140 (diff)
Make process exit diagnostics consistent
In particular, we now always print error message on non-0 exit except in cases where such exit is ignored.
Diffstat (limited to 'libbuild2/utility.ixx')
-rw-r--r--libbuild2/utility.ixx129
1 files changed, 114 insertions, 15 deletions
diff --git a/libbuild2/utility.ixx b/libbuild2/utility.ixx
index c122ec9..2447303 100644
--- a/libbuild2/utility.ixx
+++ b/libbuild2/utility.ixx
@@ -11,14 +11,16 @@ namespace build2
return run_wait (args.data (), pr, loc);
}
- // Note: currently this function is also used in run() implementations.
+ // Note: these functions are also used in the run() implementations.
//
LIBBUILD2_SYMEXPORT bool
run_finish_impl (const char* const*,
process&,
bool fail,
const string&,
- const location& = location ());
+ uint16_t,
+ bool = false,
+ const location& = {});
LIBBUILD2_SYMEXPORT bool
run_finish_impl (diag_buffer&,
@@ -26,36 +28,69 @@ namespace build2
process&,
bool fail,
uint16_t,
- const location&);
+ bool = false,
+ const location& = {});
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 /* fail */, string (), v, on, loc);
+ }
+
+ inline void
+ run_finish (const cstrings& args,
+ process& pr,
+ uint16_t v,
+ bool on,
const location& loc)
{
- run_finish_impl (args, pr, true /* fail */, l, loc);
+ run_finish (args.data (), pr, v, on, loc);
}
inline void
- run_finish (const cstrings& args, process& pr, const location& loc)
+ run_finish (const char* const* args,
+ process& pr,
+ const string& l,
+ uint16_t v,
+ bool on,
+ const location& loc)
{
- run_finish (args.data (), pr, string (), loc);
+ run_finish_impl (args, pr, true, l, v, on, loc);
}
inline bool
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, string (), v, on, loc);
+ }
+
+ inline bool
+ run_finish_code (const cstrings& args,
+ process& pr,
+ uint16_t v,
+ bool on,
const location& loc)
{
- return run_finish_impl (args, pr, false /* fail */, l, loc);
+ return run_finish_code (args.data (), pr, v, on, loc);
}
inline bool
- run_finish_code (const cstrings& args, process& pr, const location& loc)
+ run_finish_code (const char* const* args,
+ process& pr,
+ const string& l,
+ uint16_t v,
+ bool on,
+ const location& loc)
{
- return run_finish_code (args.data (), pr, string (), loc);
+ return run_finish_impl (args, pr, false, l, v, on, loc);
}
inline void
@@ -63,9 +98,10 @@ namespace build2
const char* const* args,
process& pr,
uint16_t v,
+ bool on,
const location& loc)
{
- run_finish_impl (dbuf, args, pr, true /* fail */, v, loc);
+ run_finish_impl (dbuf, args, pr, true /* fail */, v, on, loc);
}
inline void
@@ -73,9 +109,10 @@ namespace build2
const cstrings& args,
process& pr,
uint16_t v,
+ bool on,
const location& loc)
{
- run_finish_impl (dbuf, args.data (), pr, true /* fail */, v, loc);
+ run_finish_impl (dbuf, args.data (), pr, true, v, on, loc);
}
inline bool
@@ -83,9 +120,10 @@ namespace build2
const char* const* args,
process& pr,
uint16_t v,
+ bool on,
const location& loc)
{
- return run_finish_impl (dbuf, args, pr, false /* fail */, v, loc);
+ return run_finish_impl (dbuf, args, pr, false, v, on, loc);
}
inline bool
@@ -93,9 +131,10 @@ namespace build2
const cstrings& args,
process& pr,
uint16_t v,
+ bool on,
const location& loc)
{
- return run_finish_impl (dbuf, args.data (), pr, false /* fail */, v, loc);
+ return run_finish_impl (dbuf, args.data (), pr, false, v, on, loc);
}
template <typename T, typename F>
@@ -113,6 +152,7 @@ namespace build2
if (!run (ctx,
verbosity,
pe, args,
+ verbosity - 1,
[&r, &f] (string& l, bool last) // Small function optimmization.
{
r = f (l, last);
@@ -141,6 +181,7 @@ namespace build2
if (!run (dbuf,
verbosity,
pe, args,
+ verbosity - 1,
[&r, &f] (string& l, bool last) // Small function optimmization.
{
r = f (l, last);
@@ -154,6 +195,64 @@ namespace build2
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;
+ }
+
+ template <typename T, typename F>
+ inline T
+ run (diag_buffer& dbuf,
+ const process_env& pe,
+ const char* const* args,
+ uint16_t finish_verbosity,
+ F&& f,
+ bool ignore_exit,
+ sha256* checksum)
+ {
+ T r;
+ if (!run (dbuf,
+ verb_never,
+ pe, args,
+ finish_verbosity,
+ [&r, &f] (string& l, bool last)
+ {
+ r = f (l, last);
+ return r.empty ();
+ },
+ true /* trim */,
+ ignore_exit,
+ checksum))
+ r = T ();
+
+ return r;
+ }
+
inline void
hash_path (sha256& cs, const path& p, const dir_path& prefix)
{