[bug #60077] Deterministic $@ for grouped targets patch

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[bug #60077] Deterministic $@ for grouped targets patch

Paul D. Smith
URL:
  <https://savannah.gnu.org/bugs/?60077>

                 Summary: Deterministic $@ for grouped targets patch
                 Project: make
            Submitted by: toddlowe
            Submitted on: Thu 18 Feb 2021 06:42:02 PM UTC
                Severity: 3 - Normal
              Item Group: Enhancement
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
       Component Version: 4.3
        Operating System: None
           Fixed Release: None
           Triage Status: None

    _______________________________________________________

Details:

My team currently uses a macro that expands to multiple rules as a way to
simulate a rule with multiple targets.  I would like to use grouped-targets
instead, but like others, have discovered that $@ referring to the target that
triggered execution rather than a specific target from the list makes it
difficult to use.

I have had a look at
[bug #57898] Automatic variable for all targets on grouped target
and
[bug #58845] In would be nice to have "$&" expand to all targets in a grouped
target
But they refer to a way to get all targets rather than a deterministic way to
always get a “primary target”.

For my use case, I would like $@ to always expand to a specific target from
the grouped list, similar to how $< is always the first prereq.  I’m not a
fan of non-backwards compatible changes, but due to the way grouped-targets
works,  I think this change makes $@ more useful and allows it’s behaviour
to be more consistent between regular recipes and grouped-target recipes.

I’ve attached a patch that causes $@ for grouped-targets to always be the
first target from the list plus changes to the test suite for the new
behaviour.

Matching the prereq behaviour of having variables for first, trigger, and all
seems cleaner than requiring recipes to extract a target from the entire list
so I am also considered adding $& for all a new $! to represent the triggering
target.

Since my current need is only for $@ to consistency return a specific target,
that is what I have implemented and want to share.    

In order to not force this behaviour change on multi-target pattern rules, I
ended up adding a “grouped_target” file flag and only apply my change if
it is set.  I didn’t want to add an extra flag, but other attempts at
excluding pattern-rules quickly became messy.




    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Thu 18 Feb 2021 06:42:02 PM UTC  Name:
0001-Make-always-return-the-1st-target-for-grouped-target.patch  Size: 4KiB  
By: toddlowe

<http://savannah.gnu.org/bugs/download.php?file_id=50880>

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?60077>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #60077] Deterministic $@ for grouped targets patch

Paul D. Smith
Follow-up Comment #1, bug #60077 (project make):

I'm not too jazzed about the idea of $@ working differently for explicit vs.
pattern rule grouped targets.  I agree that the "instigating target" may not
be so useful, but if we change $@ to be a deterministic target then there's NO
way to obtain the instigating target: that information is lost.

What I would prefer is to leave $@ as it is and implement a new variable
containing the list of all grouped targets ($& seems like a good choice to me,
or else we could use something like $(@^) which would kind of be like $^ but
for targets) for both explicit AND pattern rules, then users can either use
$(firstword $&) to obtain the deterministic target or we could introduce a new
special variable like $(@<) or something which was basically the same thing.

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?60077>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/


Reply | Threaded
Open this post in threaded view
|

[bug #60077] Deterministic $@ for grouped targets patch

Paul D. Smith
Follow-up Comment #2, bug #60077 (project make):

I admit I wasn't too thrilled about making $@ behave differently between
explicit and pattern rules, but I definitely did not want to change the long
standing pattern rule behaviour and didn't find the grouped-target $@ useful.
I had proposed $! for instigating target, but I can see that the inconsistency
in that would be worse than the solution.

I'm not sure why I didn't like the idea of $(firstword $&), but likely because
I was too focused on $@ not behaving the way it did with my pseudo
grouped-targets by macro :-)

I had not thought about $(@^) and $(@<), but I like the consistency they have
with the existing variables.

I wrote my patch last fall and other priorities have delayed our move to 4.3.
If I get back to it before someone else, I will implement these and provide a
new patch.


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?60077>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/