From d369ab42f2d3bc52086dc7d9b79510dce5e80513 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 9 Mar 2018 16:21:14 +0200 Subject: Add support for executing bpkg --- bdep/utility.txx | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) (limited to 'bdep/utility.txx') diff --git a/bdep/utility.txx b/bdep/utility.txx index 38f0e35..9256bc7 100644 --- a/bdep/utility.txx +++ b/bdep/utility.txx @@ -4,15 +4,83 @@ #include // cin -#include - #include #include #include +#include namespace bdep { + // *_bpkg() + // + template + process + start_bpkg (const common_options& co, + O&& out, + E&& err, + A&&... args) + { + const char* bpkg (name_bpkg (co)); + + try + { + process_path pp (process::path_search (bpkg, exec_dir)); + + // Forward our --build* options. + // + cstrings ops; + + if (co.build_specified ()) + { + ops.push_back ("--build"); + ops.push_back (co.build ().string ().c_str ()); + } + + for (const string& o: co.build_option ()) + { + ops.push_back ("--build-option"); + ops.push_back (o.c_str ()); + } + + return process_start_callback ( + [] (const char* const args[], size_t n) + { + if (verb >= 2) + print_process (args, n); + }, + 0 /* stdin */, + forward (out), + forward (err), + pp, + ops, + co.bpkg_option (), + forward (args)...); + } + catch (const process_error& e) + { + fail << "unable to execute " << bpkg << ": " << e << endf; + } + } + + template + process_exit + run_bpkg (const common_options& co, A&&... args) + { + process pr (start_bpkg (co, + 1 /* stdout */, + 2 /* stderr */, + forward (args)...)); + pr.wait (); + + const process_exit& e (*pr.exit); + + if (!e.normal ()) + fail << "process " << name_bpkg (co) << " " << e; + + return e; + } + // *_manifest() // template -- cgit v1.1