From 0ad77856d2a48ded26fed592f414555d8866bde5 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 15 Jan 2019 23:04:29 +0300 Subject: Make use of butl::b_info() instead of parsing `b info` stdout manually --- bpkg/manifest-utility.cxx | 78 +++++++++++++++-------------------------------- 1 file changed, 25 insertions(+), 53 deletions(-) diff --git a/bpkg/manifest-utility.cxx b/bpkg/manifest-utility.cxx index 79c131b..b7bdd61 100644 --- a/bpkg/manifest-utility.cxx +++ b/bpkg/manifest-utility.cxx @@ -4,6 +4,7 @@ #include +#include #include #include @@ -221,68 +222,39 @@ namespace bpkg optional package_version (const common_options& o, const dir_path& d) { - fdpipe pipe (open_pipe ()); - - process pr (start_b (o, - pipe, 2 /* stderr */, - verb_b::quiet, - "info:", - d.representation ())); - - // Shouldn't throw, unless something is severely damaged. - // - pipe.out.close (); + path b (name_b (o)); try { - optional r; - - ifdstream is (move (pipe.in), - fdstream_mode::skip, - ifdstream::badbit); - - for (string l; !eof (getline (is, l)); ) - { - if (l.compare (0, 9, "version: ") == 0) - try - { - string v (l, 9); - - // An empty version indicates that the version module is not - // enabled for the project. - // - if (!v.empty ()) - r = version (v); - - break; - } - catch (const invalid_argument&) - { - fail << "no package version in '" << l << "'" << - info << "produced by '" << name_b (o) << "'; use --build to " - << "override"; - } - } + b_project_info pi ( + b_info (d, + verb, + [] (const char* const args[], size_t n) + { + if (verb >= 2) + print_process (args, n); + }, + b, + exec_dir, + o.build_option ())); - is.close (); + optional r; - if (pr.wait ()) - return r; + // An empty version indicates that the version module is not enabled for + // the project. + // + if (!pi.version.empty ()) + r = version (pi.version.string ()); - // Fall through. + return r; } - catch (const io_error&) + catch (const b_error& e) { - if (pr.wait ()) - fail << "unable to read '" << name_b (o) << "' output"; + if (e.normal ()) + throw failed (); // Assume the build2 process issued diagnostics. - // Fall through. + fail << "unable to parse project " << d << " info: " << e << + info << "produced by '" << b << "'; use --build to override" << endf; } - - // We should only get here if the child exited with an error status. - // - assert (!pr.wait ()); - - fail << "unable to obtain version using '" << name_b (o) << "'" << endf; } } -- cgit v1.1