aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-09-24 11:00:16 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-09-24 11:00:16 +0200
commitc94f066bbd47520cf52937fc4ad08a699abda28a (patch)
treea0b7f0bcf013377e2e78b96997176b00bc6f45d4
parenta414fa7b0ff469013598ca9ef2999ca6293ee7c1 (diff)
Add ability to ignore extra variables in specified_config()
-rw-r--r--libbuild2/config/utility.cxx28
-rw-r--r--libbuild2/config/utility.hxx14
2 files changed, 33 insertions, 9 deletions
diff --git a/libbuild2/config/utility.cxx b/libbuild2/config/utility.cxx
index 12ec1fe..75c9de9 100644
--- a/libbuild2/config/utility.cxx
+++ b/libbuild2/config/utility.cxx
@@ -76,8 +76,12 @@ namespace build2
}
bool
- specified_config (scope& rs, const string& n)
+ specified_config (scope& rs,
+ const string& n,
+ initializer_list<const char*> ig)
{
+ auto& vp (rs.var_pool ());
+
// Search all outer scopes for any value in this namespace.
//
// What about "pure" overrides, i.e., those without any original values?
@@ -86,19 +90,29 @@ namespace build2
// any original values, they will be "visible"; see find_override() for
// details.
//
- const variable& vns (rs.var_pool ().insert ("config." + n));
+ const variable& ns (vp.insert ("config." + n));
for (scope* s (&rs); s != nullptr; s = s->parent_scope ())
{
- for (auto p (s->vars.lookup_namespace (vns));
+ for (auto p (s->vars.lookup_namespace (ns));
p.first != p.second;
++p.first)
{
- const variable& var (p.first->first);
+ const variable* v (&p.first->first.get ());
+
+ // This can be one of the overrides (__override, __prefix, etc).
+ //
+ if (size_t n = v->override ())
+ v = vp.find (string (v->name, 0, n));
+
+ auto match_tail = [&ns, v] (const char* t)
+ {
+ return v->name.compare (ns.name.size () + 1, string::npos, t) == 0;
+ };
- // Ignore config.*.configured.
+ // Ignore config.*.configured and user-supplied names.
//
- if (var.name.size () < 11 ||
- var.name.compare (var.name.size () - 11, 11, ".configured") != 0)
+ if (!match_tail ("configured") &&
+ find_if (ig.begin (), ig.end (), match_tail) == ig.end ())
return true;
}
}
diff --git a/libbuild2/config/utility.hxx b/libbuild2/config/utility.hxx
index 7d3e18b..0429555 100644
--- a/libbuild2/config/utility.hxx
+++ b/libbuild2/config/utility.hxx
@@ -347,10 +347,20 @@ namespace build2
// Note that this function detects and ignores special config.* variables
// (such as config.*.configured) which may be used by a module to remember
// that it is unconfigured (e.g., in order to avoid re-running the tests,
- // etc; see below).
+ // etc; see below). Additional variables (e.g., unsaved) can be ignored
+ // with the third argument. If specified, it should contain the part(s)
+ // after config.<name>.
//
LIBBUILD2_SYMEXPORT bool
- specified_config (scope& rs, const string& var);
+ specified_config (scope& rs,
+ const string& var,
+ initializer_list<const char*> ignore);
+
+ inline bool
+ specified_config (scope& rs, const string& var)
+ {
+ return specified_config (rs, var, {});
+ }
// Check if there is a false config.*.configured value. This mechanism can
// be used to "remember" that the module is left unconfigured in order to