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/cxx/module | 4 +-- build/cxx/module.cxx | 91 +++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 74 insertions(+), 21 deletions(-) (limited to 'build/cxx') diff --git a/build/cxx/module b/build/cxx/module index 2d50f59..dcadcdd 100644 --- a/build/cxx/module +++ b/build/cxx/module @@ -12,8 +12,8 @@ namespace build { namespace cxx { - void - init (scope&, scope&, const location&); + extern "C" void + cxx_init (scope&, scope&, const location&, std::unique_ptr&, bool); } } diff --git a/build/cxx/module.cxx b/build/cxx/module.cxx index 7e6a211..ce7c968 100644 --- a/build/cxx/module.cxx +++ b/build/cxx/module.cxx @@ -10,10 +10,13 @@ #include #include -#include - #include +#include + +#include +#include + using namespace std; using namespace butl; @@ -21,33 +24,73 @@ namespace build { namespace cxx { - void - init (scope& root, scope& base, const location& l) + compile compile_; + link link_; + + extern "C" void + cxx_init (scope& root, + scope& base, + const location& l, + std::unique_ptr&, + bool first) { - //@@ TODO: avoid multiple inits (generally, for modules). - // - tracer trace ("cxx::init"); + level4 ([&]{trace << "for " << base.path ();}); - //@@ Should it be this way? + // Initialize the bin module. Only do this if it hasn't already + // been loaded so that we don't overwrite user's bin.* settings. // - if (&root != &base) - fail (l) << "cxx module must be initialized in project root scope"; + if (base.find_target_type ("obj") == nullptr) + load_module ("bin", root, base, l); - // Initialize the bin module. + // Register target types. // - bin::init (root, base, l); + { + auto& tts (base.target_types); + + tts.insert (); + tts.insert (); - //@@ TODO: need to register target types, rules here instead of main(). + tts.insert (); + tts.insert (); + tts.insert (); + tts.insert (); + } - const dir_path& out_root (root.path ()); - level4 ([&]{trace << "for " << out_root;}); + // Register rules. + // + { + using namespace bin; + + auto& rs (base.rules); + + rs.insert (default_id, "cxx.compile", compile_); + rs.insert (update_id, "cxx.compile", compile_); + rs.insert (clean_id, "cxx.compile", compile_); + + rs.insert (default_id, "cxx.compile", compile_); + rs.insert (update_id, "cxx.compile", compile_); + rs.insert (clean_id, "cxx.compile", compile_); + + rs.insert (default_id, "cxx.link", link_); + rs.insert (update_id, "cxx.link", link_); + rs.insert (clean_id, "cxx.link", link_); + + rs.insert (default_id, "cxx.link", link_); + rs.insert (update_id, "cxx.link", link_); + rs.insert (clean_id, "cxx.link", link_); + + rs.insert (default_id, "cxx.link", link_); + rs.insert (update_id, "cxx.link", link_); + rs.insert (clean_id, "cxx.link", link_); + } // Configure. // // config.cxx // + if (first) { auto r (config::required (root, "config.cxx", "g++")); @@ -98,17 +141,27 @@ namespace build // These are optional. We also merge them into the corresponding // cxx.* variables. // + // The merging part gets a bit tricky if this module has already + // been loaded in one of the outer scopes. By doing the straight + // append we would just be repeating the same options over and + // over. So what we are going to do is only append to a value if + // it came from this scope. Then the usage for merging becomes: + // + // cxx.coptions = # Note: '='. + // using cxx + // cxx.coptions += # Note: '+='. + // if (auto* v = config::optional (root, "config.cxx.poptions")) - root.append ("cxx.poptions") += *v; + base.assign ("cxx.poptions") += *v; if (auto* v = config::optional (root, "config.cxx.coptions")) - root.append ("cxx.coptions") += *v; + base.assign ("cxx.coptions") += *v; if (auto* v = config::optional (root, "config.cxx.loptions")) - root.append ("cxx.loptions") += *v; + base.assign ("cxx.loptions") += *v; if (auto* v = config::optional (root, "config.cxx.libs")) - root.append ("cxx.libs") += *v; + base.assign ("cxx.libs") += *v; } } } -- cgit v1.1