aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2021-07-02 12:03:24 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2021-07-02 12:03:24 +0300
commita14677a9b3bdfaa59fd4a010bff3530472768954 (patch)
treec0814e96d3023ea22ce6117067f90e51823e6164
parentca439ff4ca3f36a803419575e2db3a3ab4775c4b (diff)
-rw-r--r--bpkg/cfg-create.cxx2
-rw-r--r--bpkg/database.cxx77
-rw-r--r--bpkg/database.hxx36
-rw-r--r--bpkg/package.cxx2
-rw-r--r--bpkg/pkg-build.cxx13
5 files changed, 102 insertions, 28 deletions
diff --git a/bpkg/cfg-create.cxx b/bpkg/cfg-create.cxx
index 98d6aea..42c7cea 100644
--- a/bpkg/cfg-create.cxx
+++ b/bpkg/cfg-create.cxx
@@ -54,7 +54,7 @@ namespace bpkg
hc = normalize (*host_config, "host configuration");
database db (hc, trace, false /* pre_attach */);
- if (db.type != "host")
+ if (db.type != host_config_type)
fail << "host configuration " << hc << " is of '" << db.type
<< "' type";
}
diff --git a/bpkg/database.cxx b/bpkg/database.cxx
index 1b7612f..40110e6 100644
--- a/bpkg/database.cxx
+++ b/bpkg/database.cxx
@@ -20,6 +20,10 @@ namespace bpkg
{
namespace sqlite = odb::sqlite;
+ const string target_config_type ("target");
+ const string host_config_type ("host");
+ const string build2_config_type ("build2");
+
// Register the data migration functions.
//
// NOTE: remember to qualify table names with \"main\". if using native
@@ -47,7 +51,7 @@ namespace bpkg
// Add the unnamed self-association of the target type.
//
shared_ptr<configuration> sc (
- make_shared<configuration> (optional<string> (), "target"));
+ make_shared<configuration> (optional<string> (), target_config_type));
db.persist (sc);
db.execute ("UPDATE selected_package_prerequisites SET configuration = '" +
@@ -621,25 +625,54 @@ namespace bpkg
}
associated_databases database::
- dependency_configs (optional<bool> buildtime)
+ dependency_configs (optional<bool> buildtime, const std::string& type)
{
+ if (buildtime)
+ assert (!*buildtime ||
+ type == host_config_type ||
+ type == build2_config_type);
+ else
+ assert (type.empty ());
+
associated_databases r;
+ // Allow dependency configurations of the dependent configuration own type
+ // if all or runtime dependency configurations are requested.
+ //
bool allow_own_type (!buildtime || !*buildtime);
- bool allow_host_type (!buildtime || *buildtime);
+
+ // Allow dependency configurations of the host type if all or regular
+ // builtime dependency configurations are requested.
+ //
+ bool allow_host_type (!buildtime ||
+ (*buildtime && type == host_config_type));
+
+ // Allow dependency configurations of the build2 type if all or build2
+ // system module dependency configurations are requested.
+ //
+ bool allow_build2_type (!buildtime ||
+ (*buildtime && type == build2_config_type));
// Add the associated database to the resulting list if it is of the
- // associating database type and allow_own_type is true or if it is of the
- // host type and allow_host_type is true. Call itself recursively for the
- // explicitly associated configurations.
+ // associating database type and allow_own_type is true, or it is of the
+ // host type and allow_host_type is true, or it is of the build2 type and
+ // allow_build2_type is true. Call itself recursively for the explicitly
+ // associated configurations.
//
// Note that the associated database of the associating database type is
// not added if allow_own_type is false but its own associated databases
- // of the host type are added, if allow_host_type is true.
+ // of the host/build2 type are added, if allow_host_type/allow_build2_type
+ // is true.
//
associated_databases descended; // Note: we may not add but still descend.
- auto add = [&r, allow_own_type, allow_host_type, &descended]
- (database& db, const std::string& t, const auto& add)
+ auto add = [&r,
+ allow_own_type,
+ allow_host_type,
+ allow_build2_type,
+ &descended]
+ (database& db,
+ const std::string& t,
+ const auto& add)
{
if (std::find (descended.begin (), descended.end (), db) !=
descended.end ())
@@ -647,13 +680,16 @@ namespace bpkg
descended.push_back (db);
- bool own (db.type == t);
- bool host (db.type == "host");
+ bool own (db.type == t);
+ bool host (db.type == host_config_type);
+ bool build2 (db.type == build2_config_type);
- if (!own && !(allow_host_type && host))
+ if (!own && !(allow_host_type && host) && !(allow_build2_type && build2))
return;
- if ((allow_own_type && own) || (allow_host_type && host))
+ if ((allow_own_type && own) ||
+ (allow_host_type && host) ||
+ (allow_build2_type && build2))
r.push_back (db);
const associated_configs& acs (db.explicit_associations ());
@@ -668,6 +704,21 @@ namespace bpkg
return r;
}
+ associated_databases database::
+ dependency_configs (const package_name& n, bool buildtime)
+ {
+ return dependency_configs (buildtime,
+ buildtime
+ ? buildtime_dependency_config_type (n)
+ : empty_string);
+ }
+
+ associated_databases database::
+ dependency_configs ()
+ {
+ return dependency_configs (nullopt, empty_string);
+ }
+
database& database::
find_attached (uint64_t id)
{
diff --git a/bpkg/database.hxx b/bpkg/database.hxx
index 8367ed7..d42b254 100644
--- a/bpkg/database.hxx
+++ b/bpkg/database.hxx
@@ -161,6 +161,8 @@ namespace bpkg
associated_databases&
implicit_associations (bool attach = true, bool sys_rep = false);
+ // @@ AC Update
+ //
// Return configurations of potential dependencies of packages selected in
// the current configuration.
//
@@ -197,7 +199,10 @@ namespace bpkg
// included.
//
associated_databases
- dependency_configs (optional<bool> buildtime = nullopt);
+ dependency_configs (const package_name& n, bool buildtime);
+
+ associated_databases
+ dependency_configs ();
// Return configurations of potential dependents of packages selected in
// the current configuration.
@@ -346,6 +351,11 @@ namespace bpkg
void
add_env (bool reset = false) const;
+ // @@ AC Describe.
+ //
+ associated_databases
+ dependency_configs (optional<bool> buildtime, const std::string& type);
+
impl* impl_;
associated_configs explicit_associations_;
@@ -392,16 +402,30 @@ namespace bpkg
return os;
}
- inline string
+ // The predefined configuration types.
+ //
+ extern const string target_config_type;
+ extern const string host_config_type;
+ extern const string build2_config_type;
+
+ // Return the configuration type suitable for building a build-time
+ // dependency.
+ //
+ inline const string&
buildtime_dependency_config_type (const package_name& nm)
{
- return nm.string ().compare (0, 10, "libbuild2-") == 0 ? "build2" : "host";
+ return nm.string ().compare (0, 10, "libbuild2-") == 0
+ ? build2_config_type
+ : host_config_type;
}
- inline string
- dependency_config_type (database& db, const package_name& nm, bool buildtime)
+ // Return the configuration type suitable for building a dependency of the
+ // dependent in the specified configuration.
+ //
+ inline const string&
+ dependency_config_type (database& db, const package_name& n, bool buildtime)
{
- return buildtime ? buildtime_dependency_config_type (nm) : db.type;
+ return buildtime ? buildtime_dependency_config_type (n) : db.type;
}
// Transaction wrapper that allow the creation of dummy transactions (start
diff --git a/bpkg/package.cxx b/bpkg/package.cxx
index abfcd55..5c2235d 100644
--- a/bpkg/package.cxx
+++ b/bpkg/package.cxx
@@ -554,7 +554,7 @@ namespace bpkg
{
pair<shared_ptr<selected_package>, database*> r;
- for (database& adb: db.dependency_configs (buildtime))
+ for (database& adb: db.dependency_configs (pn, buildtime))
{
shared_ptr<selected_package> p (adb.find<selected_package> (pn));
diff --git a/bpkg/pkg-build.cxx b/bpkg/pkg-build.cxx
index 37bd99f..ff26b41 100644
--- a/bpkg/pkg-build.cxx
+++ b/bpkg/pkg-build.cxx
@@ -1089,8 +1089,8 @@ namespace bpkg
}
// If this is a build-time dependency and we build it for the first
- // time, then we need to find a suitable configuration (of the
- // respective type) to build it in.
+ // time, then we need to find a suitable configuration (of the host or
+ // build2 type) to build it in.
//
// If the current configuration (ddb) is of the required type, then we
// use that. Otherwise, we go through its immediate explicit
@@ -1106,7 +1106,7 @@ namespace bpkg
if (da.buildtime && dsp == nullptr)
{
database* db (nullptr);
- string type (buildtime_dependency_config_type (dn));
+ const string& type (buildtime_dependency_config_type (dn));
// Note that the first returned association is for ddb itself.
//
@@ -2200,7 +2200,7 @@ namespace bpkg
{
iterator r (end ());
- associated_databases adbs (db.dependency_configs (buildtime));
+ associated_databases adbs (db.dependency_configs (pn, buildtime));
for (database& adb: adbs)
{
@@ -4571,9 +4571,8 @@ namespace bpkg
return i.name == nm;
}));
- const char* tp (buildtime ? "host" : db.type.c_str ());
-
- if (i != conf_pkgs.end () && i->db.type == tp)
+ if (i != conf_pkgs.end () &&
+ i->db.type == dependency_config_type (db, nm, buildtime))
return &i->db;
}