From 3cc5e3bd441fc9d18fece3d9e99fae75c78438e7 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 28 Jun 2018 09:44:15 +0200 Subject: Implement support for excluded and ad hoc prerequisites The inclusion/exclusion is controlled via the 'include' prerequisite-specific variable. Valid values are: false - exclude true - include adhoc - include but treat as an ad hoc input For example: lib{foo}: cxx{win32-utility}: include = ($cxx.targe.class == 'windows') exe{bar}: libs{plugin}: include = adhoc --- build2/cli/rule.cxx | 77 +++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 41 deletions(-) (limited to 'build2/cli') diff --git a/build2/cli/rule.cxx b/build2/cli/rule.cxx index f621f02..45b8185 100644 --- a/build2/cli/rule.cxx +++ b/build2/cli/rule.cxx @@ -44,41 +44,48 @@ namespace build2 } bool compile_rule:: - match (action a, target& xt, const string&) const + match (action a, target& t, const string&) const { tracer trace ("cli::compile_rule::match"); - if (cli_cxx* pt = xt.is_a ()) + // Find the .cli source file. + // + auto find = [&trace, a, &t] (auto&& r) -> optional { - // The cli.cxx{} group. - // - cli_cxx& t (*pt); - - // See if we have a .cli source file. - // - bool r (false); - for (prerequisite_member p: group_prerequisite_members (a, t)) + for (prerequisite_member p: r) { + // If excluded or ad hoc, then don't factor it into our tests. + // + if (include (a, t, p) != include_type::normal) + continue; + if (p.is_a ()) { // Check that the stem match. // - if (!match_stem (t.name, p.name ())) - { - l4 ([&]{trace << ".cli file stem '" << p.name () << "' " - << "doesn't match target " << t;}); - return false; - } - - r = true; - break; + if (match_stem (t.name, p.name ())) + return p; + + l4 ([&]{trace << ".cli file stem '" << p.name () << "' " + << "doesn't match target " << t;}); } } - if (!r) + return nullopt; + }; + + if (cli_cxx* pt = t.is_a ()) + { + // The cli.cxx{} group. + // + cli_cxx& t (*pt); + + // See if we have a .cli source file. + // + if (!find (group_prerequisite_members (a, t))) { l4 ([&]{trace << "no .cli source file for target " << t;}); - return r; + return false; } // Figure out the member list. @@ -95,13 +102,12 @@ namespace build2 ? nullptr : &search (t, t.dir, t.out, t.name); - return r; + return true; } else { // One of the ?xx{} members. // - target& t (xt); // Check if there is a corresponding cli.cxx{} group. // @@ -113,24 +119,13 @@ namespace build2 // if (g == nullptr || !g->has_prerequisites ()) { - for (prerequisite_member p: prerequisite_members (a, t)) + if (optional p = find ( + prerequisite_members (a, t))) { - if (p.is_a ()) - { - // Check that the stems match. - // - if (match_stem (t.name, p.name ())) - { - if (g == nullptr) - g = &targets.insert (t.dir, t.out, t.name, trace); - - g->prerequisites (prerequisites {p.as_prerequisite ()}); - } - else - l4 ([&]{trace << ".cli file stem '" << p.name () << "' " - << "doesn't match target " << t;}); - break; - } + if (g == nullptr) + g = &targets.insert (t.dir, t.out, t.name, trace); + + g->prerequisites (prerequisites {p->as_prerequisite ()}); } } @@ -175,7 +170,7 @@ namespace build2 { case perform_update_id: return &perform_update; case perform_clean_id: return &perform_clean_group; // Standard impl. - default: return noop_recipe; // Configure update. + default: return noop_recipe; // Configure/dist update. } } else -- cgit v1.1