diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-04-11 07:57:19 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-04-11 07:57:19 +0200 |
commit | 0342dc2fcdd78ef28a4e59d84193a3807068d726 (patch) | |
tree | e750c3062d6ff54f0d409fe1a25984b7e78592c8 /build2/config/utility.cxx | |
parent | 5f7c3f923de106f9d204a8f3500274731ae84fd9 (diff) |
New configuration logic, iteration 1
Diffstat (limited to 'build2/config/utility.cxx')
-rw-r--r-- | build2/config/utility.cxx | 87 |
1 files changed, 52 insertions, 35 deletions
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 <build2/context> +#include <build2/config/module> + 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> (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<value&> (*l)); - - if (v && !v.empty ()) - { - dir_path& d (cast<dir_path> (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<bool> (ns + ".configured")); + + if (current_mif->id == configure_id) + save_variable (root, var); + + auto l (root[var]); // Include inherited values. + return l && !cast<bool> (l); + } + + void + unconfigured (scope& root, const string& ns, bool v) + { + // Note: not overridable. + // + const variable& var (var_pool.insert<bool> (ns + ".configured")); + + if (current_mif->id == configure_id) + save_variable (root, var); + + root.assign (var) = !v; + } } } |