aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/target.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2023-11-21 09:32:50 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2023-11-21 09:32:50 +0200
commit9bb8b63156f6dfb42f9ddab77f253ae0bda02d5a (patch)
tree1e219ff6a32dc3d4d32f5ec68dbe308634aba459 /libbuild2/target.cxx
parent8826a6a6823e8c5957a5b7418e93f0b78be20eef (diff)
Add target::append_locked() variant
Diffstat (limited to 'libbuild2/target.cxx')
-rw-r--r--libbuild2/target.cxx30
1 files changed, 26 insertions, 4 deletions
diff --git a/libbuild2/target.cxx b/libbuild2/target.cxx
index b4c3968..bef7dce 100644
--- a/libbuild2/target.cxx
+++ b/libbuild2/target.cxx
@@ -143,7 +143,8 @@ namespace build2
pair<lookup, size_t> target::
lookup_original (const variable& var,
bool target_only,
- const scope* bs) const
+ const scope* bs,
+ bool locked) const
{
pair<lookup_type, size_t> r (lookup_type (), 0);
@@ -204,9 +205,14 @@ namespace build2
{
if (!target_only)
{
- target_key tk (key ());
- target_key g1k (g1 != nullptr ? g1->key () : target_key {});
- target_key g2k (g2 != nullptr ? g2->key () : target_key {});
+ auto key = [locked] (const target* t)
+ {
+ return locked ? t->key_locked () : t->key ();
+ };
+
+ target_key tk (key (this));
+ target_key g1k (g1 != nullptr ? key (g1) : target_key {});
+ target_key g2k (g2 != nullptr ? key (g2) : target_key {});
if (bs == nullptr)
bs = &base_scope ();
@@ -247,6 +253,22 @@ namespace build2
return r;
}
+ value& target::
+ append_locked (const variable& var)
+ {
+ auto l (lookup_original (var, false, nullptr, true /* locked */).first);
+
+ if (l.defined () && l.belongs (*this)) // Existing var in this target.
+ return vars.modify (l); // Ok since this is original.
+
+ value& r (assign (var)); // NULL.
+
+ if (l.defined ())
+ r = *l; // Copy value (and type) from the outer scope.
+
+ return r;
+ }
+
pair<lookup, size_t> target::opstate::
lookup_original (const variable& var, bool target_only) const
{