From a14677a9b3bdfaa59fd4a010bff3530472768954 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 2 Jul 2021 12:03:24 +0300 Subject: Backup --- bpkg/database.cxx | 77 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 13 deletions(-) (limited to 'bpkg/database.cxx') 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 sc ( - make_shared (optional (), "target")); + make_shared (optional (), 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 buildtime) + dependency_configs (optional 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) { -- cgit v1.1