aboutsummaryrefslogtreecommitdiff
path: root/bbot/utility.txx
diff options
context:
space:
mode:
Diffstat (limited to 'bbot/utility.txx')
-rw-r--r--bbot/utility.txx98
1 files changed, 66 insertions, 32 deletions
diff --git a/bbot/utility.txx b/bbot/utility.txx
index d641612..383db74 100644
--- a/bbot/utility.txx
+++ b/bbot/utility.txx
@@ -12,35 +12,45 @@
namespace bbot
{
template <typename I, typename O, typename E, typename P, typename... A>
- butl::process_exit::code_type
- run_exit (tracer& t, I&& in, O&& out, E&& err, const P& p, A&&... args)
+ process
+ run_io_start (tracer& t,
+ I&& in,
+ O&& out,
+ E&& err,
+ const dir_path& cwd,
+ P&& p,
+ A&&... args)
{
- using namespace butl;
+ try
+ {
+ return butl::process_start (
+ [&t] (const char* c[], size_t n) {run_trace (t, c, n);},
+ forward<I> (in),
+ forward<O> (out),
+ forward<E> (err),
+ cwd,
+ p,
+ forward<A> (args)...);
+ }
+ catch (const process_error& e)
+ {
+ fail << "unable to execute " << p << ": " << e << endf;
+ }
+ }
+ template <typename P>
+ process_exit::code_type
+ run_io_finish_exit (tracer&, process& pr, P&& p)
+ {
try
{
- auto cmdc = [&t] (const char* cmd[], size_t n)
- {
- if (verb >= 2)
- {
- diag_record dr (t);
- process::print (dr.os, cmd, n);
- }
- };
-
- process_exit r (process_run (cmdc,
- forward<I> (in),
- forward<O> (out),
- forward<E> (err),
- dir_path (),
- p,
- forward<A> (args)...));
-
- if (!r.normal ())
+ pr.wait ();
+
+ if (!pr.exit->normal ())
fail << "process " << p << " terminated abnormally: "
- << r.description ();
+ << pr.exit->description ();
- return r.code ();
+ return pr.exit->code ();
}
catch (const process_error& e)
{
@@ -48,19 +58,43 @@ namespace bbot
}
}
- template <typename I, typename O, typename E, typename P, typename... A>
- void
- run (tracer& t, I&& in, O&& out, E&& err, const P& p, A&&... args)
+ template <typename P>
+ inline void
+ run_io_finish (tracer& t, process& pr, P&& p)
{
- if (run_exit (t,
- forward<I> (in),
- forward<O> (out),
- forward<E> (err),
- p,
- forward<A> (args)...) != 0)
+ if (run_io_finish_exit (t, pr, p) != 0)
fail << "process " << p << " terminated with non-zero exit code";
}
+ template <typename I, typename O, typename E, typename P, typename... A>
+ inline process_exit::code_type
+ run_io_exit (tracer& t, I&& in, O&& out, E&& err, const P& p, A&&... args)
+ {
+ process pr (run_io_start (t,
+ forward<I> (in),
+ forward<O> (out),
+ forward<E> (err),
+ dir_path (),
+ p,
+ forward<A> (args)...));
+
+ return run_io_finish_exit (t, pr, p);
+ }
+
+ template <typename I, typename O, typename E, typename P, typename... A>
+ inline void
+ run_io (tracer& t, I&& in, O&& out, E&& err, const P& p, A&&... args)
+ {
+ process pr (run_io_start (t,
+ forward<I> (in),
+ forward<O> (out),
+ forward<E> (err),
+ dir_path (),
+ p,
+ forward<A> (args)...));
+ run_io_finish (t, pr, p);
+ }
+
template <typename T>
T
parse_manifest (const path& f, const char* what, bool ignore_unknown)