From ad770fe609d1958a64e7364861296ac5407611d9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 4 Dec 2017 12:42:09 +0200 Subject: Improve diagnostics when c-family modules using different toolchains We now also warn on toolchain pattern mismatch. --- build2/cc/common.hxx | 2 ++ build2/cc/guess.hxx | 4 ++-- build2/cc/init.cxx | 11 +++++++---- build2/cc/module.cxx | 49 +++++++++++++++++++++++++++++++++++-------------- 4 files changed, 46 insertions(+), 20 deletions(-) (limited to 'build2/cc') diff --git a/build2/cc/common.hxx b/build2/cc/common.hxx index ad550e1..f4cd0c7 100644 --- a/build2/cc/common.hxx +++ b/build2/cc/common.hxx @@ -94,6 +94,8 @@ namespace build2 const variable& x_signature; const variable& x_checksum; + const variable& x_pattern; + const variable& x_target; const variable& x_target_cpu; const variable& x_target_vendor; diff --git a/build2/cc/guess.hxx b/build2/cc/guess.hxx index 2eaa9d7..e3a4d8c 100644 --- a/build2/cc/guess.hxx +++ b/build2/cc/guess.hxx @@ -133,7 +133,7 @@ namespace build2 // unlike all the preceding fields, this one takes into account the // compile options (e.g., -m32). // - // The cc_pattern is the toolchain program pattern that could sometimes be + // The pattern is the toolchain program pattern that could sometimes be // derived for some toolchains. For example, i686-w64-mingw32-*-4.9. // // The bin_pattern is the binutils program pattern that could sometimes be @@ -151,7 +151,7 @@ namespace build2 string signature; string checksum; string target; - string cc_pattern; + string pattern; string bin_pattern; }; diff --git a/build2/cc/init.cxx b/build2/cc/init.cxx index 90821ae..7a3e99e 100644 --- a/build2/cc/init.cxx +++ b/build2/cc/init.cxx @@ -96,6 +96,7 @@ namespace build2 // Hint variables (not overridable). // v.insert ("config.cc.id"); + v.insert ("config.cc.hinter"); // Hinting module. v.insert ("config.cc.pattern"); v.insert ("config.cc.target"); @@ -156,12 +157,14 @@ namespace build2 if (!cast_false (rs["cc.core.vars.loaded"])) load_module (rs, rs, "cc.core.vars", loc); - // config.cc.id + // config.cc.{id,hinter} // { - // This value must be hinted. + // These values must be hinted. // rs.assign ("cc.id") = cast (hints["config.cc.id"]); + rs.assign ("cc.hinter") = + cast (hints["config.cc.hinter"]); } // config.cc.target @@ -188,8 +191,8 @@ namespace build2 { // This value could be hinted. // - if (auto l = hints["config.cc.pattern"]) - rs.assign ("cc.pattern") = cast (l); + rs.assign ("cc.pattern") = + cast_empty (hints["config.cc.pattern"]); } return true; diff --git a/build2/cc/module.cxx b/build2/cc/module.cxx index 74238c3..d806583 100644 --- a/build2/cc/module.cxx +++ b/build2/cc/module.cxx @@ -167,6 +167,8 @@ namespace build2 rs.assign (x_target) = move (tt); + rs.assign (x_pattern) = ci.pattern; + new_ = p.second; // Load cc.core.guess. @@ -180,10 +182,11 @@ namespace build2 // Note that all these variables have already been registered. // h.assign ("config.cc.id") = cast (rs[x_id]); + h.assign ("config.cc.hinter") = string (x); h.assign ("config.cc.target") = cast (rs[x_target]); - if (!ci.cc_pattern.empty ()) - h.assign ("config.cc.pattern") = ci.cc_pattern; + if (!ci.pattern.empty ()) + h.assign ("config.cc.pattern") = ci.pattern; load_module (rs, rs, "cc.core.guess", loc, false, h); } @@ -193,18 +196,36 @@ namespace build2 // matched ours since it could have been loaded by another c-family // module. // - // Note that we don't require that patterns match. Presumably, if the - // toolchain id and target are the same, then where exactly the tools - // come from doesn't really matter. - // + const auto& h (cast (rs["cc.hinter"])); + { const auto& cv (cast (rs["cc.id"])); const auto& xv (cast (rs[x_id])); if (cv != xv) - fail (loc) << "cc and " << x << " module toolchain mismatch" << - info << "cc.id is " << cv << - info << x_id.name << " is " << xv; + fail (loc) << h << " and " << x << " module toolchain mismatch" << + info << h << " is " << cv << + info << x << " is " << xv << + info << "consider explicitly specifying config." << h + << " and config." << x; + } + + // We used to not require that patterns match assuming that if the + // toolchain id and target are the same, then where exactly the tools + // come from doesn't really matter. But in most cases it will be the + // g++-7 vs gcc kind of mistakes. So now we warn since even if + // intentional, it is still a bad idea. + // + { + const auto& cv (cast (rs["cc.pattern"])); + const auto& xv (cast (rs[x_pattern])); + + if (cv != xv) + warn (loc) << h << " and " << x << " toolchain pattern mismatch" << + info << h << " is '" << cv << "'" << + info << x << " is '" << xv << "'" << + info << "consider explicitly specifying config." << h + << " and config." << x; } { @@ -212,9 +233,9 @@ namespace build2 const auto& xv (cast (rs[x_target])); if (cv != xv) - fail (loc) << "cc and " << x << " module target mismatch" << - info << "cc.target is " << cv << - info << x_target.name << " is " << xv; + fail (loc) << h << " and " << x << " module target mismatch" << + info << h << " target is " << cv << + info << x << " target is " << xv; } } } @@ -326,9 +347,9 @@ namespace build2 for (const string& o: tstd) dr << ' ' << o; } - if (!ci.cc_pattern.empty ()) // bin_pattern printed by bin + if (!ci.pattern.empty ()) // Note: bin_pattern printed by bin { - dr << "\n pattern " << ci.cc_pattern; + dr << "\n pattern " << ci.pattern; } if (verb >= 3 && !inc_dirs.empty ()) -- cgit v1.1