aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-02-10 14:26:16 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-02-13 12:42:42 +0200
commitdbd30777d1c60bdcdff226b5f97582dba0bba4ba (patch)
tree30b2beaf482201e11282eb884243f301678305b5
parent92b98aee1eb9f9550634720b96eec0be1831ebb7 (diff)
Allow back overriding variables specified in buildfiles
It is still not clear whether this is the right thing to allow, conceptually, but with this disallowed it's hard to test this functionality. Perhaps we should have an attribute [overridable]. The problem is one will also have to set this variable to some value (e.g., [null]) which is not exactly the same as undefined (especially when testing).
-rw-r--r--build2/context.cxx2
-rw-r--r--build2/parser.cxx17
-rw-r--r--build2/variable.cxx14
3 files changed, 22 insertions, 11 deletions
diff --git a/build2/context.cxx b/build2/context.cxx
index 0357eb6..cbb2656 100644
--- a/build2/context.cxx
+++ b/build2/context.cxx
@@ -179,7 +179,7 @@ namespace build2
c == '%' ? variable_visibility::project :
variable_visibility::normal);
- const variable& var (vp.insert (n));
+ const variable& var (vp.insert (n, true)); // Allow overrides.
const char* k (tt == token_type::assign ? ".__override" :
tt == token_type::append ? ".__suffix" : ".__prefix");
diff --git a/build2/parser.cxx b/build2/parser.cxx
index 2ffd0cf..154c123 100644
--- a/build2/parser.cxx
+++ b/build2/parser.cxx
@@ -458,7 +458,8 @@ namespace build2
const variable& var (
var_pool.rw (*scope_).insert (
- parse_variable_name (move (pns), ploc)));
+ parse_variable_name (move (pns), ploc),
+ true)); // Allow overrides.
// Apply variable attributes.
//
@@ -727,7 +728,8 @@ namespace build2
{
const variable& var (
var_pool.rw (*scope_).insert (
- parse_variable_name (move (ns), nloc)));
+ parse_variable_name (move (ns), nloc),
+ true)); // Allow overrides.
// Apply variable attributes.
//
@@ -1054,7 +1056,7 @@ namespace build2
auto& vp (var_pool.rw (*scope_));
if (p != string::npos)
- var = &vp.insert (split (p));
+ var = &vp.insert (split (p), true); // Allow overrides.
//
// This could still be the 'foo =...' case.
//
@@ -1069,7 +1071,7 @@ namespace build2
(v[p = 0] == '=' ||
(n > 1 && v[0] == '+' && v[p = 1] == '=')))
{
- var = &vp.insert (move (t.value));
+ var = &vp.insert (move (t.value), true); // Allow overrides.
next (t, tt); // Get the peeked token.
split (p); // Returned name should be empty.
}
@@ -1593,7 +1595,10 @@ namespace build2
if (type != nullptr)
{
if (var.type == nullptr)
- var_pool.update (const_cast<variable&> (var), type);
+ {
+ const bool o (true); // Allow overrides.
+ var_pool.update (const_cast<variable&> (var), type, nullptr, &o);
+ }
else if (var.type != type)
fail (l) << "changing variable " << var << " type from "
<< var.type->name << " to " << type->name;
@@ -3502,7 +3507,7 @@ namespace build2
// Lookup.
//
- const auto& var (var_pool.rw (*scope_).insert (move (name)));
+ const auto& var (var_pool.rw (*scope_).insert (move (name), true));
return target_ != nullptr ? (*target_)[var] : (*scope_)[var];
// Undefined/NULL namespace variables are not allowed.
diff --git a/build2/variable.cxx b/build2/variable.cxx
index 78f7c04..48f3345 100644
--- a/build2/variable.cxx
+++ b/build2/variable.cxx
@@ -1003,7 +1003,14 @@ namespace build2
if (o == nullptr)
o = &*p.overridable;
else if (p.match)
- assert (*o == *p.overridable);
+ {
+ // Allow the pattern to restrict but not relax.
+ //
+ if (*o)
+ o = &*p.overridable;
+ else
+ assert (*o == *p.overridable);
+ }
}
}
@@ -1046,9 +1053,8 @@ namespace build2
{
if (t != nullptr || v != nullptr || o != nullptr)
update (r, t, v, o); // Not changing the key.
- else
- if (r.override != nullptr)
- fail << "variable " << r.name << " cannot be overridden";
+ else if (r.override != nullptr)
+ fail << "variable " << r.name << " cannot be overridden";
}
return r;