aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bpkg/package83
-rw-r--r--bpkg/package.cxx4
-rw-r--r--bpkg/package.xml62
-rw-r--r--bpkg/utility1
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 <map>
#include <set>
#include <vector>
#include <cstdint> // uint16
#include <ostream>
#include <odb/core.hxx>
-
-#include <bpkg/manifest>
+#include <odb/nested-container.hxx>
#include <bpkg/types>
#include <bpkg/utility>
@@ -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<string>;
@@ -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 <bpkg/manifest> 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 <bpkg/manifest>
+
+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<dependency_alternatives>;
// available_package
//
@@ -224,19 +239,43 @@ namespace bpkg
//
std::vector<package_location> 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<dependency_alternatives>;
+ 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 @@
</references>
</foreign-key>
</table>
+ <table name="available_package_dependencies" kind="container">
+ <column name="name" type="TEXT" null="true"/>
+ <column name="version_epoch" type="INTEGER" null="true"/>
+ <column name="version_canonical_upstream" type="TEXT" null="true"/>
+ <column name="version_revision" type="INTEGER" null="true"/>
+ <column name="index" type="INTEGER" null="true"/>
+ <column name="conditional" type="INTEGER" null="true"/>
+ <column name="comment" type="TEXT" null="true"/>
+ <foreign-key name="object_id_fk" on-delete="CASCADE">
+ <column name="name"/>
+ <column name="version_epoch"/>
+ <column name="version_canonical_upstream"/>
+ <column name="version_revision"/>
+ <references table="available_package">
+ <column name="name"/>
+ <column name="version_epoch"/>
+ <column name="version_canonical_upstream"/>
+ <column name="version_revision"/>
+ </references>
+ </foreign-key>
+ <index name="available_package_dependencies_object_id_i">
+ <column name="name"/>
+ <column name="version_epoch"/>
+ <column name="version_canonical_upstream"/>
+ <column name="version_revision"/>
+ </index>
+ <index name="available_package_dependencies_index_i">
+ <column name="index"/>
+ </index>
+ </table>
+ <table name="available_package_dependency_alternatives" kind="container">
+ <column name="name" type="TEXT" null="true"/>
+ <column name="version_epoch" type="INTEGER" null="true"/>
+ <column name="version_canonical_upstream" type="TEXT" null="true"/>
+ <column name="version_revision" type="INTEGER" null="true"/>
+ <column name="dependency_index" type="INTEGER" null="true"/>
+ <column name="index" type="INTEGER" null="true"/>
+ <column name="dep_name" type="TEXT" null="true"/>
+ <column name="dep_operation" type="TEXT" null="true"/>
+ <column name="dep_version_epoch" type="INTEGER" null="true"/>
+ <column name="dep_version_canonical_upstream" type="TEXT" null="true"/>
+ <column name="dep_version_revision" type="INTEGER" null="true"/>
+ <column name="dep_version_upstream" type="TEXT" null="true"/>
+ <foreign-key name="object_id_fk" on-delete="CASCADE">
+ <column name="name"/>
+ <column name="version_epoch"/>
+ <column name="version_canonical_upstream"/>
+ <column name="version_revision"/>
+ <references table="available_package">
+ <column name="name"/>
+ <column name="version_epoch"/>
+ <column name="version_canonical_upstream"/>
+ <column name="version_revision"/>
+ </references>
+ </foreign-key>
+ <index name="available_package_dependency_alternatives_object_id_i">
+ <column name="name"/>
+ <column name="version_epoch"/>
+ <column name="version_canonical_upstream"/>
+ <column name="version_revision"/>
+ </index>
+ </table>
<table name="package" kind="object">
<column name="name" type="TEXT" null="true"/>
<column name="version_epoch" type="INTEGER" null="true"/>
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.
//