From fad62fd770129d79e370fc95323543581473cad8 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 29 Jan 2019 16:12:21 +0300 Subject: Fix package dependency constraint completions that could end up with latest snapshot --- bpkg/pkg-build.cxx | 33 +++++++++++++++++++++------------ bpkg/pkg-checkout.cxx | 5 ++++- bpkg/pkg-configure.cxx | 5 +++-- bpkg/pkg-unpack.cxx | 13 +++++++++---- bpkg/pkg-verify.cxx | 7 +++++-- bpkg/pkg-verify.hxx | 11 ++++++++--- bpkg/rep-fetch.cxx | 17 +++++++++-------- 7 files changed, 59 insertions(+), 32 deletions(-) diff --git a/bpkg/pkg-build.cxx b/bpkg/pkg-build.cxx index 91186db..f9c84ef 100644 --- a/bpkg/pkg-build.cxx +++ b/bpkg/pkg-build.cxx @@ -193,11 +193,10 @@ namespace bpkg a->absolute () ? *a : c / *a, true /* ignore_unknown */, false /* expand_values */) - : pkg_verify (sp->effective_src_root (c), true /* ignore_unknown */)); - - // Copy the possibly fixed up version from the selected package. - // - m.version = sp->version; + : pkg_verify (sp->effective_src_root (c), + true /* ignore_unknown */, + // Copy potentially fixed up version from selected package. + [&sp] (version& v) {v = sp->version;})); return make_pair (make_shared (move (m)), move (af)); } @@ -2936,6 +2935,8 @@ namespace bpkg // This is a package archive. // + // Note that throwing failed from here on will be fatal. + // package_arc = true; l4 ([&]{trace << "archive '" << a << "': " << arg_string (pa);}); @@ -2994,10 +2995,20 @@ namespace bpkg << "package directory: "; package_manifest m ( - pkg_verify (d, true /* ignore_unknown */, diag)); + pkg_verify ( + d, + true /* ignore_unknown */, + [&o, &d] (version& v) + { + if (optional pv = package_version (o, d)) + v = move (*pv); + }, + diag)); // This is a package directory. // + // Note that throwing failed from here on will be fatal. + // package_dir = true; l4 ([&]{trace << "directory '" << d << "': " @@ -3011,12 +3022,8 @@ namespace bpkg << "' may not be built as a dependency"; // Fix-up the package version to properly decide if we need to - // upgrade/downgrade the package. Note that throwing failed - // from here on will be fatal. + // upgrade/downgrade the package. // - if (optional v = package_version (o, d)) - m.version = move (*v); - if (optional v = package_iteration (o, c, @@ -4542,7 +4549,9 @@ namespace bpkg assert (sp->state == package_state::unpacked); package_manifest m ( - pkg_verify (sp->effective_src_root (c), true /* ignore_unknown */)); + pkg_verify (sp->effective_src_root (c), + true /* ignore_unknown */, + [&sp] (version& v) {v = sp->version;})); pkg_configure (c, o, t, sp, m.dependencies, p.config_vars, simulate); } diff --git a/bpkg/pkg-checkout.cxx b/bpkg/pkg-checkout.cxx index a91cb92..6802c36 100644 --- a/bpkg/pkg-checkout.cxx +++ b/bpkg/pkg-checkout.cxx @@ -151,7 +151,10 @@ namespace bpkg // Verify the package prerequisites are all configured since the dist // meta-operation generally requires all imports to be resolvable. // - package_manifest m (pkg_verify (sd, true /* ignore_unknown */)); + package_manifest m (pkg_verify (sd, + true /* ignore_unknown */, + [&ap] (version& v) {v = ap->version;})); + pkg_configure_prerequisites (o, t, m.dependencies, m.name); if (exists (d)) diff --git a/bpkg/pkg-configure.cxx b/bpkg/pkg-configure.cxx index 515d7bd..962ae90 100644 --- a/bpkg/pkg-configure.cxx +++ b/bpkg/pkg-configure.cxx @@ -316,8 +316,9 @@ namespace bpkg l4 ([&]{trace << *p;}); - package_manifest m ( - pkg_verify (p->effective_src_root (c), true /* ignore_unknown */)); + package_manifest m (pkg_verify (p->effective_src_root (c), + true /* ignore_unknown */, + [&p] (version& v) {v = p->version;})); pkg_configure (c, o, t, p, m.dependencies, vars, false /* simulate */); } diff --git a/bpkg/pkg-unpack.cxx b/bpkg/pkg-unpack.cxx index 9d041e5..483a252 100644 --- a/bpkg/pkg-unpack.cxx +++ b/bpkg/pkg-unpack.cxx @@ -171,7 +171,15 @@ namespace bpkg // Verify the directory is a package and get its manifest. // - package_manifest m (pkg_verify (d, true /* ignore_unknown */)); + package_manifest m ( + pkg_verify (d, + true /* ignore_unknown */, + [&o, &d] (version& v) + { + if (optional pv = package_version (o, d)) + v = move (*pv); + })); + l4 ([&]{trace << d << ": " << m.name << " " << m.version;}); // Check/diagnose an already existing package. @@ -180,9 +188,6 @@ namespace bpkg // Fix-up the package version. // - if (optional v = package_version (o, d)) - m.version = move (*v); - if (optional v = package_iteration ( o, c, t, d, m.name, m.version, true /* check_external */)) m.version = move (*v); diff --git a/bpkg/pkg-verify.cxx b/bpkg/pkg-verify.cxx index 3894b25..00a5db0 100644 --- a/bpkg/pkg-verify.cxx +++ b/bpkg/pkg-verify.cxx @@ -143,7 +143,10 @@ namespace bpkg } package_manifest - pkg_verify (const dir_path& d, bool iu, bool diag) + pkg_verify (const dir_path& d, + bool iu, + const function& tf, + bool diag) { // Parse the manifest. // @@ -161,7 +164,7 @@ namespace bpkg { ifdstream ifs (mf); manifest_parser mp (ifs, mf.string ()); - package_manifest m (mp, iu); + package_manifest m (mp, tf, iu); // We used to verify package directory is - but it is // not clear why we should enforce it in this case (i.e., the user diff --git a/bpkg/pkg-verify.hxx b/bpkg/pkg-verify.hxx index 3741467..f3a7c01 100644 --- a/bpkg/pkg-verify.hxx +++ b/bpkg/pkg-verify.hxx @@ -33,11 +33,16 @@ namespace bpkg bool diag = true); // Similar to the above but verifies that a source directory is a valid - // package. Note that it doesn't enforce the - form for the - // directory itself. + // package. Always translates the package version and completes dependency + // constraints but doesn't expand the file-referencing manifest values. Note + // that it doesn't enforce the - form for the directory + // itself. // package_manifest - pkg_verify (const dir_path& source, bool ignore_unknown, bool diag = true); + pkg_verify (const dir_path& source, + bool ignore_unknown, + const function&, + bool diag = true); } #endif // BPKG_PKG_VERIFY_HXX diff --git a/bpkg/rep-fetch.cxx b/bpkg/rep-fetch.cxx index 83a30f9..b64bbe2 100644 --- a/bpkg/rep-fetch.cxx +++ b/bpkg/rep-fetch.cxx @@ -231,7 +231,15 @@ namespace bpkg { ifdstream ifs (f); manifest_parser mp (ifs, f.string ()); - package_manifest m (mp, iu); + + package_manifest m ( + mp, + [&co, &d] (version& v) + { + if (optional pv = package_version (co, d)) + v = move (*pv); + }, + iu); // Save the package manifest, preserving its location. // @@ -249,13 +257,6 @@ namespace bpkg fail << "unable to read from " << f << ": " << e; } - // Fix-up the package version. - // - optional v (package_version (co, d)); - - if (v) - sm.version = move (*v); - r.emplace_back (move (sm)); } -- cgit v1.1