aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/config/utility.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-03-19 09:27:22 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-03-19 09:27:22 +0200
commitcbcb0b03501ce346ca3778624dcf908e851e6e2e (patch)
treeec7cf219ea6772ed5ea03de35eefd5e781d7906a /libbuild2/config/utility.cxx
parent14b34a239fa23e1a28519ab87f450c0a440d4f85 (diff)
Tweak lookup_config() semantics some more
Diffstat (limited to 'libbuild2/config/utility.cxx')
-rw-r--r--libbuild2/config/utility.cxx28
1 files changed, 25 insertions, 3 deletions
diff --git a/libbuild2/config/utility.cxx b/libbuild2/config/utility.cxx
index cf0f73b..b3f94be 100644
--- a/libbuild2/config/utility.cxx
+++ b/libbuild2/config/utility.cxx
@@ -33,9 +33,31 @@ namespace build2
if (var.overrides != nullptr)
{
- pair<lookup, size_t> ovr (rs.lookup_override (var, move (org)));
-
- if (l != ovr.first) // Overriden?
+ // This is tricky: if we didn't find the original, pretend we have set
+ // the default value for the purpose of override lookup in order to
+ // have consistent semantics with the default value case (see notes in
+ // that implementation for background).
+ //
+ // In particular, this makes sure we can first do the lookup without
+ // the default value and then, if there is no value, call the version
+ // with the default value and end up with the same result if we called
+ // the default value version straight away.
+ //
+ // Note that we need to detect both when the default value is not
+ // overridden as well as when the override is based on it (e.g., via
+ // append; think config.cxx+=-m32).
+ //
+ // @@ Maybe a callback that computes the default value on demand is a
+ // better way?
+ //
+ variable_map::value_data v; // NULL value, but must be with version.
+ if (!l.defined ())
+ org = make_pair (lookup (v, var, rs), 1); // As default value case.
+
+ scope::override_info li (rs.lookup_override_info (var, move (org)));
+ pair<lookup, size_t>& ovr (li.lookup);
+
+ if (l.defined () ? l != ovr.first : !li.original) // Overriden?
{
// Override is always treated as new.
//