From 7e34f1a99bd6ac9e604ee1c85ec6224928ba81f7 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 8 Mar 2019 13:27:51 +0300 Subject: Use real package names rather than sanitized ones for diagnostics in version module --- build2/version/init.cxx | 14 +++++++++----- build2/version/module.hxx | 20 +++++++++++++++----- build2/version/rule.cxx | 35 ++++++++++++++++++++--------------- 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/build2/version/init.cxx b/build2/version/init.cxx index 7e8f0ffe..1a5f2492 100644 --- a/build2/version/init.cxx +++ b/build2/version/init.cxx @@ -45,7 +45,7 @@ namespace build2 string url; standard_version v; - dependency_constraints ds; + dependencies ds; { path f (rs.src_path () / manifest_file); @@ -129,7 +129,10 @@ namespace build2 try { - ds.emplace (project_name (move (n)).variable (), move (c)); + package_name pn (move (n)); + string v (pn.variable ()); + + ds.emplace (move (v), dependency {move (pn), move (c)}); } catch (const invalid_argument& e) { @@ -184,15 +187,16 @@ namespace build2 { auto i (ds.find ("build2")); - if (i != ds.end () && !i->second.empty ()) + if (i != ds.end () && !i->second.constraint.empty ()) try { - check_build_version (standard_version_constraint (i->second, v), l); + check_build_version ( + standard_version_constraint (i->second.constraint, v), l); } catch (const invalid_argument& e) { fail (l) << "invalid version constraint for dependency build2 " - << i->second << ": " << e; + << i->second.constraint << ": " << e; } } diff --git a/build2/version/module.hxx b/build2/version/module.hxx index 46af616c..1c6e6370 100644 --- a/build2/version/module.hxx +++ b/build2/version/module.hxx @@ -16,13 +16,23 @@ namespace build2 { namespace version { - // The 'depends' values from manifest. Note that the package names are - // sanitized for use in variable names. + // A map of package names sanitized for use in variable names to the + // 'depends' values from manifest. // - using dependency_constraints = std::map; + using package_name = project_name; + + struct dependency + { + package_name name; + string constraint; + }; + + using dependencies = std::map; struct module: module_base { + using dependencies_type = version::dependencies; + static const string name; // The project variable value sanitized for use in variable names. @@ -33,7 +43,7 @@ namespace build2 bool committed; // Whether this is a committed snapshot. bool rewritten; // Whether this is a rewritten .z snapshot. - dependency_constraints dependencies; + dependencies_type dependencies; bool dist_uncommitted = false; @@ -41,7 +51,7 @@ namespace build2 butl::standard_version v, bool c, bool r, - dependency_constraints d) + dependencies_type d) : project (p.variable ()), version (move (v)), committed (c), diff --git a/build2/version/rule.cxx b/build2/version/rule.cxx index 83f402fe..674defda 100644 --- a/build2/version/rule.cxx +++ b/build2/version/rule.cxx @@ -134,25 +134,30 @@ namespace build2 // all of them are necessarily in the standard form and secondly because // of the MT-safety. // - standard_version_constraint c; + standard_version_constraint dc; + const package_name* dn; { auto i (m.dependencies.find (pn)); if (i == m.dependencies.end ()) fail (l) << "unknown dependency '" << pn << "'"; - if (i->second.empty ()) - fail (l) << "no version constraint for dependency " << pn; + const dependency& dp (i->second); + + if (dp.constraint.empty ()) + fail (l) << "no version constraint for dependency " << dp.name; try { - c = standard_version_constraint (i->second, m.version); + dc = standard_version_constraint (dp.constraint, m.version); } catch (const invalid_argument& e) { - fail (l) << "invalid version constraint for dependency " << pn - << " " << i->second << ": " << e; + fail (l) << "invalid version constraint for dependency " << dp.name + << " " << dp.constraint << ": " << e; } + + dn = &dp.name; } // Now substitute. @@ -160,7 +165,7 @@ namespace build2 size_t i; if (vn == "version") { - return c.string (); // Use normalized representation. + return dc.string (); // Use normalized representation. } if (vn.compare (0, (i = 6), "check(") == 0 || vn.compare (0, (i = 10), "condition(") == 0) @@ -178,18 +183,18 @@ namespace build2 trim (vm); trim (sm); - auto cond = [&l, &c, &vm, &sm] () -> string + auto cond = [&l, &dc, &vm, &sm] () -> string { - auto& miv (c.min_version); - auto& mav (c.max_version); + auto& miv (dc.min_version); + auto& mav (dc.max_version); - bool mio (c.min_open); - bool mao (c.max_open); + bool mio (dc.min_open); + bool mao (dc.max_open); if (sm.empty () && ((miv && miv->snapshot ()) || (mav && mav->snapshot ()))) - fail (l) << "snapshot macro required for " << c.string (); + fail (l) << "snapshot macro required for " << dc.string (); auto cmp = [] (const string& m, const char* o, uint64_t v) { @@ -278,8 +283,8 @@ namespace build2 // r += "#ifdef " + vm + "\n"; r += "# if !(" + cond () + ")\n"; - r += "# error incompatible " + pn + " version, "; - r += pn + ' ' + c.string () + " is required\n"; + r += "# error incompatible " + dn->string () + " version, "; + r += dn->string () + ' ' + dc.string () + " is required\n"; r += "# endif\n"; r += "#endif"; -- cgit