From a3925d12af6a6ae75897d5aab25a9de0edb642fb Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 5 Sep 2016 09:24:39 +0200 Subject: Add support for build-time dependencies --- bpkg/satisfaction.cxx | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) (limited to 'bpkg/satisfaction.cxx') 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 +#include +#include + +#include #include #include +#include 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; + } } -- cgit v1.1