From 6d58efb0a5ca051bb205812edd130573bf3c39ce Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 4 Dec 2017 11:23:44 +0200 Subject: Suppress duplicate module init() calls for same scope --- build2/module.cxx | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) (limited to 'build2/module.cxx') diff --git a/build2/module.cxx b/build2/module.cxx index f1e7dd3..7a35008 100644 --- a/build2/module.cxx +++ b/build2/module.cxx @@ -96,17 +96,47 @@ namespace build2 } } - bool l (i != lm.end ()); - bool c (l && - i->second.init (rs, bs, loc, i->second.module, f, opt, hints)); - - auto& vp (var_pool.rw (rs)); - // Note: pattern-typed in context.cxx:reset() as project-visibility // variables of type bool. // - bs.assign (vp.insert (name + ".loaded")) = l; - bs.assign (vp.insert (name + ".configured")) = c; + auto& vp (var_pool.rw (rs)); + value& lv (bs.assign (vp.insert (name + ".loaded"))); + value& cv (bs.assign (vp.insert (name + ".configured"))); + + bool l; // Loaded. + bool c; // Configured. + + // Suppress duplicate init() calls for the same module in the same scope. + // + if (!lv.null) + { + assert (!cv.null); + + l = cast (lv); + c = cast (cv); + + if (!opt) + { + if (!l) + fail (loc) << "unknown module " << name; + + // We don't have original diagnostics. We could call init() again so + // that it can issue it. But that means optional modules must be + // prepared to be called again if configuring failed. Let's keep it + // simple for now. + // + if (!c) + fail (loc) << "module " << name << " failed to configure"; + } + } + else + { + l = i != lm.end (); + c = l && i->second.init (rs, bs, loc, i->second.module, f, opt, hints); + + lv = l; + cv = c; + } return l && c; } -- cgit v1.1