aboutsummaryrefslogtreecommitdiff
path: root/build/module.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-12-02 11:37:15 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-12-02 11:37:15 +0200
commit9891b20350021ce41a950645dd76df20a45c92cc (patch)
tree0cd27041b0c3413e17b9319ae99e87c5e745b1ff /build/module.cxx
parent74212589a797ca75e55f92a522e198915c0dbaf6 (diff)
Implement optional module loading
The syntax is: using? cli Now each module use results in two bool variables: <module>.loaded and <module>.configured. Also implement variable visibility (the above two variables are limited to project).
Diffstat (limited to 'build/module.cxx')
-rw-r--r--build/module.cxx37
1 files changed, 28 insertions, 9 deletions
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 <utility> // make_pair()
#include <build/scope>
+#include <build/variable>
#include <build/diagnostics>
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;
}
}