aboutsummaryrefslogtreecommitdiff
path: root/bpkg/pkg-configure.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-08-19 17:37:29 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2016-08-29 18:20:03 +0300
commit53c2aa8e382dd50d09b385285bc3fa0b645ace0a (patch)
tree6d23d091bc57c0aa8d8a529e63ec2f2f22322a3a /bpkg/pkg-configure.cxx
parenta4b29effed15b0a3e9309a4633a3ada37f3081e6 (diff)
Support system packages
Diffstat (limited to 'bpkg/pkg-configure.cxx')
-rw-r--r--bpkg/pkg-configure.cxx86
1 files changed, 77 insertions, 9 deletions
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 <bpkg/database>
#include <bpkg/diagnostics>
#include <bpkg/satisfaction>
+#include <bpkg/manifest-utility>
#include <bpkg/pkg-verify>
#include <bpkg/pkg-disfigure>
@@ -146,6 +147,36 @@ namespace bpkg
t.commit ();
}
+ shared_ptr<selected_package>
+ 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<selected_package> 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<selected_package> p (db.find<selected_package> (n));
+ shared_ptr<selected_package> 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<selected_package> (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<repository> rep (db.load<repository> ("")); // Root.
- if (p->state != package_state::unpacked)
- fail << "package " << n << " is " << p->state <<
- info << "expected it to be unpacked";
+ using query = query<available_package>;
+ query q (query::id.name == n);
- l4 ([&]{trace << p->name << " " << p->version;});
+ if (filter_one (rep, db.query<available_package> (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<selected_package> (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;
}