aboutsummaryrefslogtreecommitdiff
path: root/bdep/utility.txx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-03-14 14:29:43 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-03-14 14:29:43 +0200
commitcc7216e60cd6893974e687599682c5e6233e9b69 (patch)
tree2304123805fda221d189034b2b85b3aac56055f4 /bdep/utility.txx
parent6be9c7746f92aa721782a4d0eaff5f901fc528cd (diff)
Initial implementation of new command
Diffstat (limited to 'bdep/utility.txx')
-rw-r--r--bdep/utility.txx44
1 files changed, 44 insertions, 0 deletions
diff --git a/bdep/utility.txx b/bdep/utility.txx
index b796f69..9e94196 100644
--- a/bdep/utility.txx
+++ b/bdep/utility.txx
@@ -12,6 +12,50 @@
namespace bdep
{
+ template <typename I, typename O, typename E, typename P, typename... A>
+ process
+ start (I&& in, O&& out, E&& err, const P& prog, A&&... args)
+ {
+ try
+ {
+ return process_start_callback (
+ [] (const char* const args[], size_t n)
+ {
+ if (verb >= 2)
+ print_process (args, n);
+ },
+ forward<I> (in),
+ forward<O> (out),
+ forward<E> (err),
+ prog,
+ forward<A> (args)...);
+ }
+ catch (const process_error& e)
+ {
+ fail << "unable to execute " << prog << ": " << e << endf;
+ }
+ }
+
+ template <typename P, typename... A>
+ void
+ run (const P& prog, A&&... args)
+ {
+ process pr (start (0 /* stdin */,
+ 1 /* stdout */,
+ 2 /* stderr */,
+ prog,
+ forward<A> (args)...));
+ if (!pr.wait ())
+ {
+ const process_exit& e (*pr.exit);
+
+ if (e.normal ())
+ throw failed (); // Assume the child issued diagnostics.
+
+ fail << "process " << prog << " " << e;
+ }
+ }
+
// *_bpkg()
//
template <typename O, typename E, typename... A>