From 0342dc2fcdd78ef28a4e59d84193a3807068d726 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 11 Apr 2016 07:57:19 +0200 Subject: New configuration logic, iteration 1 --- build2/config/utility.cxx | 87 ++++++++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 35 deletions(-) (limited to 'build2/config/utility.cxx') diff --git a/build2/config/utility.cxx b/build2/config/utility.cxx index e96a896..1dbf3d3 100644 --- a/build2/config/utility.cxx +++ b/build2/config/utility.cxx @@ -6,53 +6,37 @@ #include +#include + using namespace std; namespace build2 { namespace config { - const value& - optional (scope& root, const variable& var) + void + save_variable (scope& root, const variable& var, uint64_t flags) { - auto l (root[var]); - - return l.defined () - ? l.belongs (*global_scope) ? (root.assign (var) = *l) : *l - : root.assign (var); // NULL + 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)) + mod->vars.emplace (var, flags); + } } const value& - optional_absolute (scope& root, const variable& var) + optional (scope& root, const variable& var) { - auto l (root[var]); + if (current_mif->id == configure_id) + save_variable (root, var); - if (!l.defined ()) - return root.assign (var); // NULL - - if (!l.belongs (*global_scope)) // Value from (some) root scope. - return *l; - - // Make the command-line value absolute. This is necessary to avoid - // a warning issued by the config module about global/root scope - // value mismatch. - // - // @@ CMDVAR - // - value& v (const_cast (*l)); - - if (v && !v.empty ()) - { - dir_path& d (cast (v)); - - if (d.relative ()) - { - d = work / d; - d.normalize (); - } - } - - return root.assign (var) = v; + auto l (root[var]); + return l.defined () + ? *l + : root.assign (var); // NULL. } bool @@ -60,6 +44,12 @@ namespace build2 { // Search all outer scopes for any value in this namespace. // + // What about "pure" overrides, i.e., those without any original values? + // Well, they will also be found since their names have the original + // variable as a prefix. But do they apply? Yes, since we haven't found + // any original values, they will be "visible"; see find_override() for + // details. + // for (scope* s (&r); s != nullptr; s = s->parent_scope ()) { for (auto p (s->vars.find_namespace (ns)); @@ -78,5 +68,32 @@ namespace build2 return false; } + + bool + unconfigured (scope& root, const string& ns) + { + // Note: not overridable. + // + const variable& var (var_pool.insert (ns + ".configured")); + + if (current_mif->id == configure_id) + save_variable (root, var); + + auto l (root[var]); // Include inherited values. + return l && !cast (l); + } + + void + unconfigured (scope& root, const string& ns, bool v) + { + // Note: not overridable. + // + const variable& var (var_pool.insert (ns + ".configured")); + + if (current_mif->id == configure_id) + save_variable (root, var); + + root.assign (var) = !v; + } } } -- cgit v1.1