From ca708a3f172e2f0ffab8638087b3e478de06b996 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 2 Apr 2020 15:07:26 +0300 Subject: Make brep-load to resolve package dependencies in shallow mode --- libbrep/package.hxx | 4 ++-- load/load.cli | 3 ++- load/load.cxx | 43 +++++++++++++++++++++---------------------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/libbrep/package.hxx b/libbrep/package.hxx index f8a4079..07bd2a0 100644 --- a/libbrep/package.hxx +++ b/libbrep/package.hxx @@ -140,8 +140,8 @@ namespace brep package_name name; optional constraint; - // Resolved dependency package. NULL if the repository load was shallow - // and so the package dependencies are not resolved. + // Resolved dependency package. Can be NULL if the repository load was + // shallow and the package dependency could not be resolved. // lazy_shared_ptr package; diff --git a/load/load.cli b/load/load.cli index be19ebf..05bbb11 100644 --- a/load/load.cli +++ b/load/load.cli @@ -53,7 +53,8 @@ class options bool --shallow { "Don't load package information from prerequisite or complement - repositories." + repositories, don't fail if unable to resolve a package dependency, and + don't detect package dependency cycles." }; std::string --tenant diff --git a/load/load.cxx b/load/load.cxx index bf8584c..260f557 100644 --- a/load/load.cxx +++ b/load/load.cxx @@ -852,11 +852,12 @@ find (const lazy_shared_ptr& r, // Resolve package run-time dependencies, tests, examples, and benchmarks. // Make sure that the best matching dependency belongs to the package // repositories, their complements, recursively, or their immediate -// prerequisite repositories (only for run-time dependencies). Should be -// called once per internal package. +// prerequisite repositories (only for run-time dependencies). Fail if unable +// to resolve a dependency, unless ignore_unresolved is true in which case +// leave this dependency NULL. Should be called once per internal package. // static void -resolve_dependencies (package& p, database& db) +resolve_dependencies (package& p, database& db, bool ignore_unresolved) { using brep::dependency; using brep::dependency_alternatives; @@ -960,31 +961,28 @@ resolve_dependencies (package& p, database& db) // Practically it is enough to resolve at least one dependency // alternative to build a package. Meanwhile here we consider an error // specifying in the manifest file an alternative which can't be - // resolved. + // resolved, unless unresolved dependencies are allowed. // - if (!resolve (d, true /* prereq */)) + if (!resolve (d, true /* prereq */) && !ignore_unresolved) bail (d, "dependency"); } } - // Should we allow tests, examples, and benchmarks packages to be - // unresolvable? Let's forbid that until we see a use case for that. - // for (dependency& d: p.tests) { - if (!resolve (d, false /* prereq */)) + if (!resolve (d, false /* prereq */) && !ignore_unresolved) bail (d, "tests"); } for (dependency& d: p.examples) { - if (!resolve (d, false /* prereq */)) + if (!resolve (d, false /* prereq */) && !ignore_unresolved) bail (d, "examples"); } for (dependency& d: p.benchmarks) { - if (!resolve (d, false /* prereq */)) + if (!resolve (d, false /* prereq */) && !ignore_unresolved) bail (d, "benchmarks"); } @@ -1371,9 +1369,9 @@ try load_repositories (r, db, ops.ignore_unknown (), ops.shallow ()); } - // Resolve internal packages dependencies unless this is a shallow load. + // Resolve internal packages dependencies and, unless this is a shallow + // load, make sure there are no package dependency cycles. // - if (!ops.shallow ()) { session s; using query = query; @@ -1382,16 +1380,17 @@ try db.query ( query::id.tenant == tnt && query::internal_repository.canonical_name.is_not_null ())) - resolve_dependencies (p, db); + resolve_dependencies (p, db, ops.shallow ()); - // Make sure there is no package dependency cycles. - // - package_ids chain; - for (const auto& p: - db.query ( - query::id.tenant == tnt && - query::internal_repository.canonical_name.is_not_null ())) - detect_dependency_cycle (p.id, chain, db); + if (!ops.shallow ()) + { + package_ids chain; + for (const auto& p: + db.query ( + query::id.tenant == tnt && + query::internal_repository.canonical_name.is_not_null ())) + detect_dependency_cycle (p.id, chain, db); + } } } -- cgit v1.1