diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2022-05-23 13:09:51 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2022-05-23 13:09:51 +0200 |
commit | b7f6c386e0396bd242d0ec42f820db4ea0f6760b (patch) | |
tree | 873b7deac298b64e7cd41b975adf57cc97075e72 /libbuild2/config | |
parent | 0347acdf4c96c2d78d173c84adae99187887be62 (diff) |
Add config::origin(const variable&) overload
Diffstat (limited to 'libbuild2/config')
-rw-r--r-- | libbuild2/config/utility.cxx | 29 | ||||
-rw-r--r-- | libbuild2/config/utility.hxx | 3 |
2 files changed, 23 insertions, 9 deletions
diff --git a/libbuild2/config/utility.cxx b/libbuild2/config/utility.cxx index 7437c5b..243c03a 100644 --- a/libbuild2/config/utility.cxx +++ b/libbuild2/config/utility.cxx @@ -160,23 +160,34 @@ namespace build2 pair<variable_origin, lookup> origin (const scope& rs, const string& n) { + const variable* var (rs.ctx.var_pool.find (n)); + + if (var == nullptr) + { + if (n.compare (0, 7, "config.") != 0) + throw invalid_argument ("config.* variable expected"); + + return make_pair (variable_origin::undefined, lookup ()); + } + + return origin (rs, *var); + } + + pair<variable_origin, lookup> + origin (const scope& rs, const variable& var) + { // Make sure this is a config.* variable. This could matter since we // reply on the semantics of value::extra. We could also detect // special variables like config.booted, some config.config.*, etc., // (see config_save() for details) but that seems harmless. // - if (n.compare (0, 7, "config.") != 0) + if (var.name.compare (0, 7, "config.") != 0) throw invalid_argument ("config.* variable expected"); - const variable* var (rs.ctx.var_pool.find (n)); - - if (var == nullptr) - return make_pair (variable_origin::undefined, lookup ()); - - pair<lookup, size_t> org (rs.lookup_original (*var)); - pair<lookup, size_t> ovr (var->overrides == nullptr + pair<lookup, size_t> org (rs.lookup_original (var)); + pair<lookup, size_t> ovr (var.overrides == nullptr ? org - : rs.lookup_override (*var, org)); + : rs.lookup_override (var, org)); if (!ovr.first.defined ()) return make_pair (variable_origin::undefined, lookup ()); diff --git a/libbuild2/config/utility.hxx b/libbuild2/config/utility.hxx index 5a00d00..050339a 100644 --- a/libbuild2/config/utility.hxx +++ b/libbuild2/config/utility.hxx @@ -517,6 +517,9 @@ namespace build2 LIBBUILD2_SYMEXPORT pair<variable_origin, lookup> origin (const scope& rs, const string& name); + + LIBBUILD2_SYMEXPORT pair<variable_origin, lookup> + origin (const scope& rs, const variable&); } } |