diff options
Diffstat (limited to 'bpkg/package.cxx')
-rw-r--r-- | bpkg/package.cxx | 403 |
1 files changed, 94 insertions, 309 deletions
diff --git a/bpkg/package.cxx b/bpkg/package.cxx index a7282c5..05dbc0d 100644 --- a/bpkg/package.cxx +++ b/bpkg/package.cxx @@ -6,6 +6,7 @@ #include <bpkg/database.hxx> #include <bpkg/checksum.hxx> +#include <bpkg/rep-mask.hxx> #include <bpkg/pkg-verify.hxx> #include <bpkg/diagnostics.hxx> #include <bpkg/satisfaction.hxx> @@ -69,6 +70,42 @@ namespace bpkg return r != 0 ? (r < 0) : (db < v.db); } + // package_version_key + // + string package_version_key:: + string (bool ignore_version) const + { + std::string r (name.string ()); + + if (version && !version->empty () && !ignore_version) + { + r += '/'; + r += version->string (); + } + + const std::string& d (db.get ().string); + + if (!d.empty ()) + { + r += ' '; + r += d; + } + + return r; + } + + bool package_version_key:: + operator< (const package_version_key& v) const + { + // NOTE: remember to update cmdline_adjustments::tried_earlier() if + // changing anything here. + // + if (int r = name.compare (v.name)) + return r < 0; + + return version != v.version ? (version < v.version) : (db < v.db); + } + // available_package // const version* available_package:: @@ -116,275 +153,6 @@ namespace bpkg sp != nullptr ? sp->authoritative : false); } - odb::result<available_package> - query_available (database& db, - const package_name& name, - const optional<version_constraint>& c, - bool order, - bool revision) - { - using query = query<available_package>; - - query q (query::id.name == name); - const auto& vm (query::id.version); - - // If there is a constraint, then translate it to the query. Otherwise, - // get the latest version or stub versions if present. - // - if (c) - { - assert (c->complete ()); - - query qs (compare_version_eq (vm, - canonical_version (wildcard_version), - false /* revision */, - false /* iteration */)); - - if (c->min_version && - c->max_version && - *c->min_version == *c->max_version) - { - const version& v (*c->min_version); - - q = q && - (compare_version_eq (vm, - canonical_version (v), - revision || v.revision.has_value (), - revision /* iteration */) || - qs); - } - else - { - query qr (true); - - if (c->min_version) - { - const version& v (*c->min_version); - canonical_version cv (v); - bool rv (revision || v.revision); - - if (c->min_open) - qr = compare_version_gt (vm, cv, rv, revision /* iteration */); - else - qr = compare_version_ge (vm, cv, rv, revision /* iteration */); - } - - if (c->max_version) - { - const version& v (*c->max_version); - canonical_version cv (v); - bool rv (revision || v.revision); - - if (c->max_open) - qr = qr && compare_version_lt (vm, cv, rv, revision); - else - qr = qr && compare_version_le (vm, cv, rv, revision); - } - - q = q && (qr || qs); - } - } - - if (order) - q += order_by_version_desc (vm); - - return db.query<available_package> (q); - } - - // Check if the package is available from the specified repository fragment, - // its prerequisite repositories, or one of their complements, recursively. - // Return the first repository fragment that contains the package or NULL if - // none are. - // - // Note that we can end up with a repository dependency cycle since the - // root repository can be the default complement for dir and git - // repositories (see rep_fetch() implementation for details). Thus we need - // to make sure that the repository fragment is not in the dependency chain - // yet. - // - using repository_fragments = - vector<reference_wrapper<const shared_ptr<repository_fragment>>>; - - static shared_ptr<repository_fragment> - find (const shared_ptr<repository_fragment>& rf, - const shared_ptr<available_package>& ap, - repository_fragments& chain, - bool prereq) - { - // Prerequisites are not searched through recursively. - // - assert (!prereq || chain.empty ()); - - if (find_if (chain.begin (), chain.end (), - [&rf] (const shared_ptr<repository_fragment>& i) -> bool - { - return i == rf; - }) != chain.end ()) - return nullptr; - - chain.emplace_back (rf); - - unique_ptr<repository_fragments, void (*)(repository_fragments*)> deleter ( - &chain, [] (repository_fragments* rf) {rf->pop_back ();}); - - const auto& cs (rf->complements); - const auto& ps (rf->prerequisites); - - for (const package_location& pl: ap->locations) - { - const lazy_shared_ptr<repository_fragment>& lrf (pl.repository_fragment); - - // First check the repository itself. - // - if (lrf.object_id () == rf->name) - return rf; - - // Then check all the complements and prerequisites repository fragments - // without loading them. Though, we still need to load complement and - // prerequisite repositories. - // - auto pr = [&lrf] (const repository::fragment_type& i) - { - return i.fragment == lrf; - }; - - for (const lazy_weak_ptr<repository>& r: cs) - { - const auto& frs (r.load ()->fragments); - - if (find_if (frs.begin (), frs.end (), pr) != frs.end ()) - return lrf.load (); - } - - if (prereq) - { - for (const lazy_weak_ptr<repository>& r: ps) - { - const auto& frs (r.load ()->fragments); - - if (find_if (frs.begin (), frs.end (), pr) != frs.end ()) - return lrf.load (); - } - } - - // Finally, load the complements and prerequisites and check them - // recursively. - // - for (const lazy_weak_ptr<repository>& cr: cs) - { - for (const auto& fr: cr.load ()->fragments) - { - // Should we consider prerequisites of our complements as our - // prerequisites? I'd say not. - // - if (shared_ptr<repository_fragment> r = - find (fr.fragment.load (), ap, chain, false)) - return r; - } - } - - if (prereq) - { - for (const lazy_weak_ptr<repository>& pr: ps) - { - for (const auto& fr: pr.load ()->fragments) - { - if (shared_ptr<repository_fragment> r = - find (fr.fragment.load (), ap, chain, false)) - return r; - } - } - } - } - - return nullptr; - } - - shared_ptr<repository_fragment> - filter (const shared_ptr<repository_fragment>& r, - const shared_ptr<available_package>& ap, - bool prereq) - { - repository_fragments chain; - return find (r, ap, chain, prereq); - } - - vector<shared_ptr<available_package>> - filter (const shared_ptr<repository_fragment>& r, - result<available_package>&& apr, - bool prereq) - { - vector<shared_ptr<available_package>> aps; - - for (shared_ptr<available_package> ap: pointer_result (apr)) - { - if (filter (r, ap, prereq) != nullptr) - aps.push_back (move (ap)); - } - - return aps; - } - - pair<shared_ptr<available_package>, shared_ptr<repository_fragment>> - filter_one (const shared_ptr<repository_fragment>& r, - result<available_package>&& apr, - bool prereq) - { - using result = pair<shared_ptr<available_package>, - shared_ptr<repository_fragment>>; - - for (shared_ptr<available_package> ap: pointer_result (apr)) - { - if (shared_ptr<repository_fragment> pr = filter (r, ap, prereq)) - return result (move (ap), move (pr)); - } - - return result (); - } - - vector<pair<shared_ptr<available_package>, shared_ptr<repository_fragment>>> - filter (const vector<shared_ptr<repository_fragment>>& rps, - odb::result<available_package>&& apr, - bool prereq) - { - vector<pair<shared_ptr<available_package>, - shared_ptr<repository_fragment>>> aps; - - for (shared_ptr<available_package> ap: pointer_result (apr)) - { - for (const shared_ptr<repository_fragment>& r: rps) - { - if (shared_ptr<repository_fragment> rf = filter (r, ap, prereq)) - { - aps.emplace_back (move (ap), move (rf)); - break; - } - } - } - - return aps; - } - - pair<shared_ptr<available_package>, shared_ptr<repository_fragment>> - filter_one (const vector<shared_ptr<repository_fragment>>& rps, - odb::result<available_package>&& apr, - bool prereq) - { - using result = pair<shared_ptr<available_package>, - shared_ptr<repository_fragment>>; - - for (shared_ptr<available_package> ap: pointer_result (apr)) - { - for (const shared_ptr<repository_fragment>& r: rps) - { - if (shared_ptr<repository_fragment> rf = filter (r, ap, prereq)) - return result (move (ap), move (rf)); - } - } - - return result (); - } - void check_any_available (const linked_databases& dbs, transaction&, @@ -480,7 +248,7 @@ namespace bpkg // Quote the result as it contains the space character. // - return "'" + name.string () + ' ' + constraint->string () + "'"; + return '\'' + name.string () + ' ' + constraint->string () + '\''; } // selected_package @@ -548,7 +316,7 @@ namespace bpkg if (s == "user") return config_source::user; else if (s == "dependent") return config_source::dependent; else if (s == "reflect") return config_source::reflect; - else throw invalid_argument ("invalid config source '" + s + "'"); + else throw invalid_argument ("invalid config source '" + s + '\''); } shared_ptr<available_package> @@ -564,18 +332,26 @@ namespace bpkg // The package is in at least fetched state, which means we should // be able to get its manifest. // - const optional<path>& a (sp->archive); - + // @@ PERF We should probably implement the available package caching not + // to parse the same manifests multiple times during all that build + // plan refinement iterations. What should be the cache key? Feels like + // it should be the archive/directory path. Note that the package + // manifests can potentially differ in different external package + // directories for the same version iteration. Testing showed 6% + // speedup on tests (debug/sanitized). + // package_manifest m ( sp->state == package_state::fetched ? pkg_verify (options, - a->absolute () ? *a : db.config_orig / *a, + sp->effective_archive (db.config_orig), true /* ignore_unknown */, + false /* ignore_toolchain */, false /* expand_values */, true /* load_buildfiles */) : pkg_verify (options, sp->effective_src_root (db.config_orig), true /* ignore_unknown */, + false /* ignore_toolchain */, true /* load_buildfiles */, // Copy potentially fixed up version from selected package. [&sp] (version& v) {v = sp->version;})); @@ -640,7 +416,7 @@ namespace bpkg { const shared_ptr<repository_fragment>& rf (prf.repository_fragment); - if (rf->location.directory_based ()) + if (!rep_masked_fragment (db, rf) && rf->location.directory_based ()) fail << "external package " << n << '/' << v << " is already available from " << rf->location.canonical_name (); @@ -656,45 +432,54 @@ namespace bpkg false /* iteration */)) return nullopt; - string mc (package_checksum (o, d, pi)); - - // The selected package must not be "simulated" (see pkg-build for - // details). - // - assert (p->manifest_checksum); - - bool changed (mc != *p->manifest_checksum); + bool changed (!p->external ()); - // If the manifest hasn't changed and the package has buildfile clauses in - // the dependencies, then check if the buildfiles haven't changed either. + // If the selected package is not external, then increment the iteration + // number to make the external package preferable. Note that for such + // packages the manifest/subprojects and buildfiles checksums are absent. // - if (!changed && p->buildfiles_checksum) + if (!changed) { - // Always calculate the checksum over the buildfiles since the package - // is external. + // The selected package must not be "simulated" (see pkg-build for + // details). // - changed = package_buildfiles_checksum ( - nullopt /* bootstrap_build */, - nullopt /* root_build */, - {} /* buildfiles */, - d) != *p->buildfiles_checksum; - } + assert (p->manifest_checksum); - // If the manifest hasn't changed but the selected package points to an - // external source directory, then we also check if the directory have - // moved. - // - if (!changed && p->external ()) - { - dir_path src_root (p->effective_src_root (db.config)); + changed = (package_checksum (o, d, pi) != *p->manifest_checksum); - // We need to complete and normalize the source directory as it may - // generally be completed against the configuration directory (unlikely - // but possible), that can be relative and/or not normalized. + // If the manifest hasn't changed and the package has buildfile clauses + // in the dependencies, then check if the buildfiles haven't changed + // either. // - normalize (src_root, "package source"); + if (!changed && p->buildfiles_checksum) + { + // Always calculate the checksum over the buildfiles since the package + // is external. + // + changed = package_buildfiles_checksum ( + nullopt /* bootstrap_build */, + nullopt /* root_build */, + {} /* buildfiles */, + d) != *p->buildfiles_checksum; + } + + // If the manifest hasn't changed but the selected package points to an + // external source directory, then we also check if the directory have + // moved. + // + if (!changed) + { + dir_path src_root (p->effective_src_root (db.config)); + + // We need to complete and normalize the source directory as it may + // generally be completed against the configuration directory + // (unlikely but possible), that can be relative and/or not + // normalized. + // + normalize (src_root, "package source"); - changed = src_root != normalize (d, "package source"); + changed = src_root != normalize (d, "package source"); + } } return !changed @@ -731,7 +516,7 @@ namespace bpkg else if (s == "fetched") return package_state::fetched; else if (s == "unpacked") return package_state::unpacked; else if (s == "configured") return package_state::configured; - else throw invalid_argument ("invalid package state '" + s + "'"); + else throw invalid_argument ("invalid package state '" + s + '\''); } // substate @@ -753,7 +538,7 @@ namespace bpkg { if (s == "none") return package_substate::none; else if (s == "system") return package_substate::system; - else throw invalid_argument ("invalid package substate '" + s + "'"); + else throw invalid_argument ("invalid package substate '" + s + '\''); } // certificate @@ -827,7 +612,7 @@ namespace bpkg bool toolchain_buildtime_dependency (const common_options& o, - const dependency_alternatives_ex& das, + const dependency_alternatives& das, const package_name* pkg) { if (das.buildtime) |