[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug #54727] foreach variable is not visible for a target specific v
Re: [bug #54727] foreach variable is not visible for a target specific variable definition in a recipe
Fri, 5 Oct 2018 10:28:01 +0300
Many thanks to you, Brian.
I'm not solving a real problem, I just found a corner case, which I think should
fixed or documented.
In some cases, it is preferable to delay variable expansions in $(eval ...) to speed up the parser, and $(foreach ...) can be used to introduce local variables.
It seems that it's not hard to fix this bug and the fix does not break existing scripts, I will send a patch when I have time.
On Fri, Oct 5, 2018 at 2:50 AM Brian Vandenberg <address@hidden
On Thu, Oct 4, 2018 at 7:53 AM Michael Builov <address@hidden> wrote:
> Follow-up Comment #3, bug #54727 (project make):
> It also possible to step on this "foreach + eval" bug not in a recipe.
Agreed, I reproduced with the following:
$ cat -n makefile
1 .RECIPEPREFIX := >
3 asdf=$(foreach f,1,$(eval $1:$2:=$$f))
4 $(call asdf,A,M)
5 all:TMP:=$(call asdf,B,M)
6 all:A B
7 all A B:
8 >$(warning address@hidden: M := $(value M))
$ make --version | head -n1
GNU Make 4.1
makefile:8: A: M := 1
makefile:8: B: M := g
makefile:8: all: M :=
... however, by changing $$f => $f the problem goes away. On the one
hand I agree it's inconsistent but on the other hand in these toy
examples "$$f" isn't needed. In the original problem you were trying
to report is there any particular reason the $(foreach) variable's
expansion was delayed?
> Please consider the next example:
> # define global variable
> f := g
> # function for defining target-specific variables
> # $1 - target
> # $2 - variable
> def_target_specific = $(foreach f,1,$(eval $1: $2:=$$f))
> # calling in global context: M=1
> $(call def_target_specific,target_X,M)
> # calling in target-specific context: M=g
> all: TMP := $(call def_target_specific,target_Y,M)
> all: target_X target_Y
> target_X target_Y:; $(info $@: M=$M)
> target_X: M=1
> target_Y: M=g
> As we can see, the variable M has different values for target_X and target_Y,
> which is not expected.
> Outer foreach variables cannot be used inside the eval context, if the call
> comes from a target-specific variable definition.
> Reply to this item at:
> Message sent via Savannah
> Bug-make mailing list
Bug-make mailing list