From 026c827b978761bf0cb618ff9429df8508cd3190 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 19 May 2022 13:10:54 +0200 Subject: Make $config.origin() also available internally as config::origin() --- libbuild2/config/functions.cxx | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) (limited to 'libbuild2/config/functions.cxx') 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 (move (name))); + switch (origin (*s, convert (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 org (s->lookup_original (*var)); - pair 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() -- cgit v1.1