From cbcb0b03501ce346ca3778624dcf908e851e6e2e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 19 Mar 2020 09:27:22 +0200 Subject: Tweak lookup_config() semantics some more --- libbuild2/config/utility.cxx | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'libbuild2/config/utility.cxx') 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 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& ovr (li.lookup); + + if (l.defined () ? l != ovr.first : !li.original) // Overriden? { // Override is always treated as new. // -- cgit v1.1