diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2024-01-16 08:07:04 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2024-01-16 08:11:03 +0200 |
commit | 3925bdc7708abd4387a5ffb0db60bc57098f2669 (patch) | |
tree | 4357758974e7768308f155c4d30f9ae23e0345b2 /libbuild2/algorithm.cxx | |
parent | 56cc47e7e5dd3aa15e1023db5525bdc6a5486c1f (diff) |
Add add_adhoc_member_identity(), use to fix ad hoc pattern rule logic
Diffstat (limited to 'libbuild2/algorithm.cxx')
-rw-r--r-- | libbuild2/algorithm.cxx | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/libbuild2/algorithm.cxx b/libbuild2/algorithm.cxx index df8e650..2abf391 100644 --- a/libbuild2/algorithm.cxx +++ b/libbuild2/algorithm.cxx @@ -400,6 +400,49 @@ namespace build2 return *m; }; + pair<target&, bool> + add_adhoc_member_identity (target& t, + const target_type& tt, + dir_path dir, + dir_path out, + string n, + optional<string> ext, + const location& loc) + { + // NOTE: see similar code in parser::enter_adhoc_members(). + + tracer trace ("add_adhoc_member_identity"); + + pair<target&, ulock> r ( + t.ctx.targets.insert_locked (tt, + move (dir), + move (out), + move (n), + move (ext), + target_decl::implied, + trace, + true /* skip_find */)); + target& m (r.first); + + // Add as an ad hoc member at the end of the chain skipping duplicates. + // + const_ptr<target>* mp (&t.adhoc_member); + for (; *mp != nullptr; mp = &(*mp)->adhoc_member) + { + if (*mp == &m) + return {m, false}; + } + + if (!r.second) + fail (loc) << "target " << m << " already exists and cannot be made " + << "ad hoc member of group " << t; + + m.group = &t; + *mp = &m; + + return {m, true}; + } + static bool trace_target (const target& t, const vector<name>& ns) { |