From 9891b20350021ce41a950645dd76df20a45c92cc Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 2 Dec 2015 11:37:15 +0200 Subject: Implement optional module loading The syntax is: using? cli Now each module use results in two bool variables: .loaded and .configured. Also implement variable visibility (the above two variables are limited to project). --- build/module.cxx | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'build/module.cxx') diff --git a/build/module.cxx b/build/module.cxx index 0f2b1b2..5f1aeff 100644 --- a/build/module.cxx +++ b/build/module.cxx @@ -7,6 +7,7 @@ #include // make_pair() #include +#include #include using namespace std; @@ -15,13 +16,16 @@ namespace build { available_module_map builtin_modules; - void - load_module (const string& name, scope& root, scope& base, const location& l) + bool + load_module (bool opt, + const string& name, + scope& rs, + scope& bs, + const location& loc) { - // First see if this modules has already been loaded for this - // project. + // First see if this modules has already been loaded for this project. // - loaded_module_map& lm (root.modules); + loaded_module_map& lm (rs.modules); auto i (lm.find (name)); bool f (i == lm.end ()); @@ -32,11 +36,26 @@ namespace build auto j (builtin_modules.find (name)); if (j == builtin_modules.end ()) - fail (l) << "unknown module " << name; - - i = lm.emplace (name, make_pair (j->second, nullptr)).first; + { + if (!opt) + fail (loc) << "unknown module " << name; + } + else + i = lm.emplace (name, make_pair (j->second, nullptr)).first; } - i->second.first (root, base, l, i->second.second, f); + bool l (i != lm.end ()); + bool c (l && i->second.first (rs, bs, loc, i->second.second, f, opt)); + + const variable& lv (var_pool.find (name + ".loaded", + variable_visibility::project, + bool_type)); + const variable& cv (var_pool.find (name + ".configured", + variable_visibility::project, + bool_type)); + bs.assign (lv) = l; + bs.assign (cv) = c; + + return l && c; } } -- cgit v1.1