From 67db22fcae32c8a8014866ef2ee55b6c7733c3f9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 10 Aug 2021 08:57:59 +0200 Subject: Complete process_libraries() duplicate suppression work --- libbuild2/cc/compile-rule.cxx | 69 ++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 24 deletions(-) (limited to 'libbuild2/cc/compile-rule.cxx') diff --git a/libbuild2/cc/compile-rule.cxx b/libbuild2/cc/compile-rule.cxx index 26ee566..df7be87 100644 --- a/libbuild2/cc/compile-rule.cxx +++ b/libbuild2/cc/compile-rule.cxx @@ -434,14 +434,14 @@ namespace build2 auto opt = [&d, this] (const target& lt, const string& t, bool com, bool exp) { - const file& l (lt.as ()); - // Note that in our model *.export.poptions are always "interface", // even if set on liba{}/libs{}, unlike loptions. // if (!exp) // Ignore libux. return true; + const file& l (lt.as ()); + // Suppress duplicates. // // Compilation is the simple case: we can add the options on the first @@ -519,23 +519,31 @@ namespace build2 // recursively, prerequisite libraries first. // void compile_rule:: - append_library_prefixes (prefix_map& m, + append_library_prefixes (appended_libraries& ls, prefix_map& pm, const scope& bs, - action a, - target& t, - linfo li) const + action a, target& t, linfo li) const { - //@@ TODO: implement duplicate suppression and prunning. Reuse above - // machinery. + struct data + { + appended_libraries& ls; + prefix_map& pm; + } d {ls, pm}; auto imp = [] (const target& l, bool la) {return la && l.is_a ();}; - auto opt = [&m, this] ( - const target& l, const string& t, bool com, bool exp) + auto opt = [&d, this] (const target& lt, + const string& t, bool com, bool exp) { if (!exp) return true; + const file& l (lt.as ()); + + // Suppress duplicates like in append_library_options(). + // + if (find (d.ls.begin (), d.ls.end (), &l) != d.ls.end ()) + return false; + const variable& var ( com ? c_export_poptions @@ -543,7 +551,11 @@ namespace build2 ? x_export_poptions : l.ctx.var_pool[t + ".export.poptions"])); - append_prefixes (m, l, var); + append_prefixes (d.pm, l, var); + + if (com) + d.ls.push_back (&l); + return true; }; @@ -1603,18 +1615,19 @@ namespace build2 target& t, linfo li) const -> prefix_map { - prefix_map m; + prefix_map pm; // First process our own. // - append_prefixes (m, t, x_poptions); - append_prefixes (m, t, c_poptions); + append_prefixes (pm, t, x_poptions); + append_prefixes (pm, t, c_poptions); // Then process the include directories from prerequisite libraries. // - append_library_prefixes (m, bs, a, t, li); + appended_libraries ls; + append_library_prefixes (ls, pm, bs, a, t, li); - return m; + return pm; } // Return the next make prerequisite starting from the specified @@ -6222,17 +6235,16 @@ namespace build2 // auto imp = [] (const target&, bool) { return false; }; - //@@ TODO: implement duplicate suppression and prunning? Reuse above - // machinery (do before is_a() call). - // The same logic as in append_libraries(). // + appended_libraries ls; struct data { - action a; - const file& ht; - const target*& lt; - } d {a, ht, lt}; + action a; + const file& ht; + const target*& lt; + appended_libraries& ls; + } d {a, ht, lt, ls}; auto lib = [&d] ( const target* const* lc, @@ -6250,6 +6262,11 @@ namespace build2 if (l == nullptr) return true; + // Suppress duplicates. + // + if (find (d.ls.begin (), d.ls.end (), l) != d.ls.end ()) + return false; + // Feels like we should only consider non-utility libraries with // utilities being treated as "direct" use. // @@ -6261,9 +6278,13 @@ namespace build2 // const auto& pts (l->prerequisite_targets[d.a]); if (find (pts.begin (), pts.end (), &d.ht) != pts.end ()) + { d.lt = l; + return false; + } - return d.lt == nullptr; + d.ls.push_back (l); + return true; }; library_cache lib_cache; -- cgit v1.1