From 41cad5bba8a718a0403c0578660c60e81c9f46e4 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 27 Jun 2016 16:59:09 +0200 Subject: Add config.bin.target var/hint, use to decide libso{} install mode Normally the user doesn't need to specify config.bin.target explicitly since the cxx module will hint it. We now also have the whole set of target's components: bin.target.{cpu,vendor,system,version,class} --- build2/config/utility | 15 +++++++++++++++ build2/config/utility.cxx | 47 +++++++++++++++++++++++++++++++++++++++++------ build2/config/utility.txx | 3 +++ 3 files changed, 59 insertions(+), 6 deletions(-) (limited to 'build2/config') diff --git a/build2/config/utility b/build2/config/utility index beab758..c47cecf 100644 --- a/build2/config/utility +++ b/build2/config/utility @@ -55,6 +55,21 @@ namespace build2 return required (root, name, string (default_value), override); } + // As above, but leave the unspecified value as undefined (and return + // NULL pointer) rather than setting it to the default value. + // + // This can be useful when we don't have a default value but may figure + // out some fallback. See config.bin.target for an example. + // + pair + required (scope& root, const variable&); + + inline pair + required (scope& root, const string& name) + { + return required (root, var_pool.find (name)); + } + // Set, if necessary, an optional config.* variable. In particular, // an unspecified variable is set to NULL which is used to distinguish // between the "configured as unspecified" and "not yet configured" diff --git a/build2/config/utility.cxx b/build2/config/utility.cxx index 1dbf3d3..768a70d 100644 --- a/build2/config/utility.cxx +++ b/build2/config/utility.cxx @@ -15,28 +15,63 @@ namespace build2 namespace config { void - save_variable (scope& root, const variable& var, uint64_t flags) + save_variable (scope& r, const variable& var, uint64_t flags) { if (current_mif->id == configure_id) { // The project might not be using the config module. But then how // could we be configuring it? Good question. // - if (module* mod = root.modules.lookup (module::name)) + if (module* mod = r.modules.lookup (module::name)) mod->vars.emplace (var, flags); } } + pair + required (scope& r, const variable& var) + { + // This is a stripped-down version of the other required() twisted + // implementation. + + pair org (r.find_original (var)); + + bool n (false); // New flag. + lookup l (org.first); + + // Treat an inherited value that was set to default as new. + // + if (l.defined () && l->extra) + n = true; + + if (var.override != nullptr) + { + pair ovr (r.find_override (var, move (org))); + + if (l != ovr.first) // Overriden? + { + // Override is always treated as new. + // + n = true; + l = move (ovr.first); + } + } + + if (l.defined () && current_mif->id == configure_id) + save_variable (r, var); + + return pair (l.value, n); + } + const value& - optional (scope& root, const variable& var) + optional (scope& r, const variable& var) { if (current_mif->id == configure_id) - save_variable (root, var); + save_variable (r, var); - auto l (root[var]); + auto l (r[var]); return l.defined () ? *l - : root.assign (var); // NULL. + : r.assign (var); // NULL. } bool diff --git a/build2/config/utility.txx b/build2/config/utility.txx index 30ed02f..5ebd261 100644 --- a/build2/config/utility.txx +++ b/build2/config/utility.txx @@ -13,6 +13,9 @@ namespace build2 pair, bool> required (scope& root, const variable& var, const T& def_val, bool def_ovr) { + // Note: see also the other required() version if changing anything + // here. + if (current_mif->id == configure_id) save_variable (root, var); -- cgit v1.1