aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/config/utility.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2/config/utility.cxx')
-rw-r--r--libbuild2/config/utility.cxx61
1 files changed, 57 insertions, 4 deletions
diff --git a/libbuild2/config/utility.cxx b/libbuild2/config/utility.cxx
index a78b263..6574367 100644
--- a/libbuild2/config/utility.cxx
+++ b/libbuild2/config/utility.cxx
@@ -32,7 +32,7 @@ namespace build2
// Treat an inherited value that was set to default as new.
//
- if (l.defined () && l->extra)
+ if (l.defined () && l->extra == 1)
n = true;
if (var.overrides != nullptr)
@@ -81,7 +81,9 @@ namespace build2
const string& n,
initializer_list<const char*> ig)
{
- auto& vp (rs.var_pool ());
+ // Note: go straight for the public variable pool.
+ //
+ auto& vp (rs.ctx.var_pool);
// Search all outer scopes for any value in this namespace.
//
@@ -128,7 +130,7 @@ namespace build2
// Pattern-typed as bool.
//
const variable& var (
- rs.var_pool ().insert ("config." + n + ".configured"));
+ rs.var_pool (true).insert ("config." + n + ".configured"));
save_variable (rs, var);
@@ -142,7 +144,7 @@ namespace build2
// Pattern-typed as bool.
//
const variable& var (
- rs.var_pool ().insert ("config." + n + ".configured"));
+ rs.var_pool (true).insert ("config." + n + ".configured"));
save_variable (rs, var);
@@ -156,5 +158,56 @@ namespace build2
else
return false;
}
+
+ pair<variable_origin, lookup>
+ origin (const scope& rs, const string& n)
+ {
+ // Note: go straight for the public variable pool.
+ //
+ 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
+ // rely 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 (var.name.compare (0, 7, "config.") != 0)
+ throw invalid_argument ("config.* variable expected");
+
+ return origin (rs, var, rs.lookup_original (var));
+ }
+
+ pair<variable_origin, lookup>
+ origin (const scope& rs, const variable& var, pair<lookup, size_t> org)
+ {
+ 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 == 1
+ ? variable_origin::default_
+ : variable_origin::buildfile,
+ org.first);
+ }
}
}