From 58357d79110a925dcb3cdc734d812f17b6465c17 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 24 Jun 2020 22:12:01 +0300 Subject: Fix build order for test and main packages --- bpkg/rep-fetch.cxx | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 3 deletions(-) (limited to 'bpkg/rep-fetch.cxx') diff --git a/bpkg/rep-fetch.cxx b/bpkg/rep-fetch.cxx index 1b8e00a..b58ef2c 100644 --- a/bpkg/rep-fetch.cxx +++ b/bpkg/rep-fetch.cxx @@ -5,7 +5,6 @@ #include #include -#include // equal() #include @@ -1273,8 +1272,8 @@ namespace bpkg } } - // Finally, make sure that the external packages are available from a - // single directory-based repository. + // Make sure that the external packages are available from a single + // directory-based repository. // // Sort the packages by name and version. This way the external packages // with the same upstream version and revision will be adjacent. Note @@ -1324,6 +1323,70 @@ namespace bpkg ap = id; rf = f; } + + // Finally, invert the main packages external test dependencies into the + // the test packages special test dependencies. + // + // But first, remove the existing (and possibly outdated) special test + // dependencies from the test packages, unless all the available + // packages are (re)created from scratch. + // + if (!full_fetch) + { + for (const auto& at: db.query ()) + { + dependencies& ds (at.package->dependencies); + + // Note that the special test dependencies entry is always the last + // one, if present. + // + assert (!ds.empty () && ds.back ().type); + + ds.pop_back (); + + db.update (at.package); + } + } + + // Go through the available packages that have external tests and add + // them as the special test dependencies to these test packages. + // + for (const auto& am: db.query ()) + { + const shared_ptr& p (am.package); + + vector> rfs; + + for (const package_location& pl: p->locations) + rfs.push_back (pl.repository_fragment.load ()); + + for (const test_dependency& td: p->tests) + { + vector, + shared_ptr>> tps ( + filter (rfs, + query_available (db, + td.name, + td.constraint, + false /* order */), + false /* prereq */)); + + for (const auto& t: tps) + { + const shared_ptr& tp (t.first); + + dependencies& ds (tp->dependencies); + + if (ds.empty () || !ds.back ().type) + ds.push_back (dependency_alternatives_ex (td.type)); + + ds.back ().push_back ( + dependency {p->id.name, version_constraint (p->version)}); + + db.update (tp); + } + } + } } catch (const failed&) { -- cgit v1.1