bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New conditional assignment facility


From: Dmitry Goncharov
Subject: Re: New conditional assignment facility
Date: Sat, 20 Jan 2024 22:18:50 -0500

On Thu, Jan 11, 2024 at 7:55 AM Paul Smith <psmith@gnu.org> wrote:
> So the new confusion becomes, what happens if you use "+" to append to
> an existing variable that has a different type?
>
> Due to decades of history (and, to be honest, significant technical
> incentive), we have to say that in this case:
>
>     bar = xx
>     biz = yy
>     FOO := $(bar)
>     FOO += $(biz)
>     bar = 1
>     biz = 2
>
> FOO is a simply-expanded variable and $(biz) is expanded immediately
> even though it uses a "+=" assignment, and FOO is "xx yy".
>
> But then, what do we say about this case:
>
>     bar = xx
>     biz = yy
>     FOO = $(bar)
>     FOO +:= $(biz)
>     bar = 1
>     biz = 2
>
> ? There appear to be two options:
>
> Either we could follow the example of "+=" and say that the assignment
> type in "+:=" only takes effect if the variable doesn't already have a
> type but if it does that type is preserved, so in the above example FOO
> would continue to be recursively expanded in spite of "+:=", so FOO has
> a value of "$(bar) $(biz)" and $(FOO) gives "1 2".
>
> Or we could say that "+=" is a special case where we follow the type of
> the existing variable, but for the other operators we first expand the
> right hand side then append the result regardless of the original type.
> So in the above example FOO is still a recursive variable, BUT $(baz)
> is expanded immediately before appending so the value of FOO would be
> "$(bar) yy" and $(FOO) gives "1 yy".
>
> Neither of these is great, in that they both will cause people to be
> surprised, in different situations.

i like option one. It is simple to explain in the manual and, as far
as i can tell, option one does what users want.
As long as the manual says something like "when there is no variable
+:= creates a simple variable, otherwise +:= behaves the same as :="
is there still room for surprises?

i suspect option two is a lot trickier to use in a makefile. Option
two introduces a doubt in the mind of a makefile author. If the
makefile author knows that all the appends +=, :+=, ::+=+, :::+=
follow the variable flavor, once the variable is created, then the
author sees that a variable is recursive at the top of a makefile and
knows anything can be appended to the variable at the bottom of the
makefile and the value will contain that anything at build time. If we
go with option two then the author does not have this knowledge. In
your example, one scenario is that the author misses that the
assignment is +:= and sets biz to 2 and expects that FOO contains "1
2" at build time. Another scenario is that 'FOO +:= $(biz)' is
introduced long after 'biz = 2'. Similarly, if the author wants to
introduce a +:= assignment somewhere in a makefile, they have to check
that the makefile does not contain another assignment later. In our
example, if the author wanted to introduce FOO +:= $(biz) they will
have to check that biz is not assigned later.



regards, Dmitry



reply via email to

[Prev in Thread] Current Thread [Next in Thread]