From 7eea18037581f266fca33c2c20fd2f7910be3d60 Mon Sep 17 00:00:00 2001 From: rillig Date: Mon, 15 Mar 2021 18:46:05 +0000 Subject: [PATCH] tests/make: demonstrate that the modifier '::=' expands the varname --- usr.bin/make/unit-tests/varmod-assign.exp | 17 +++++++++++++ usr.bin/make/unit-tests/varmod-assign.mk | 30 ++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/usr.bin/make/unit-tests/varmod-assign.exp b/usr.bin/make/unit-tests/varmod-assign.exp index 0116ea30c7b4..3f7a7700b816 100644 --- a/usr.bin/make/unit-tests/varmod-assign.exp +++ b/usr.bin/make/unit-tests/varmod-assign.exp @@ -1,3 +1,20 @@ +Global:param = twice +Global:VARNAME = VAR.$${param} +Var_Parse: ${VARNAME} (eval) +Global:VAR.${param} = initial-value +Var_Parse: ${${VARNAME}::=assigned-value} (eval-defined) +Var_Parse: ${VARNAME}::=assigned-value} (eval-defined) +Applying ${VAR.${param}::...} to "initial-value" (eval-defined, none, regular) +Modifier part: "assigned-value" +Var_Parse: ${param} (eval) +Global:VAR.twice = assigned-value +Result of ${VAR.${param}::=assigned-value} is "" (eval-defined, none, regular) +Var_Parse: $ for symmetry with the usual assignment operators. (eval) +make: "varmod-assign.mk" line 139: FIXME: don't expand the variable name twice here, for symmetry with the usual assignment operators. +Var_Parse: ${${VARNAME}} != "initial-value" (eval-defined) +Var_Parse: ${VARNAME}} != "initial-value" (eval-defined) +Global:.MAKEFLAGS = -r -k -d v -d +Global:.MAKEFLAGS = -r -k -d v -d 0 mod-assign: first=1. mod-assign: last=3. mod-assign: appended=1 2 3. diff --git a/usr.bin/make/unit-tests/varmod-assign.mk b/usr.bin/make/unit-tests/varmod-assign.mk index 5d362946bb53..657363911b71 100644 --- a/usr.bin/make/unit-tests/varmod-assign.mk +++ b/usr.bin/make/unit-tests/varmod-assign.mk @@ -1,4 +1,4 @@ -# $NetBSD: varmod-assign.mk,v 1.10 2021/02/14 12:14:37 rillig Exp $ +# $NetBSD: varmod-assign.mk,v 1.11 2021/03/15 18:46:05 rillig Exp $ # # Tests for the obscure ::= variable modifiers, which perform variable # assignments during evaluation, just like the = operator in C. @@ -114,3 +114,31 @@ _:= $(VAR::=current}) .if ${VAR} != "current}" . error .endif + + +# Before var.c 1.888 from 2021-03-15, an expression using the modifier '::=' +# expanded its variable name once too often during evaluation. This was only +# relevant for variable names containing a '$' sign in their actual name, not +# the usual VAR.${param}. +.MAKEFLAGS: -dv +param= twice +VARNAME= VAR.$${param} # Indirect variable name because of the '$', + # to avoid difficult escaping rules. + +${VARNAME}= initial-value # Sets 'VAR.${param}' to 'expanded'. +.if defined(VAR.twice) # At this point, the '$$' is not expanded. +. error +.endif +.if ${${VARNAME}::=assigned-value} # Here the variable name gets expanded once +. error # too often. +.endif +.if !defined(VAR.twice) +. error # FIXME: This is the unwanted current behavior. +.else +. info FIXME: don't expand the variable name twice here, $\ + for symmetry with the usual assignment operators. +.endif +.if ${${VARNAME}} != "initial-value" +. error +.endif +.MAKEFLAGS: -d0