aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/module.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-01-27 09:07:09 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-01-27 09:07:09 +0200
commit2169f0e960c6e2b94518c03e6eb0406908b96e65 (patch)
tree73cfda5d0c7aa38c74104cca89931045db37892e /libbuild2/module.cxx
parent1abc10223b37d9ead3454a06e176b4b65370a2be (diff)
Improve module loading API
Diffstat (limited to 'libbuild2/module.cxx')
-rw-r--r--libbuild2/module.cxx40
1 files changed, 38 insertions, 2 deletions
diff --git a/libbuild2/module.cxx b/libbuild2/module.cxx
index eec770b..9bc79ab 100644
--- a/libbuild2/module.cxx
+++ b/libbuild2/module.cxx
@@ -526,7 +526,7 @@ namespace build2
rs.assign (rs.ctx.var_pool.rw (rs).insert (mod + ".booted")) = true;
}
- bool
+ module_state*
init_module (scope& rs,
scope& bs,
const string& mod,
@@ -614,6 +614,42 @@ namespace build2
cv = c;
}
- return l && c;
+ return l && c ? &i->second : nullptr;
+ }
+
+ // @@ TODO: This is a bit of a fuzzy mess:
+ //
+ // - The .loaded variable check: it's not clear if init_module()
+ // already has this semantics?
+ //
+ // - Why do we use variable instead of the module map entry? Probably
+ // because of optional. Also entry present if only booted. Need to be
+ // careful here. Also root vs base!
+ //
+ // Note that it would have been nice to keep these inline but we need the
+ // definition of scope for the variable lookup.
+ //
+ bool
+ load_module (scope& rs,
+ scope& bs,
+ const string& name,
+ const location& loc,
+ bool opt,
+ const variable_map& hints)
+ {
+ return cast_false<bool> (bs[name + ".loaded"]) ||
+ init_module (rs, bs, name, loc, opt, hints);
+ }
+
+ unique_ptr<module_base>&
+ load_module (scope& rs,
+ scope& bs,
+ const string& name,
+ const location& loc,
+ const variable_map& hints)
+ {
+ return cast_false<bool> (bs[name + ".loaded"])
+ ? rs.root_extra->modules.find (name)->second.module
+ : init_module (rs, bs, name, loc, false /* optional */, hints)->module;
}
}