diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2024-11-20 09:25:50 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2024-11-20 09:25:50 +0200 |
commit | aec6628e8c1f0ebdb87767cbf804b01504d82459 (patch) | |
tree | 5d761b889e7c3ae9043112f777142612b14fd4b2 /libbuild2/config/utility.cxx | |
parent | bbf670d03ee587b0794f77a39db801bad6459ca5 (diff) |
Generalize config::specified_config()
Diffstat (limited to 'libbuild2/config/utility.cxx')
-rw-r--r-- | libbuild2/config/utility.cxx | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/libbuild2/config/utility.cxx b/libbuild2/config/utility.cxx index aa0d5af..35ff3ff 100644 --- a/libbuild2/config/utility.cxx +++ b/libbuild2/config/utility.cxx @@ -87,10 +87,13 @@ namespace build2 } bool - specified_config (scope& rs, - const string& n, - initializer_list<const char*> ig) + specified_config (const scope& rs, + const string& ns, + initializer_list<const char*> ig, + bool exact) { + assert (!exact || ig.size () == 0); + // Note: go straight for the public variable pool. // auto& vp (rs.ctx.var_pool); @@ -103,8 +106,7 @@ namespace build2 // any original values, they will be "visible"; see find_override() for // details. // - const string ns ("config." + n); - for (scope* s (&rs); s != nullptr; s = s->parent_scope ()) + for (const scope* s (&rs); s != nullptr; s = s->parent_scope ()) { for (auto p (s->vars.lookup_namespace (ns)); p.first != p.second; @@ -117,17 +119,25 @@ namespace build2 if (size_t n = v->override ()) v = vp.find (string (v->name, 0, n)); - auto match_tail = [&ns, v] (const char* t) + if (exact) { - return v->name.compare (ns.size () + 1, string::npos, t) == 0; - }; - - // Ignore config.*.configured and user-supplied names. - // - if (v->name.size () <= ns.size () || - (!match_tail ("configured") && - find_if (ig.begin (), ig.end (), match_tail) == ig.end ())) - return true; + if (v->name.size () == ns.size ()) + return true; + } + else + { + auto match_tail = [&ns, v] (const char* t) + { + return v->name.compare (ns.size () + 1, string::npos, t) == 0; + }; + + // Ignore config.*.configured and user-supplied names. + // + if (v->name.size () <= ns.size () || // @@ Hm, when can it be < ? + (!match_tail ("configured") && + find_if (ig.begin (), ig.end (), match_tail) == ig.end ())) + return true; + } } } |