From c1d08dbc56d0c8d3346deaba5d6b1946b6d711f4 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 21 Jul 2016 15:39:52 +0200 Subject: Save config vars in order specified rather than alphabetically This way we can group them semantically which results in easier to understand config.build output. --- build2/config/utility.cxx | 59 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 13 deletions(-) (limited to 'build2/config/utility.cxx') diff --git a/build2/config/utility.cxx b/build2/config/utility.cxx index 768a70d..a24f7b3 100644 --- a/build2/config/utility.cxx +++ b/build2/config/utility.cxx @@ -14,19 +14,6 @@ namespace build2 { namespace config { - void - 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 = r.modules.lookup (module::name)) - mod->vars.emplace (var, flags); - } - } - pair required (scope& r, const variable& var) { @@ -130,5 +117,51 @@ namespace build2 root.assign (var) = !v; } + + void + save_variable (scope& r, const variable& var, uint64_t flags) + { + if (current_mif->id != configure_id) + return; + + // The project might not be using the config module. But then how + // could we be configuring it? Good question. + // + if (module* m = r.modules.lookup (module::name)) + { + const string& n (var.name); + + // First try to find the module with the name that is the longest + // prefix of this variable name. + // + saved_modules& sm (m->saved_modules); + auto i (sm.end ()); + + if (!sm.empty ()) + { + i = sm.upper_bound (n); + + // Get the greatest less than, if any. We might still not be a + // suffix. And we still have to check the last element if + // upper_bound() returned end(). + // + if (i == sm.begin () || !sm.key_comp ().prefix ((--i)->first, n)) + i = sm.end (); + } + + // If no module matched, then create one based on the variable name. + // + if (i == sm.end ()) + { + // @@ For now with 'config.' prefix. + // + i = sm.insert (string (n, 0, n.find ('.', 7))); + } + + // We assume each variable is saved/configured once. + // + i->second.push_back (saved_variable {var, flags}); + } + } } } -- cgit v1.1