From e3ef708dd18dbd0d24e11e37d552fddcaa362d72 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 1 Oct 2015 11:44:38 +0200 Subject: Add dependencies list to available packages --- bpkg/package | 83 +++++++++++++++++++++++++++++++++++++++++--------------- bpkg/package.cxx | 4 +-- bpkg/package.xml | 62 ++++++++++++++++++++++++++++++++++++++++++ bpkg/utility | 1 + 4 files changed, 126 insertions(+), 24 deletions(-) diff --git a/bpkg/package b/bpkg/package index 5967448..6bd68cc 100644 --- a/bpkg/package +++ b/bpkg/package @@ -5,14 +5,14 @@ #ifndef BPKG_PACKAGE #define BPKG_PACKAGE +#include #include #include #include // uint16 #include #include - -#include +#include #include #include @@ -21,8 +21,6 @@ namespace bpkg { - // compare_lazy_ptr - // // Compare two lazy pointers via the pointed-to object ids. // struct compare_lazy_ptr @@ -35,7 +33,6 @@ namespace bpkg } }; - // path // using optional_string = optional; @@ -56,7 +53,25 @@ namespace bpkg to((?) ? (?)->string () : bpkg::optional_string ()) \ from((?) ? bpkg::dir_path (*(?)) : bpkg::optional_dir_path ()) + // An image type that is used to map version to the database since + // there is no way to modify individual components directly. We have + // to define it before including since some value + // types that are defined there use version as their data members. + // + #pragma db value + struct _version + { + uint16_t epoch; + string canonical_upstream; + uint16_t revision; + string upstream; + }; +} +#include + +namespace bpkg +{ // version // // Sometimes we need to split the version into two parts: the part @@ -98,18 +113,6 @@ namespace bpkg } }; - // Use an image type to map version to the database since there - // is no way to modify individual components directly. - // - #pragma db value - struct _version - { - uint16_t epoch; - string canonical_upstream; - uint16_t revision; - string upstream; - }; - #pragma db map type(version) as(_version) \ to(bpkg::_version{(?).epoch (), \ (?).canonical_upstream (), \ @@ -196,6 +199,18 @@ namespace bpkg path location; // Relative to the repository. }; + // dependencies + // + #pragma db map type(comparison) as(string) \ + to(to_string (?)) \ + from(bpkg::to_comparison (?)) + + #pragma db value(dependency_condition) definition + #pragma db value(dependency) definition + #pragma db member(dependency::condition) column("") + #pragma db value(dependency_alternatives) definition + + using dependencies = std::vector; // available_package // @@ -224,19 +239,43 @@ namespace bpkg // std::vector locations; //@@ Map? + // Package manifest data. + // + using dependencies_type = bpkg::dependencies; + + dependencies_type dependencies; + public: available_package (package_manifest&& m) - : id (move (m.name), m.version), version (move (m.version)) {} + : id (move (m.name), m.version), + version (move (m.version)), + dependencies (move (m.dependencies)) {} // Database mapping. // #pragma db member(id) id column("") - #pragma db member(version) set(this.version.init (this.id.version, (?))) - #pragma db member(locations) id_column("") value_column("") \ unordered value_not_null + // dependencies + // + using _dependency_key = odb::nested_key; + using _dependency_alternatives_type = + std::map<_dependency_key, dependency>; + + #pragma db value(_dependency_key) + #pragma db member(_dependency_key::outer) column("dependency_index") + #pragma db member(_dependency_key::inner) column("index") + + #pragma db member(dependencies) id_column("") value_column("") + #pragma db member(dependency_alternatives) \ + virtual(_dependency_alternatives_type) \ + after(dependencies) \ + get(odb::nested_get (this.dependencies)) \ + set(odb::nested_set (this.dependencies, std::move (?))) \ + id_column("") key_column("") value_column("dep_") + private: friend class odb::access; available_package () = default; @@ -276,14 +315,14 @@ namespace bpkg to_string (state); state - from_string (const string&); // May throw invalid_argument. + to_state (const string&); // May throw invalid_argument. inline std::ostream& operator<< (std::ostream& os, state s) {return os << to_string (s);} #pragma db map type(state) as(string) \ to(to_string (?)) \ - from(bpkg::from_string (?)) + from(bpkg::to_state (?)) // package diff --git a/bpkg/package.cxx b/bpkg/package.cxx index c6f5dcf..02cb49d 100644 --- a/bpkg/package.cxx +++ b/bpkg/package.cxx @@ -117,12 +117,12 @@ namespace bpkg } state - from_string (const string& s) + to_state (const string& s) { if (s == "broken") return state::broken; else if (s == "fetched") return state::fetched; else if (s == "unpacked") return state::unpacked; else if (s == "configured") return state::configured; - else throw invalid_argument (s); + else throw invalid_argument ("invalid package state '" + s + "'"); } } diff --git a/bpkg/package.xml b/bpkg/package.xml index 8bb959d..4a689e3 100644 --- a/bpkg/package.xml +++ b/bpkg/package.xml @@ -90,6 +90,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/bpkg/utility b/bpkg/utility index b07d502..5f41843 100644 --- a/bpkg/utility +++ b/bpkg/utility @@ -18,6 +18,7 @@ namespace bpkg { using std::move; using std::make_shared; + using std::to_string; // To complement bpkg::to_string(). // Filesystem. // -- cgit v1.1