From 2169f0e960c6e2b94518c03e6eb0406908b96e65 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 27 Jan 2020 09:07:09 +0200 Subject: Improve module loading API --- libbuild2/module.cxx | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'libbuild2/module.cxx') 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 (bs[name + ".loaded"]) || + init_module (rs, bs, name, loc, opt, hints); + } + + unique_ptr& + load_module (scope& rs, + scope& bs, + const string& name, + const location& loc, + const variable_map& hints) + { + return cast_false (bs[name + ".loaded"]) + ? rs.root_extra->modules.find (name)->second.module + : init_module (rs, bs, name, loc, false /* optional */, hints)->module; } } -- cgit v1.1