From b39ce46b80ef5cccc592398e0a74ba8d02742ead Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 4 Nov 2019 13:34:52 +0200 Subject: Add $config.export() function This is similar to the config.export variable functionality except it can be called from within buildfiles. Note that this function can only be used during configure unless the config module creation was forced for other meta-operations with config.module=true in bootstrap.build. --- libbuild2/config/utility.cxx | 48 +++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 30 deletions(-) (limited to 'libbuild2/config/utility.cxx') diff --git a/libbuild2/config/utility.cxx b/libbuild2/config/utility.cxx index 355e896..8a99a8b 100644 --- a/libbuild2/config/utility.cxx +++ b/libbuild2/config/utility.cxx @@ -18,12 +18,12 @@ namespace build2 namespace config { pair - omitted (scope& r, const variable& var) + omitted (scope& rs, const variable& var) { // This is a stripped-down version of the required() twisted // implementation. - pair org (r.find_original (var)); + pair org (rs.find_original (var)); bool n (false); // New flag. lookup l (org.first); @@ -35,7 +35,7 @@ namespace build2 if (var.overrides != nullptr) { - pair ovr (r.find_override (var, move (org))); + pair ovr (rs.find_override (var, move (org))); if (l != ovr.first) // Overriden? { @@ -46,26 +46,25 @@ namespace build2 } } - if (l.defined () && r.ctx.current_mif->id == configure_id) - save_variable (r, var); + if (l.defined ()) + save_variable (rs, var); return pair (l, n); } lookup - optional (scope& r, const variable& var) + optional (scope& rs, const variable& var) { - if (r.ctx.current_mif->id == configure_id) - save_variable (r, var); + save_variable (rs, var); - auto l (r[var]); + auto l (rs[var]); return l.defined () ? l - : lookup (r.assign (var), var, r); // NULL. + : lookup (rs.assign (var), var, rs); // NULL. } bool - specified (scope& r, const string& n) + specified (scope& rs, const string& n) { // Search all outer scopes for any value in this namespace. // @@ -75,8 +74,8 @@ namespace build2 // any original values, they will be "visible"; see find_override() for // details. // - const variable& vns (r.ctx.var_pool.rw (r).insert ("config." + n)); - for (scope* s (&r); s != nullptr; s = s->parent_scope ()) + const variable& vns (rs.ctx.var_pool.rw (rs).insert ("config." + n)); + for (scope* s (&rs); s != nullptr; s = s->parent_scope ()) { for (auto p (s->vars.find_namespace (vns)); p.first != p.second; @@ -103,8 +102,7 @@ namespace build2 const variable& var ( rs.ctx.var_pool.rw (rs).insert ("config." + n + ".configured")); - if (rs.ctx.current_mif->id == configure_id) - save_variable (rs, var); + save_variable (rs, var); auto l (rs[var]); // Include inherited values. return l && !cast (l); @@ -118,8 +116,7 @@ namespace build2 const variable& var ( rs.ctx.var_pool.rw (rs).insert ("config." + n + ".configured")); - if (rs.ctx.current_mif->id == configure_id) - save_variable (rs, var); + save_variable (rs, var); value& x (rs.assign (var)); @@ -133,25 +130,16 @@ namespace build2 } void - save_variable (scope& r, const variable& var, uint64_t flags) + save_variable (scope& rs, const variable& var, uint64_t flags) { - if (r.ctx.current_mif->id != configure_id) - return; - - // The project might not be using the config module. But then how - // could we be configuring it? Good question. - // - if (module* m = r.lookup_module (module::name)) + if (module* m = rs.lookup_module (module::name)) m->save_variable (var, flags); } void - save_module (scope& r, const char* name, int prio) + save_module (scope& rs, const char* name, int prio) { - if (r.ctx.current_mif->id != configure_id) - return; - - if (module* m = r.lookup_module (module::name)) + if (module* m = rs.lookup_module (module::name)) m->save_module (name, prio); } -- cgit v1.1