From 49d5628e35593a5300d39596286c768d7aa435b6 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 7 Jul 2015 09:18:22 +0200 Subject: Rework module architecture Now the target type and rule maps are in scopes (builtins -- in global scope). We also now have the map of loaded modules in the root scope of each project. --- build/bin/module.cxx | 59 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 14 deletions(-) (limited to 'build/bin/module.cxx') diff --git a/build/bin/module.cxx b/build/bin/module.cxx index 3775302..b2374ff 100644 --- a/build/bin/module.cxx +++ b/build/bin/module.cxx @@ -10,39 +10,70 @@ #include +#include +#include + using namespace std; namespace build { namespace bin { + static obj_rule obj_; + static lib_rule lib_; + // Default config.bin.*.lib values. // static const list_value exe_lib (names {name ("shared"), name ("static")}); static const list_value liba_lib ("static"); static const list_value libso_lib ("shared"); - void - init (scope& root, scope& base, const location& l) + extern "C" void + bin_init (scope& root, + scope& base, + const location& l, + std::unique_ptr&, + bool) { - //@@ TODO: avoid multiple inits (generally, for modules). - // tracer trace ("bin::init"); + level4 ([&]{trace << "for " << base.path ();}); + + // Register target types. + // + { + auto& tts (base.target_types); + tts.insert (); + tts.insert (); + tts.insert (); + tts.insert (); + tts.insert (); + tts.insert (); + tts.insert (); + } - //@@ Should it be this way? + // Register rules. // - if (&root != &base) - fail (l) << "bin module must be initialized in project root scope"; + { + auto& rs (base.rules); - //@@ TODO: need to register target types, rules here instead of main(). + rs.insert (default_id, "bin.obj", obj_); + rs.insert (update_id, "bin.obj", obj_); + rs.insert (clean_id, "bin.obj", obj_); - const dir_path& out_root (root.path ()); - level4 ([&]{trace << "for " << out_root;}); + rs.insert (default_id, "bin.lib", lib_); + rs.insert (update_id, "bin.lib", lib_); + rs.insert (clean_id, "bin.lib", lib_); + } // Configure. // using config::required; + // The idea here is as follows: if we already have one of + // the bin.* variables set, then we assume this is static + // project configuration and don't bother setting the + // corresponding config.bin.* variable. + // //@@ Need to validate the values. Would be more efficient // to do it once on assignment than every time on query. // Custom var type? @@ -51,7 +82,7 @@ namespace build // config.bin.lib // { - auto v (root.vars.assign ("bin.lib")); + auto v (base.vars.assign ("bin.lib")); if (!v) v = required (root, "config.bin.lib", "shared").first; } @@ -59,7 +90,7 @@ namespace build // config.bin.exe.lib // { - auto v (root.vars.assign ("bin.exe.lib")); + auto v (base.vars.assign ("bin.exe.lib")); if (!v) v = required (root, "config.bin.exe.lib", exe_lib).first; } @@ -67,7 +98,7 @@ namespace build // config.bin.liba.lib // { - auto v (root.vars.assign ("bin.liba.lib")); + auto v (base.vars.assign ("bin.liba.lib")); if (!v) v = required (root, "config.bin.liba.lib", liba_lib).first; } @@ -75,7 +106,7 @@ namespace build // config.bin.libso.lib // { - auto v (root.vars.assign ("bin.libso.lib")); + auto v (base.vars.assign ("bin.libso.lib")); if (!v) v = required (root, "config.bin.libso.lib", libso_lib).first; } -- cgit v1.1