diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2021-08-12 09:27:24 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2021-08-12 09:27:24 +0200 |
commit | 7382e4bf15d11b9200d6220b2a89e1f82b220c5e (patch) | |
tree | 1d3614f58ed7fe5e2154fa9ea189b7bd01557352 /libbuild2/cc/link-rule.hxx | |
parent | 037e5e9224648fdc9f3956d612fb476966847f5c (diff) |
Avoid duplication in Libs/Libs.private in generated .pc files
Diffstat (limited to 'libbuild2/cc/link-rule.hxx')
-rw-r--r-- | libbuild2/cc/link-rule.hxx | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/libbuild2/cc/link-rule.hxx b/libbuild2/cc/link-rule.hxx index 23f7167..3d801d6 100644 --- a/libbuild2/cc/link-rule.hxx +++ b/libbuild2/cc/link-rule.hxx @@ -81,11 +81,10 @@ namespace build2 class appended_libraries: public small_vector<appended_library, 128> { public: - // Find existing or append new entry. If appending new, use the second - // argument as the begin value. + // Find existing entry, if any. // - appended_library& - append (const file& l, size_t b) + appended_library* + find (const file& l) { auto i (find_if (begin (), end (), [&l] (const appended_library& al) @@ -93,19 +92,11 @@ namespace build2 return al.l2 == nullptr && al.l1 == &l; })); - if (i != end ()) - return *i; - - push_back (appended_library {&l, nullptr, b, appended_library::npos}); - return back (); + return i != end () ? &*i : nullptr; } - // Return NULL if no duplicate tracking can be performed for this - // library. - // appended_library* - append (const small_vector<reference_wrapper<const string>, 2>& ns, - size_t b) + find (const small_vector<reference_wrapper<const string>, 2>& ns) { size_t n (ns.size ()); @@ -125,8 +116,36 @@ namespace build2 : al.l1 == nullptr); })); - if (i != end ()) - return &*i; + return i != end () ? &*i : nullptr; + } + + // Find existing or append new entry. If appending new, use the second + // argument as the begin value. + // + appended_library& + append (const file& l, size_t b) + { + if (appended_library* r = find (l)) + return *r; + + push_back (appended_library {&l, nullptr, b, appended_library::npos}); + return back (); + } + + // Return NULL if no duplicate tracking can be performed for this + // library. + // + appended_library* + append (const small_vector<reference_wrapper<const string>, 2>& ns, + size_t b) + { + size_t n (ns.size ()); + + if (n > 2) + return nullptr; + + if (appended_library* r = find (ns)) + return r; push_back (appended_library { n == 2 ? &ns[1].get () : nullptr, &ns[0].get (), |