aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/config/functions.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-05-19 13:10:54 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-05-20 09:16:14 +0200
commit026c827b978761bf0cb618ff9429df8508cd3190 (patch)
treeb7baab17dda08d529ba7d306944342a77f598771 /libbuild2/config/functions.cxx
parent5139b4e0f76076f3fb40b30e99a461fe0947d73e (diff)
Make $config.origin() also available internally as config::origin()
Diffstat (limited to 'libbuild2/config/functions.cxx')
-rw-r--r--libbuild2/config/functions.cxx38
1 files changed, 10 insertions, 28 deletions
diff --git a/libbuild2/config/functions.cxx b/libbuild2/config/functions.cxx
index 3e1b8a3..84c1b03 100644
--- a/libbuild2/config/functions.cxx
+++ b/libbuild2/config/functions.cxx
@@ -23,8 +23,8 @@ namespace build2
// $config.origin()
//
- // Return the origin of the specified configuration variable value.
- // Possible result values and their semantics are as follows:
+ // Return the origin of the value of the specified configuration
+ // variable. Possible result values and their semantics are as follows:
//
// undefined
// The variable is undefined.
@@ -60,33 +60,15 @@ namespace build2
if (s == nullptr)
fail << "config.origin() called out of project" << endf;
- string n (convert<string> (move (name)));
+ switch (origin (*s, convert<string> (move (name))).first)
+ {
+ case variable_origin::undefined: return "undefined";
+ case variable_origin::default_: return "default";
+ case variable_origin::buildfile: return "buildfile";
+ case variable_origin::override_: return "override";
+ }
- // 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)
- fail << "non-config.* variable passed to config.origin()" << endf;
-
- const variable* var (s->ctx.var_pool.find (n));
-
- if (var == nullptr)
- return "undefined";
-
- pair<lookup, size_t> org (s->lookup_original (*var));
- pair<lookup, size_t> ovr (var->overrides == nullptr
- ? org
- : s->lookup_override (*var, org));
-
- if (!ovr.first.defined ())
- return "undefined";
-
- if (org.first != ovr.first)
- return "override";
-
- return org.first->extra ? "default" : "buildfile";
+ return ""; // Should not reach.
};
// $config.save()