From e3f077ba7584f65561e21ca195215abd341b9147 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 7 Feb 2022 07:59:48 +0200 Subject: Add support for meta-operation wildcard in scope::insert_rule() --- build2/cli/init.cxx | 16 +++++----------- libbuild2/parser.cxx | 6 ++++++ libbuild2/scope.hxx | 26 +++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/build2/cli/init.cxx b/build2/cli/init.cxx index 2a07196..a00fd7f 100644 --- a/build2/cli/init.cxx +++ b/build2/cli/init.cxx @@ -246,6 +246,9 @@ namespace build2 // Register our rules. // + // Other rules (e.g., cc::compile) may need to have the group members + // resolved/linked up. Looks like a general pattern: groups should + // resolve on *(update). { auto reg = [&rs, &m] (meta_operation_id mid, operation_id oid) { @@ -255,17 +258,8 @@ namespace build2 rs.insert_rule (mid, oid, "cli.compile", m); }; - reg (perform_id, update_id); - reg (perform_id, clean_id); - - // Other rules (e.g., cc::compile) may need to have the group members - // resolved/linked up. Looks like a general pattern: groups should - // resolve on *(update). - // - // @@ meta-op wildcard? - // - reg (configure_id, update_id); - reg (dist_id, update_id); + reg (0 /* wildcard */, update_id); + reg (perform_id, clean_id); } return true; diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx index 9f69117..f42666b 100644 --- a/libbuild2/parser.cxx +++ b/libbuild2/parser.cxx @@ -1171,6 +1171,12 @@ namespace build2 skip: ; } + + // @@ TODO: if this rule does dynamic member discovery of a + // see-through target group, then we may also need to + // register update for other meta-operations (see, for + // example, wildcard update registration in the cli + // module). } } } diff --git a/libbuild2/scope.hxx b/libbuild2/scope.hxx index f82db72..e3ebdef 100644 --- a/libbuild2/scope.hxx +++ b/libbuild2/scope.hxx @@ -423,13 +423,37 @@ namespace build2 rules.insert (a, move (hint), r); } + // 0 meta-operation id is treated as an (emulated) wildcard. + // + // Emulated means that we just iterate over all the meta-operations known + // to this project (and they should all be known at this point) and + // register the rule for each of them. + // template void insert_rule (meta_operation_id mid, operation_id oid, string hint, const rule& r) { - rules.insert (mid, oid, move (hint), r); + if (mid != 0) + rules.insert (mid, oid, move (hint), r); + else + { + auto& ms (root_scope ()->root_extra->meta_operations); + + for (size_t i (1), n (ms.size ()); i != n; ++i) + { + // Skip a few well-known meta-operations that cannot possibly + // trigger a rule match. + // + if (ms[i] != nullptr && + i != noop_id && + i != info_id && + i != create_id && + i != disfigure_id) + rules.insert (i, oid, hint, r); + } + } } // Operation callbacks. -- cgit v1.1