From 83f8b6a45fc041586819537ca86be2eb534f79b0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 16 Mar 2017 18:14:16 +0200 Subject: Implement create meta-operation --- build2/config/module.cxx | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 build2/config/module.cxx (limited to 'build2/config/module.cxx') diff --git a/build2/config/module.cxx b/build2/config/module.cxx new file mode 100644 index 0000000..6d54e46 --- /dev/null +++ b/build2/config/module.cxx @@ -0,0 +1,66 @@ +// file : build2/config/module.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include + +using namespace std; + +namespace build2 +{ + namespace config + { + void module:: + save_variable (const variable& var, uint64_t flags) + { + const string& n (var.name); + + // First try to find the module with the name that is the longest + // prefix of this variable name. + // + auto& sm (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))); + } + + // Don't insert duplicates. The config.import vars are particularly + // susceptible to duplication. + // + saved_variables& sv (i->second); + auto j (sv.find (var)); + + if (j == sv.end ()) + sv.push_back (saved_variable {var, flags}); + else + assert (j->flags == flags); + } + + void module:: + save_module (const char* name, int prio) + { + saved_modules.insert (string ("config.") += name, prio); + } + + const string module::name ("config"); + const uint64_t module::version (1); + } +} -- cgit v1.1