Module Name:    src
Committed By:   rillig
Date:           Mon Nov  2 22:59:49 UTC 2020

Modified Files:
        src/usr.bin/make/unit-tests: varname.exp varname.mk

Log Message:
make(1): document test for parsing of variable assignments


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/varname.exp \
    src/usr.bin/make/unit-tests/varname.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/unit-tests/varname.exp
diff -u src/usr.bin/make/unit-tests/varname.exp:1.7 src/usr.bin/make/unit-tests/varname.exp:1.8
--- src/usr.bin/make/unit-tests/varname.exp:1.7	Mon Nov  2 22:46:52 2020
+++ src/usr.bin/make/unit-tests/varname.exp	Mon Nov  2 22:59:48 2020
@@ -14,11 +14,9 @@ Var_Parse: ${:UVAR\(\(\(}=	try2 with VAR
 Applying ${:U...} to "" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF)
 Result of ${:UVAR\(\(\(} is "VAR\(\(\(" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
 Global:.ALLTARGETS =  VAR(((=) VAR\(\(\(=
-make: "varname.mk" line 31: Need an operator
-Var_Parse: ${:UVAR\(\(\(}=	try3 with VARE_UNDEFERR|VARE_WANTRES
-Applying ${:U...} to "" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF)
-Result of ${:UVAR\(\(\(} is "VAR\(\(\(" (VARE_UNDEFERR|VARE_WANTRES, none, VEF_UNDEF|VEF_DEF)
-make: "varname.mk" line 32: Need an operator
+make: "varname.mk" line 35: Need an operator
+Var_Parse: ${VARNAME} with VARE_WANTRES
+Global:VAR((( = try3
 Global:.MAKEFLAGS =  -r -k -d v -d
 Global:.MAKEFLAGS =  -r -k -d v -d 0
 make: Fatal errors encountered -- cannot continue
Index: src/usr.bin/make/unit-tests/varname.mk
diff -u src/usr.bin/make/unit-tests/varname.mk:1.7 src/usr.bin/make/unit-tests/varname.mk:1.8
--- src/usr.bin/make/unit-tests/varname.mk:1.7	Mon Nov  2 22:44:29 2020
+++ src/usr.bin/make/unit-tests/varname.mk	Mon Nov  2 22:59:48 2020
@@ -1,4 +1,4 @@
-# $NetBSD: varname.mk,v 1.7 2020/11/02 22:44:29 rillig Exp $
+# $NetBSD: varname.mk,v 1.8 2020/11/02 22:59:48 rillig Exp $
 #
 # Tests for special variables, such as .MAKE or .PARSEDIR.
 # And for variable names in general.
@@ -28,8 +28,16 @@ ${VARNAME}=	3 open parentheses
 # balanced.  At the end of the line, there are still 3 levels open, which
 # means the variable name is not finished.
 ${:UVAR(((}=	try1
+# On the left-hand side of a variable assignments, the backslash is not parsed
+# as an escape character, therefore the parentheses still count to the nesting
+# level, which at the end of the line is still 3.  Therefore this is not a
+# variable assignment as well.
 ${:UVAR\(\(\(}=	try2
-${:UVAR\(\(\(}=	try3
+# To assign to a variable with an arbitrary name, the variable name has to
+# come from an external source, not the text that is parsed in the assignment
+# itself.  This is exactly the reason why further above, the indirect
+# ${VARNAME} works, while all other attempts fail.
+${VARNAME}=	try3
 
 .MAKEFLAGS: -d0
 

Reply via email to