aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2019-01-15 23:02:46 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2019-01-16 18:30:06 +0300
commit93b2fdca9283b73ffca25170a01e262297e8e254 (patch)
tree2503b9a3512b7706bf77abf3a370fa310806e2ee
parent1cec9d6cb41d157d2e907e5ef5717dd508222c0c (diff)
Make use of butl::b_info() instead of parsing `b info` stdout manually
-rw-r--r--bdep/project.cxx86
1 files changed, 34 insertions, 52 deletions
diff --git a/bdep/project.cxx b/bdep/project.cxx
index f6ca5bf..181c091 100644
--- a/bdep/project.cxx
+++ b/bdep/project.cxx
@@ -5,6 +5,8 @@
#include <bdep/project.hxx>
#include <bdep/project-odb.hxx>
+#include <libbutl/b.mxx>
+
#include <libbpkg/manifest.hxx>
#include <bdep/database.hxx>
@@ -387,65 +389,45 @@ namespace bdep
const dir_path& cfg,
const package_name& p)
{
+ using namespace butl;
+
// We could have used bpkg-pkg-status but then we would have to deal with
// iterations. So we use the build system's info meta-operation directly.
//
- string v;
- {
- process pr;
- bool io (false);
- try
- {
- fdpipe pipe (fdopen_pipe ()); // Text mode seems appropriate.
-
- // Note: the package directory inside the configuration is a bit of an
- // assumption.
- //
- pr = start_b (
- o,
- pipe /* stdout */,
- 2 /* stderr */,
- "info:", (dir_path (cfg) /= p.string ()).representation ());
-
- pipe.out.close ();
- ifdstream is (move (pipe.in), fdstream_mode::skip, ifdstream::badbit);
-
- for (string l; !eof (getline (is, l)); )
- {
- // Verify the name for good measure (comes before version).
- //
- if (l.compare (0, 9, "project: ") == 0)
- {
- if (l.compare (9, string::npos, p.string ()) != 0)
- fail << "name mismatch for package " << p;
- }
- else if (l.compare (0, 9, "version: ") == 0)
- {
- v = string (l, 9);
- break;
- }
- }
-
- is.close (); // Detect errors.
- }
- catch (const io_error&)
- {
- // Presumably the child process failed and issued diagnostics so let
- // finish_b() try to deal with that first.
- //
- io = true;
- }
-
- finish_b (o, pr, io);
- }
-
try
{
- return standard_version (v);
+ // Note: the package directory inside the configuration is a bit of an
+ // assumption.
+ //
+ b_project_info pi (
+ b_info ((dir_path (cfg) /= p.string ()),
+ verb,
+ [] (const char* const args[], size_t n)
+ {
+ if (verb >= 3)
+ print_process (args, n);
+ },
+ path (name_b (o)),
+ exec_dir,
+ o.build_option ()));
+
+ if (pi.version.empty ())
+ fail << "empty version for package " << p;
+
+ // Verify the name for good measure.
+ //
+ if (pi.project != p)
+ fail << "name mismatch for package " << p;
+
+ return move (pi.version);
}
- catch (const invalid_argument& e)
+ catch (const b_error& e)
{
- fail << "invalid package " << p << " version " << v << ": " << e << endf;
+ if (e.normal ())
+ throw failed (); // Assume the build2 process issued diagnostics.
+
+ fail << "unable to obtain package " << p << " project info: " << e
+ << endf;
}
}
}