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.txx | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'build2/config/utility.txx') diff --git a/build2/config/utility.txx b/build2/config/utility.txx index d3c57a54..f49be75f 100644 --- a/build2/config/utility.txx +++ b/build2/config/utility.txx @@ -3,6 +3,7 @@ // license : MIT; see accompanying LICENSE file #include +#include namespace build2 { @@ -10,20 +11,43 @@ namespace build2 { template pair, bool> - required (scope& root, const variable& var, const T& def_value, bool ovr) + required (scope& root, const variable& var, const T& def_val, bool def_ovr) { - using result = pair, bool>; + if (current_mif->id == configure_id) + save_variable (root, var); - if (auto l = root[var]) + pair org (root.find_original (var)); + lookup l (org.first); + bool n (false); + + // The interaction with command line overrides can get tricky. For + // example, the override to defaul value could make (non-recursive) + // command line override in the outer scope no longer apply. So what we + // are going to do is first ignore overrides and perform the normal + // logic on the original. Then we apply the overrides on the result. + // + if (!l.defined () || (def_ovr && !l.belongs (root))) { - if (l.belongs (*global_scope)) - return result (root.assign (var) = *l, true); + l = lookup ((root.assign (var) = def_val), root); + org = make_pair (l, 1); // Lookup depth is 1 since in root.vars. + n = true; + } + + if (var.override != nullptr) + { + pair ovr (root.find_override (var, move (org))); + + if (l != ovr.first) // Overriden? + { + l = move (ovr.first); - if (!ovr || l.belongs (root)) - return result (*l, false); + // Overriden and not inherited (same logic as in save_config()). + // + n = l.belongs (root) || l.belongs (*global_scope); + } } - return result (root.assign (var) = def_value, true); + return pair, bool> (*l, n); } } } -- cgit