From 9ce886d010dee58e5d3e547df84da487fd1c4220 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 7 Jul 2020 08:40:42 +0200 Subject: Skip sources of executables in cc::install_rule Failed that, they may pull headers via an ad hoc group. --- libbuild2/cc/install-rule.cxx | 27 +++++++++++++++++++++++---- libbuild2/target.hxx | 10 +++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/libbuild2/cc/install-rule.cxx b/libbuild2/cc/install-rule.cxx index 17cf4ab..dc10543 100644 --- a/libbuild2/cc/install-rule.cxx +++ b/libbuild2/cc/install-rule.cxx @@ -82,15 +82,26 @@ namespace build2 // Note that if they come from a group, then we assume the entire // group is not to be installed. // + // We also skip sources since they may "pull" a header if they are a + // member of an ad hoc group. + // + auto header_source = [this] (const auto& p) + { + return (x_header (p) || + p.is_a (x_src) || + (x_mod != nullptr && p.is_a (*x_mod))); + }; + if (t.is_a ()) { - if (x_header (p)) + if (header_source (p)) pt = nullptr; else if (p.type.see_through) { for (i.enter_group (); i.group (); ) { - if (x_header (*++i)) + ++i; // Note that we have to iterate until the end of the group. + if (pt != nullptr && header_source (*i)) pt = nullptr; } } @@ -300,15 +311,23 @@ namespace build2 if (pt == nullptr) return pt; + auto header_source = [this] (const auto& p) + { + return (x_header (p) || + p.is_a (x_src) || + (x_mod != nullptr && p.is_a (*x_mod))); + }; + if (t.is_a ()) { - if (x_header (p)) + if (header_source (p)) pt = nullptr; else if (p.type.see_through) { for (i.enter_group (); i.group (); ) { - if (x_header (*++i)) + ++i; + if (pt != nullptr && header_source (*i)) pt = nullptr; } } diff --git a/libbuild2/target.hxx b/libbuild2/target.hxx index a97097f..091b2d8 100644 --- a/libbuild2/target.hxx +++ b/libbuild2/target.hxx @@ -179,7 +179,7 @@ namespace build2 // const target* group = nullptr; - // What has been described above is a "explicit" group. That is, there is + // What has been described above is an "explicit" group. That is, there is // a dedicated target type that explicitly serves as a group and there is // an explicit mechanism for discovering the group's members. // @@ -195,10 +195,10 @@ namespace build2 // would be much easier and more consistent to make these extra files // proper targets. // - // So to support this requirement we have ad hoc groups. The idea is - // that any target can be turned either by a user's declaration in a - // buildfile or by the rule that matches it into an ad hoc group by - // chaining several targets together. + // So to support this requirement we have ad hoc groups. The idea is that + // any target can be turned either by a user's declaration in a buildfile + // or by the rule that matches it into an ad hoc group by chaining several + // targets together. // // Ad hoc groups have a more restricted semantics compared to the normal // groups. In particular: -- cgit v1.1