diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2019-01-15 23:04:29 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2019-01-16 18:31:30 +0300 |
commit | 0ad77856d2a48ded26fed592f414555d8866bde5 (patch) | |
tree | a7fa89e59d07aa337cc51f44ae71c988b7d7d17c | |
parent | cbd3cd125b574deaf1ad3c7001c5b6c9c40198ed (diff) |
Make use of butl::b_info() instead of parsing `b info` stdout manually
-rw-r--r-- | bpkg/manifest-utility.cxx | 78 |
1 files 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 <bpkg/manifest-utility.hxx> +#include <libbutl/b.mxx> #include <libbutl/url.mxx> #include <libbutl/sha256.mxx> @@ -221,68 +222,39 @@ namespace bpkg optional<version> 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<version> 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<version> 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; } } |