aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-03-18 08:22:03 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-03-18 08:22:03 +0200
commitee36f1d58484479a2fa3547fad1eb1cc34c51c3e (patch)
treebfb0077f9a0b16748e422153addc3cf4fd0bece8
parent65be7de7aca4bdac05e0acf68ec86a351e779839 (diff)
Fix variable pattern merging logic
-rw-r--r--libbuild2/variable.cxx43
1 files changed, 31 insertions, 12 deletions
diff --git a/libbuild2/variable.cxx b/libbuild2/variable.cxx
index 7b55357..f1c5515 100644
--- a/libbuild2/variable.cxx
+++ b/libbuild2/variable.cxx
@@ -1249,6 +1249,9 @@ namespace build2
// Apply pattern.
//
+ const pattern* pa (nullptr);
+ auto pt (t); auto pv (v); auto po (o);
+
if (pat)
{
if (n.find ('.') != string::npos)
@@ -1259,35 +1262,51 @@ namespace build2
{
if (match_pattern (n, p.prefix, p.suffix, p.multi))
{
- merge_pattern (p, t, v, o);
+ merge_pattern (p, pt, pv, po);
+ pa = &p;
break;
}
}
}
}
- auto p (
+ auto r (
insert (
variable {
move (n),
nullptr,
- t,
+ pt,
nullptr,
- v != nullptr ? *v : variable_visibility::normal}));
+ pv != nullptr ? *pv : variable_visibility::normal}));
- variable& r (p.first->second);
+ variable& var (r.first->second);
- if (p.second)
- r.aliases = &r;
+ if (r.second)
+ var.aliases = &var;
else // Note: overridden variable will always exist.
{
- if (t != nullptr || v != nullptr || o != nullptr)
- update (r, t, v, o); // Not changing the key.
- else if (r.overrides != nullptr)
- fail << "variable " << r.name << " cannot be overridden";
+ if (pt != nullptr || pv != nullptr || po != nullptr)
+ {
+ // This is tricky: if the pattern does not require a match, then we
+ // should re-merge it with values that came from the variable.
+ //
+ bool vo;
+ if (pa != nullptr && !pa->match)
+ {
+ pt = t != nullptr ? t : var.type;
+ pv = v != nullptr ? v : &var.visibility;
+ po = o != nullptr ? o : &(vo = (var.overrides != nullptr));
+
+ merge_pattern (*pa, pt, pv, po);
+ }
+
+ update (var, pt, pv, po); // Not changing the key.
+ }
+ else if (var.overrides != nullptr)
+ fail << "variable " << var << " cannot be overridden";
}
- return r;
+ return var;
}
const variable& variable_pool::