From 349b34108752e2fcf1ead648ffec8e5acfe4a91c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 23 May 2023 09:21:40 +0200 Subject: Explicit group: syntax parsing --- libbuild2/target.hxx | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'libbuild2/target.hxx') diff --git a/libbuild2/target.hxx b/libbuild2/target.hxx index e935477..01e82bb 100644 --- a/libbuild2/target.hxx +++ b/libbuild2/target.hxx @@ -409,7 +409,7 @@ namespace build2 // usually needed is to derive its path. // // - Unless declared, members are discovered lazily, they are only known - // after the group's rule's apply() call. + // after the matching rule's apply() call. // // - Only declared members can be used as prerequisites but all can be // used as targets (e.g., to set variables, etc). @@ -439,7 +439,11 @@ namespace build2 // target for the ad hoc members (with a special target type that rules // like install could recognize). See also the variable lookup semantics. // We could also probably support see_through via an attribute or some - // such. + // such. Or perhaps such cases should be handled through explicit groups + // and the ad hoc semantics is left to the non-see_through "primary + // targets with a bunch of subordinates" cases. In other words, if the + // members are "equal/symmetrical", then perhaps an explicit group is the + // correct approach. // const_ptr adhoc_member = nullptr; @@ -2148,6 +2152,33 @@ namespace build2 static const target_type static_type; }; + // Mtime-based group target. + // + // Used to support explicit groups in buildfiles: can be derived from, + // populated with static members using the group{foo}<...> syntax, and + // matched with an ad hoc recipe/rule, including dynamic member extraction. + // Note that it is not see-through but a derived group can be made see- + // through via the [see_through] attribute. + // + // Note that normally you wouldn't use it as a base for a custom group + // defined in C++, instead deriving from mtime_target directly and using a + // custom members layout more appropriate for the group's semantics. + // + class LIBBUILD2_SYMEXPORT group: public mtime_target + { + public: + vector> static_members; + + group (context& c, dir_path d, dir_path o, string n) + : mtime_target (c, move (d), move (o), move (n)) + { + dynamic_type = &static_type; + } + + public: + static const target_type static_type; + }; + // Alias target. It represents a list of targets (its prerequisites) // as a single "name". // -- cgit v1.1