From 67d42b48930f65a7e270e153f1ca627c5241d17b Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 28 Jul 2023 22:04:29 +0300 Subject: Fix unexpected 'no package available for dependency' error when building from archives (GH issue #303) --- bpkg/package-query.cxx | 29 +++++++++++++++++++++++++++++ bpkg/package-query.hxx | 19 +++++++++++++++++++ bpkg/pkg-build-collect.cxx | 7 +++++-- bpkg/pkg-build.cxx | 4 ++++ bpkg/pkg-checkout.cxx | 2 +- bpkg/pkg-unpack.cxx | 2 +- 6 files changed, 59 insertions(+), 4 deletions(-) (limited to 'bpkg') diff --git a/bpkg/package-query.cxx b/bpkg/package-query.cxx index 9705579..0c6d459 100644 --- a/bpkg/package-query.cxx +++ b/bpkg/package-query.cxx @@ -7,6 +7,7 @@ #include #include #include +#include using namespace std; @@ -26,6 +27,34 @@ namespace bpkg return i != imaginary_stubs.end () ? *i : nullptr; } + vector, + shared_ptr>> existing_packages; + + pair, lazy_shared_ptr> + find_existing (const package_name& name, + const optional& c, + const lazy_shared_ptr& rf) + { + database& db (rf.database ()); + + pair, + lazy_shared_ptr> r; + + for (const auto& p: existing_packages) + { + if (p.first == db && + p.second->id.name == name && + (!c || satisfies (p.second->version, *c))) + { + r.first = p.second; + r.second = lazy_shared_ptr (db, empty_string); + break; + } + } + + return r; + } + linked_databases repo_configs; linked_databases diff --git a/bpkg/package-query.hxx b/bpkg/package-query.hxx index 12456ce..be4e0be 100644 --- a/bpkg/package-query.hxx +++ b/bpkg/package-query.hxx @@ -226,6 +226,25 @@ namespace bpkg shared_ptr find_imaginary_stub (const package_name&); + // Try to find an available package in the existing packages registry. Such + // a registry is configuration-specific and contains package versions + // specified by the user on the command line as archives or directories for + // specific configurations (see pkg-build for details on such packages). + // + // Note that semantically such a registry can be considered as an imaginary + // repository which complements all the real repositories fetched in the + // respective configuration. Also note that normally this repository is used + // first (by calling this function) when trying to resolve a dependency + // package, prior to searching in the real repositories. + // + extern vector, + shared_ptr>> existing_packages; + + pair, lazy_shared_ptr> + find_existing (const package_name&, + const optional&, + const lazy_shared_ptr&); + // Configurations to use as the repository information sources. // // The list normally contains the current configurations and configurations diff --git a/bpkg/pkg-build-collect.cxx b/bpkg/pkg-build-collect.cxx index c581f5c..4006caa 100644 --- a/bpkg/pkg-build-collect.cxx +++ b/bpkg/pkg-build-collect.cxx @@ -2507,7 +2507,10 @@ namespace bpkg // recognized. An unrecognized package means the broken/stale // repository (see below). // - rp = find_available_one (dn, d.constraint, af); + rp = find_existing (dn, d.constraint, af); + + if (dap == nullptr) + rp = find_available_one (dn, d.constraint, af); if (dap == nullptr && system && d.constraint) rp = find_available_one (dn, nullopt, af); @@ -2658,7 +2661,7 @@ namespace bpkg system, specified, force, - ru}); + ru}); } // Now, as we have pre-collected the dependency builds, go through diff --git a/bpkg/pkg-build.cxx b/bpkg/pkg-build.cxx index 9a73ea6..46569df 100644 --- a/bpkg/pkg-build.cxx +++ b/bpkg/pkg-build.cxx @@ -2946,6 +2946,8 @@ namespace bpkg af = root; ap = make_shared (move (m)); ap->locations.push_back (package_location {root, move (a)}); + + existing_packages.push_back (make_pair (ref (*pdb), ap)); } } catch (const invalid_path&) @@ -3037,6 +3039,8 @@ namespace bpkg ap = make_shared (move (m)); af = root; ap->locations.push_back (package_location {root, move (d)}); + + existing_packages.push_back (make_pair (ref (*pdb), ap)); } } catch (const invalid_path&) diff --git a/bpkg/pkg-checkout.cxx b/bpkg/pkg-checkout.cxx index d7b36e4..81efdc2 100644 --- a/bpkg/pkg-checkout.cxx +++ b/bpkg/pkg-checkout.cxx @@ -133,7 +133,7 @@ namespace bpkg check_any_available (rdb, t); - // Note that here we compare including the revision (see pkg-fetch() + // Note that here we compare including the revision (see pkg_fetch() // implementation for more details). // shared_ptr ap ( diff --git a/bpkg/pkg-unpack.cxx b/bpkg/pkg-unpack.cxx index 6e99b36..323f296 100644 --- a/bpkg/pkg-unpack.cxx +++ b/bpkg/pkg-unpack.cxx @@ -289,7 +289,7 @@ namespace bpkg check_any_available (rdb, t); - // Note that here we compare including the revision (see pkg-fetch() + // Note that here we compare including the revision (see pkg_fetch() // implementation for more details). // shared_ptr ap ( -- cgit v1.1