From e2ba7fa123213fcc5673119b8d993d7967a1fb24 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 7 Sep 2017 18:09:44 +0200 Subject: Implement {c,cxx}.guess modules These can be loaded before {c,cxx} to guess the compiler. Based on this information we can then choose the standard, experimental features, etc. For example: using cxx.guess if ($cxx.id == 'clang') cxx.features.modules = false cxx.std = experimental using cxx --- build2/c/init.cxx | 62 +++++++++++++++++++++++++++++++++++++++++-------------- build2/c/init.hxx | 9 ++++++++ 2 files changed, 55 insertions(+), 16 deletions(-) (limited to 'build2/c') diff --git a/build2/c/init.cxx b/build2/c/init.cxx index 79cfec7..1190eae 100644 --- a/build2/c/init.cxx +++ b/build2/c/init.cxx @@ -30,7 +30,7 @@ namespace build2 config_module (config_data&& d) : config_data (move (d)), cc::config_module (move (d)) {} - strings + virtual strings translate_std (const compiler_info&, scope&, const string*) const override; @@ -106,22 +106,24 @@ namespace build2 return r; } + // See cc::module for details on guess_init vs config_init. + // bool - config_init (scope& rs, - scope& bs, - const location& loc, - unique_ptr& mod, - bool, - bool, - const variable_map& hints) + guess_init (scope& rs, + scope& bs, + const location& loc, + unique_ptr& mod, + bool, + bool, + const variable_map& hints) { - tracer trace ("c::config_init"); + tracer trace ("c::guess_init"); l5 ([&]{trace << "for " << bs.out_path ();}); // We only support root loading (which means there can only be one). // if (&rs != &bs) - fail (loc) << "c.config module must be loaded in project root"; + fail (loc) << "c.guess module must be loaded in project root"; // Load cc.core.vars so that we can cache all the cc.* variables. // @@ -207,10 +209,38 @@ namespace build2 assert (mod == nullptr); config_module* m (new config_module (move (d))); mod.reset (m); - m->init (rs, loc, hints); + m->guess (rs, loc, hints); return true; } + bool + config_init (scope& rs, + scope& bs, + const location& loc, + unique_ptr&, + bool, + bool, + const variable_map& hints) + { + tracer trace ("c::config_init"); + l5 ([&]{trace << "for " << bs.out_path ();}); + + // We only support root loading (which means there can only be one). + // + if (&rs != &bs) + fail (loc) << "c.config module must be loaded in project root"; + + // Load c.guess. + // + if (!cast_false (rs["c.guess.loaded"])) + load_module (rs, rs, "c.guess", loc, false, hints); + + config_module& cm (*rs.modules.lookup ("c.guess")); + cm.init (rs, loc, hints); + return true; + } + + static const target_type* const hdr[] = { &h::static_type, @@ -246,7 +276,7 @@ namespace build2 if (!cast_false (rs["c.config.loaded"])) load_module (rs, rs, "c.config", loc, false, hints); - config_module& cm (*rs.modules.lookup ("c.config")); + config_module& cm (*rs.modules.lookup ("c.guess")); cc::data d { cm, @@ -256,10 +286,10 @@ namespace build2 "c.install", "c.uninstall", - cm.cid, - cast (rs[cm.x_id_variant]), - cast (rs[cm.x_version_major]), - cast (rs[cm.x_version_minor]), + cm.ci.id.value (), + cm.ci.id.variant, + cm.ci.version.major, + cm.ci.version.minor, cast (rs[cm.x_path]), cast (rs[cm.x_target]), diff --git a/build2/c/init.hxx b/build2/c/init.hxx index e18a5df..5fd7c84 100644 --- a/build2/c/init.hxx +++ b/build2/c/init.hxx @@ -15,6 +15,15 @@ namespace build2 namespace c { bool + guess_init (scope&, + scope&, + const location&, + unique_ptr&, + bool, + bool, + const variable_map&); + + bool config_init (scope&, scope&, const location&, -- cgit v1.1