From 53c2aa8e382dd50d09b385285bc3fa0b645ace0a Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 19 Aug 2016 17:37:29 +0300 Subject: Support system packages --- bpkg/pkg-configure.cxx | 86 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 9 deletions(-) (limited to 'bpkg/pkg-configure.cxx') diff --git a/bpkg/pkg-configure.cxx b/bpkg/pkg-configure.cxx index 16eefd2..81b1fe3 100644 --- a/bpkg/pkg-configure.cxx +++ b/bpkg/pkg-configure.cxx @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -146,6 +147,36 @@ namespace bpkg t.commit (); } + shared_ptr + pkg_configure_system (const string& n, const version& v, transaction& t) + { + tracer trace ("pkg_configure_system"); + + database& db (t.database ()); + tracer_guard tg (db, trace); + + shared_ptr p ( + new selected_package { + n, + v, + package_state::configured, + package_substate::system, + false, // Don't hold package. + false, // Don't hold version. + repository_location (), // Root repository. + nullopt, // No source archive. + false, // No auto-purge (does not get there). + nullopt, // No source directory. + false, + nullopt, // No output directory. + {}}); // No prerequisites. + + db.persist (p); + t.commit (); + + return p; + } + int pkg_configure (const pkg_configure_options& o, cli::scanner& args) { @@ -175,25 +206,62 @@ namespace bpkg fail << "package name argument expected" << info << "run 'bpkg help pkg-configure' for more information"; + const char* package (n.c_str ()); + package_scheme ps (parse_package_scheme (package)); + + if (ps == package_scheme::sys && !vars.empty ()) + fail << "configuration variables specified for a system package"; + database db (open (c, trace)); transaction t (db.begin ()); session s; - shared_ptr p (db.find (n)); + shared_ptr p; + + // pkg_configure() commits the transaction. + // + if (ps == package_scheme::sys) + { + // Configure system package. + // + version v (parse_package_version (package)); + n = parse_package_name (package); + + p = db.find (n); + + if (p != nullptr) + fail << "package " << n << " already exists in configuration " << c; - if (p == nullptr) - fail << "package " << n << " does not exist in configuration " << c; + shared_ptr rep (db.load ("")); // Root. - if (p->state != package_state::unpacked) - fail << "package " << n << " is " << p->state << - info << "expected it to be unpacked"; + using query = query; + query q (query::id.name == n); - l4 ([&]{trace << p->name << " " << p->version;}); + if (filter_one (rep, db.query (q)).first == nullptr) + fail << "unknown package " << n; - pkg_configure (c, o, t, p, vars); // Commits the transaction. + p = pkg_configure_system (n, v.empty () ? wildcard_version : v, t); + } + else + { + // Configure unpacked package. + // + p = db.find (n); + + if (p == nullptr) + fail << "package " << n << " does not exist in configuration " << c; + + if (p->state != package_state::unpacked) + fail << "package " << n << " is " << p->state << + info << "expected it to be unpacked"; + + l4 ([&]{trace << *p;}); + + pkg_configure (c, o, t, p, vars); + } if (verb) - text << "configured " << p->name << " " << p->version; + text << "configured " << *p; return 0; } -- cgit v1.1