From aec6628e8c1f0ebdb87767cbf804b01504d82459 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 20 Nov 2024 09:25:50 +0200 Subject: Generalize config::specified_config() --- libbuild2/config/utility.cxx | 40 +++++++++++++++++++++++++--------------- libbuild2/config/utility.hxx | 18 ++++++++++++------ libbuild2/dist/init.cxx | 2 +- libbuild2/install/init.cxx | 2 +- 4 files changed, 39 insertions(+), 23 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 ig) + specified_config (const scope& rs, + const string& ns, + initializer_list 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; + } } } diff --git a/libbuild2/config/utility.hxx b/libbuild2/config/utility.hxx index 3b67c6c..57f253f 100644 --- a/libbuild2/config/utility.hxx +++ b/libbuild2/config/utility.hxx @@ -506,17 +506,23 @@ namespace build2 // that it is unconfigured (e.g., in order to avoid re-running the tests, // 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.. + // after the namespace (config.). + // + // Note that may include several components (separated with `.`). + // And you can request the exact match rather than the prefix. + // + // Note: unlike the above functions, can be called from any phase. // LIBBUILD2_SYMEXPORT bool - specified_config (scope& rs, - const string& var, - initializer_list ignore); + specified_config (const scope& rs, + const string& ns, + initializer_list ignore, + bool exact = false); inline bool - specified_config (scope& rs, const string& var) + specified_config (const scope& rs, const string& ns, bool exact = false) { - return specified_config (rs, var, {}); + return specified_config (rs, ns, {}, exact); } // Check if there is a false config.*.configured value. This mechanism can diff --git a/libbuild2/dist/init.cxx b/libbuild2/dist/init.cxx index 48a3e15..32cbff2 100644 --- a/libbuild2/dist/init.cxx +++ b/libbuild2/dist/init.cxx @@ -132,7 +132,7 @@ namespace build2 // Note: ignore config.dist.bootstrap. // - bool s (specified_config (rs, "dist", {"bootstrap"})); + bool s (specified_config (rs, "config.dist", {"bootstrap"})); // config.dist.root // diff --git a/libbuild2/install/init.cxx b/libbuild2/install/init.cxx index 3df912f..19c57d4 100644 --- a/libbuild2/install/init.cxx +++ b/libbuild2/install/init.cxx @@ -427,7 +427,7 @@ namespace build2 // Note: ignore config.install.{scope,manifest} (see below). // - bool s (specified_config (rs, "install", {"scope", "manifest"})); + bool s (specified_config (rs, "config.install", {"scope", "manifest"})); // Adjust module priority so that the (numerous) config.install.* // values are saved at the end of config.build. -- cgit v1.1