From ce14007653e22f7cb8906317d80c5968f7b53a95 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 21 Sep 2023 09:33:13 +0200 Subject: Don't install static library prerequisites of executable --- libbuild2/cc/install-rule.cxx | 30 ++++++++++++++++++++++++++++++ libbuild2/cc/install-rule.hxx | 3 ++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/libbuild2/cc/install-rule.cxx b/libbuild2/cc/install-rule.cxx index dae65db..ac4a897 100644 --- a/libbuild2/cc/install-rule.cxx +++ b/libbuild2/cc/install-rule.cxx @@ -38,15 +38,29 @@ namespace build2 // Less obvious: we also want to install a static library prerequisite // of a library (since it could be referenced from its .pc file, etc). // + // This is also the place were we make sure we don't install static + // library prerequisites of an executable (we cannot do it later, where + // we handle headers, because we may need to resolve the member). + // However, there is a nuance: we still have to update such static + // libraries in order to signal that they are being built for install. + // // Note: for now we assume these prerequisites never come from see- // through groups. // // Note: we install ad hoc prerequisites by default. // + if (a.operation () != update_id && t.is_a () && p.is_a ()) + return nullptr; + otype ot (link_type (t).type); + // Note: at least one must be true since we only register this rule for + // exe{}, and lib[as]{} (this makes sure the following if-condition will + // always be true for libx{}). + // bool st (t.is_a () || t.is_a ()); // Target needs shared. bool at (t.is_a () || t.is_a ()); // Target needs static. + assert (st || at); if ((st && (p.is_a () || p.is_a ())) || (at && (p.is_a () || p.is_a ()))) @@ -57,8 +71,14 @@ namespace build2 // link. For libu*{} we want the "see through" logic. // if (const libx* l = pt->is_a ()) + { pt = link_member (*l, a, link_info (t.base_scope (), ot)); + if (a.operation () != update_id && + t.is_a () && pt->is_a ()) + return nullptr; + } + // Note: not redundant since we are returning a member. // if ((st && pt->is_a ()) || (at && pt->is_a ())) @@ -312,10 +332,14 @@ namespace build2 // above. In particular, here we use libue/libua/libus{} as proxies for // exe/liba/libs{} there. // + if (a.operation () != update_id && t.is_a () && p.is_a ()) + return nullptr; + otype ot (link_type (t).type); bool st (t.is_a () || t.is_a ()); // Target needs shared. bool at (t.is_a () || t.is_a ()); // Target needs static. + assert (at || at); if ((st && (p.is_a () || p.is_a ())) || (at && (p.is_a () || p.is_a ()))) @@ -323,8 +347,14 @@ namespace build2 const target* pt (&search (t, p)); if (const libx* l = pt->is_a ()) + { pt = link_member (*l, a, link_info (t.base_scope (), ot)); + if (a.operation () != update_id && + t.is_a () && pt->is_a ()) + return nullptr; + } + if ((st && pt->is_a ()) || (at && pt->is_a ())) return is == nullptr || pt->in (*is) ? pt : nullptr; diff --git a/libbuild2/cc/install-rule.hxx b/libbuild2/cc/install-rule.hxx index 6998d63..5039309 100644 --- a/libbuild2/cc/install-rule.hxx +++ b/libbuild2/cc/install-rule.hxx @@ -24,7 +24,8 @@ namespace build2 // // 1. Signal to the link rule that this is update for install. // - // 2. Custom filtering of prerequisites (e.g., headers of an exe{}). + // 2. Custom filtering of prerequisites (e.g., headers and static + // libraries of an exe{}). // // 3. Extra un/installation (e.g., libs{} symlinks). // -- cgit v1.1