aboutsummaryrefslogtreecommitdiff
path: root/bpkg/satisfaction.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-09-05 09:24:39 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-09-05 09:24:39 +0200
commita3925d12af6a6ae75897d5aab25a9de0edb642fb (patch)
treec7a95927bbc339f873f58ba3bab63916eced71fb /bpkg/satisfaction.cxx
parent3469e1d984c6ae000b59c471e6ef84c4b43497f2 (diff)
Add support for build-time dependencies
Diffstat (limited to 'bpkg/satisfaction.cxx')
-rw-r--r--bpkg/satisfaction.cxx91
1 files changed, 91 insertions, 0 deletions
diff --git a/bpkg/satisfaction.cxx b/bpkg/satisfaction.cxx
index bddf7e7..2e2b269 100644
--- a/bpkg/satisfaction.cxx
+++ b/bpkg/satisfaction.cxx
@@ -4,8 +4,13 @@
#include <bpkg/satisfaction>
+#include <butl/process>
+#include <butl/fdstream>
+
+#include <bpkg/utility>
#include <bpkg/package-odb>
#include <bpkg/diagnostics>
+#include <bpkg/bpkg-version>
using namespace std;
using namespace butl;
@@ -93,4 +98,90 @@ namespace bpkg
return s;
}
+
+ static version build2_version;
+
+ void
+ satisfy_build2 (const common_options& co,
+ const string& pkg,
+ const dependency& d)
+ {
+ assert (d.name == "build2");
+
+ // Extract, parse, and cache build2 version string.
+ //
+ if (build2_version.empty ())
+ {
+ const char* args[] = {name_b (co), "--version", nullptr};
+
+ try
+ {
+ process_path pp (process::path_search (args[0], exec_dir));
+
+ if (verb >= 3)
+ print_process (args);
+
+ process pr (pp, args, 0, -1); // Redirect STDOUT to pipe.
+
+ string l;
+ try
+ {
+ ifdstream is (pr.in_ofd, fdstream_mode::skip);
+ getline (is, l);
+ is.close ();
+
+ if (pr.wait () && l.compare (0, 7, "build2 ") == 0)
+ {
+ try
+ {
+ build2_version = version (string (l, 7));
+ }
+ catch (const invalid_argument&) {} // Fall through.
+ }
+
+ // Fall through.
+ }
+ catch (const ifdstream::failure&)
+ {
+ pr.wait ();
+ // Fall through.
+ }
+
+ if (build2_version.empty ())
+ fail << "unable to determine build2 version of " << args[0];
+ }
+ catch (const process_error& e)
+ {
+ error << "unable to execute " << args[0] << ": " << e.what ();
+
+ if (e.child ())
+ exit (1);
+
+ throw failed ();
+ }
+ }
+
+ if (!satisfies (build2_version, d.constraint))
+ fail << "unable to satisfy constraint (" << d << ") for package "
+ << pkg <<
+ info << "available build2 version is " << build2_version;
+ }
+
+ static version bpkg_version;
+
+ void
+ satisfy_bpkg (const common_options&, const string& pkg, const dependency& d)
+ {
+ assert (d.name == "bpkg");
+
+ // Parse and cache bpkg version string.
+ //
+ if (bpkg_version.empty ())
+ bpkg_version = version (BPKG_VERSION_STR);
+
+ if (!satisfies (bpkg_version, d.constraint))
+ fail << "unable to satisfy constraint (" << d << ") for package "
+ << pkg <<
+ info << "available bpkg version is " << bpkg_version;
+ }
}