From 9f5c4c1ae3bff517eefb39130287016514fb31c7 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 6 Jan 2017 17:28:45 +0200 Subject: Store platform targets as typed target_triplet --- build2/cc/module.cxx | 104 +++++++++++++++++++++++++++------------------------ 1 file changed, 56 insertions(+), 48 deletions(-) (limited to 'build2/cc/module.cxx') diff --git a/build2/cc/module.cxx b/build2/cc/module.cxx index 5ac10f7..067aea3 100644 --- a/build2/cc/module.cxx +++ b/build2/cc/module.cxx @@ -6,8 +6,6 @@ #include // left, setw() -#include - #include #include #include @@ -93,31 +91,33 @@ namespace build2 // Split/canonicalize the target. First see if the user asked us to // use config.sub. // - string ct, st; - triplet tt; - - if (ops.config_sub_specified ()) + target_triplet tt; { - st = run (ops.config_sub (), - ci.target.c_str (), - [] (string& l) {return move (l);}); - l5 ([&]{trace << "config.sub target: '" << st << "'";}); - } + string ct; - try - { - tt = triplet (st.empty () ? ci.target : st, ct); - l5 ([&]{trace << "canonical target: '" << ct << "'; " - << "class: " << tt.class_;}); - } - catch (const invalid_argument& e) - { - // This is where we suggest that the user specifies --config-sub to - // help us out. - // - fail << "unable to parse " << x_lang << " compiler target '" - << ci.target << "': " << e.what () << - info << "consider using the --config-sub option"; + if (ops.config_sub_specified ()) + { + ct = run (ops.config_sub (), + ci.target.c_str (), + [] (string& l) {return move (l);}); + l5 ([&]{trace << "config.sub target: '" << ct << "'";}); + } + + try + { + tt = target_triplet (ct.empty () ? ci.target : ct); + l5 ([&]{trace << "canonical target: '" << tt.string () << "'; " + << "class: " << tt.class_;}); + } + catch (const invalid_argument& e) + { + // This is where we suggest that the user specifies --config-sub to + // help us out. + // + fail << "unable to parse " << x_lang << " compiler target '" + << ci.target << "': " << e.what () << + info << "consider using the --config-sub option"; + } } // Translate x_std value (if any) to the compiler option (if any). @@ -177,6 +177,8 @@ namespace build2 } { + const string& ct (tt.string ()); // Canonical target. + dr << " signature " << ci.signature << '\n' << " target " << ct; @@ -232,14 +234,16 @@ namespace build2 rs.assign (x_signature) = move (ci.signature); rs.assign (x_checksum) = move (ci.checksum); - // Enter as x.target.{cpu,vendor,system,version,class}. + // Also enter as x.target.{cpu,vendor,system,version,class} for + // convenience of access. // - rs.assign (x_target) = move (ct); - rs.assign (x_target_cpu) = move (tt.cpu); - rs.assign (x_target_vendor) = move (tt.vendor); - rs.assign (x_target_system) = move (tt.system); - rs.assign (x_target_version) = move (tt.version); - rs.assign (x_target_class) = move (tt.class_); + rs.assign (x_target_cpu) = tt.cpu; + rs.assign (x_target_vendor) = tt.vendor; + rs.assign (x_target_system) = tt.system; + rs.assign (x_target_version) = tt.version; + rs.assign (x_target_class) = tt.class_; + + rs.assign (x_target) = move (tt); // config.x.{p,c,l}options // config.x.libs @@ -278,7 +282,7 @@ namespace build2 variable_map h; h.assign ("config.cc.id") = cast (rs[x_id]); - h.assign ("config.cc.target") = cast (rs[x_target]); + h.assign ("config.cc.target") = cast (rs[x_target]); if (!ci.cc_pattern.empty ()) h.assign ("config.cc.pattern") = move (ci.cc_pattern); @@ -294,25 +298,29 @@ namespace build2 // matched ours since it could have been loaded by another c-family // module. // - auto check = [&rs, &loc, this](const char* cvar, - const variable& xvar, - const char* w) - { - const string& cv (cast (rs[cvar])); - const string& xv (cast (rs[xvar])); - - if (cv != xv) - fail (loc) << "cc and " << x << " module " << w << " mismatch" << - info << cvar << " is " << cv << - info << xvar.name << " is " << xv; - }; - // 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. // - check ("cc.id", x_id, "toolchain"); - check ("cc.target", x_target, "target"); + { + 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; + } + + { + const auto& cv (cast (rs["cc.target"])); + 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; + } } } -- cgit v1.1