diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2022-05-19 13:10:54 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2022-05-20 09:16:14 +0200 |
commit | 026c827b978761bf0cb618ff9429df8508cd3190 (patch) | |
tree | b7baab17dda08d529ba7d306944342a77f598771 /libbuild2/config/utility.cxx | |
parent | 5139b4e0f76076f3fb40b30e99a461fe0947d73e (diff) |
Make $config.origin() also available internally as config::origin()
Diffstat (limited to 'libbuild2/config/utility.cxx')
-rw-r--r-- | libbuild2/config/utility.cxx | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/libbuild2/config/utility.cxx b/libbuild2/config/utility.cxx index a78b263..7437c5b 100644 --- a/libbuild2/config/utility.cxx +++ b/libbuild2/config/utility.cxx @@ -156,5 +156,38 @@ namespace build2 else return false; } + + pair<variable_origin, lookup> + origin (const scope& rs, const string& n) + { + // 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) + 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 + ? org + : rs.lookup_override (*var, org)); + + if (!ovr.first.defined ()) + return make_pair (variable_origin::undefined, lookup ()); + + if (org.first != ovr.first) + return make_pair (variable_origin::override_, ovr.first); + + return make_pair (org.first->extra + ? variable_origin::default_ + : variable_origin::buildfile, + org.first); + } } } |