From 83b5af87efef571b707fc1f409f22571a9f5054c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 12 Aug 2016 16:23:37 +0200 Subject: Add support for ordering modules in config.build --- build2/config/module | 18 +++++++++++++++--- build2/config/module.cxx | 22 ++++++++++++++-------- build2/config/operation.cxx | 7 +++---- build2/config/utility | 5 +++++ build2/config/utility.cxx | 10 ++++++++++ 5 files changed, 47 insertions(+), 15 deletions(-) (limited to 'build2/config') diff --git a/build2/config/module b/build2/config/module index 7360cf6..21a7e28 100644 --- a/build2/config/module +++ b/build2/config/module @@ -5,6 +5,7 @@ #ifndef BUILD2_CONFIG_MODULE #define BUILD2_CONFIG_MODULE +#include #include // find_if() #include @@ -49,15 +50,26 @@ namespace build2 struct saved_modules: butl::prefix_map { - vector sequence; + // Priority order with INT32_MIN being the highest. Modules with the + // same priority are saved in the order inserted. + // + // Generally, the idea is that we want higher-level modules at the top + // of the file since that's the configuration that we usualy want to + // change. So we have the following priority bands/defaults: + // + // 101-200/150 - code generators (e.g., yacc, bison) + // 201-300/250 - compilers (e.g., C, C++), + // 301-400/350 - binutils (ar, ld) + // + std::multimap order; iterator - insert (string name) + insert (string name, int prio = 0) { auto p (emplace (move (name), saved_variables ())); if (p.second) - sequence.push_back (p.first); + order.emplace (prio, p.first); return p.first; } diff --git a/build2/config/module.cxx b/build2/config/module.cxx index d4b9b49..de106b7 100644 --- a/build2/config/module.cxx +++ b/build2/config/module.cxx @@ -11,6 +11,7 @@ #include // file_exists() #include +#include #include using namespace std; @@ -23,17 +24,17 @@ namespace build2 const string module::name ("config"); void - boot (scope& root, const location&, unique_ptr&) + boot (scope& rs, const location&, unique_ptr&) { tracer trace ("config::boot"); - const dir_path& out_root (root.out_path ()); + const dir_path& out_root (rs.out_path ()); l5 ([&]{trace << "for " << out_root;}); // Register meta-operations. // - root.meta_operations.insert (configure_id, configure); - root.meta_operations.insert (disfigure_id, disfigure); + rs.meta_operations.insert (configure_id, configure); + rs.meta_operations.insert (disfigure_id, disfigure); // Load config.build if one exists. // @@ -45,11 +46,11 @@ namespace build2 path f (out_root / config_file); if (file_exists (f)) - source (f, root, root); + source (f, rs, rs); } bool - init (scope& root, + init (scope& rs, scope&, const location& l, unique_ptr& mod, @@ -65,7 +66,7 @@ namespace build2 return true; } - l5 ([&]{trace << "for " << root.out_path ();}); + l5 ([&]{trace << "for " << rs.out_path ();}); assert (config_hints.empty ()); // We don't known any hints. @@ -74,6 +75,11 @@ namespace build2 if (current_mif->id == configure_id) mod.reset (new module); + // Adjust priority for the import pseudo-module so that config.import.* + // values come first in config.build. + // + config::save_module (rs, "import", INT32_MIN); + // Register alias and fallback rule for the configure meta-operation. // { @@ -83,7 +89,7 @@ namespace build2 global_scope->rules.insert ( configure_id, 0, "config.file", file_rule::instance); - auto& r (root.rules); + auto& r (rs.rules); r.insert (configure_id, 0, "config", fallback_rule::instance); r.insert (configure_id, 0, "config.file", fallback_rule::instance); diff --git a/build2/config/operation.cxx b/build2/config/operation.cxx index 89ddcfb..ca2d559 100644 --- a/build2/config/operation.cxx +++ b/build2/config/operation.cxx @@ -93,11 +93,10 @@ namespace build2 // names storage; - for (const saved_modules::const_iterator& i: - mod.saved_modules.sequence) + for (auto p: mod.saved_modules.order) { - const string& sname (i->first); - const saved_variables& svars (i->second); + const string& sname (p.second->first); + const saved_variables& svars (p.second->second); bool first (true); // Separate modules with a blank line. for (const saved_variable& sv: svars) diff --git a/build2/config/utility b/build2/config/utility index 2be2842..d11a38b 100644 --- a/build2/config/utility +++ b/build2/config/utility @@ -132,6 +132,11 @@ namespace build2 void save_variable (scope& root, const variable&, uint64_t flags = 0); + + // Establish module order/priority. See config::module for details. + // + void + save_module (scope& root, const char* name, int prio = 0); } } diff --git a/build2/config/utility.cxx b/build2/config/utility.cxx index b73e852..45417f1 100644 --- a/build2/config/utility.cxx +++ b/build2/config/utility.cxx @@ -170,5 +170,15 @@ namespace build2 assert (j->flags == flags); } } + + void + save_module (scope& r, const char* name, int prio) + { + if (current_mif->id != configure_id) + return; + + if (module* m = r.modules.lookup (module::name)) + m->saved_modules.insert (string ("config.") += name, prio); + } } } -- cgit v1.1