aboutsummaryrefslogtreecommitdiff
path: root/build2/config/utility.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-07-21 15:39:52 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-07-21 15:39:52 +0200
commitc1d08dbc56d0c8d3346deaba5d6b1946b6d711f4 (patch)
treede85880067c80e56d83de8e3902d95f2c2f9d7c5 /build2/config/utility.cxx
parent01fe759b58fbde7f8c7391122421dd08c754dc51 (diff)
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.
Diffstat (limited to 'build2/config/utility.cxx')
-rw-r--r--build2/config/utility.cxx59
1 files changed, 46 insertions, 13 deletions
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> (module::name))
- mod->vars.emplace (var, flags);
- }
- }
-
pair<const value*, bool>
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> (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});
+ }
+ }
}
}