From 9bb8b63156f6dfb42f9ddab77f253ae0bda02d5a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 21 Nov 2023 09:32:50 +0200 Subject: Add target::append_locked() variant --- libbuild2/target.cxx | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'libbuild2/target.cxx') 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 target:: lookup_original (const variable& var, bool target_only, - const scope* bs) const + const scope* bs, + bool locked) const { pair 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 target::opstate:: lookup_original (const variable& var, bool target_only) const { -- cgit v1.1