Module Name: src
Committed By: rillig
Date: Tue Nov 30 23:52:19 UTC 2021
Modified Files:
src/usr.bin/make/unit-tests: var-op-expand.exp var-op-expand.mk
varmisc.mk varmod-defined.mk varmod-loop-varname.exp
varmod-loop-varname.mk varmod-loop.exp varmod-loop.mk
varname-dot-make-save_dollars.mk
Log Message:
tests/make: test and document .MAKE.SAVE_DOLLARS and ':='
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/var-op-expand.exp
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/make/unit-tests/var-op-expand.mk
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/make/unit-tests/varmisc.mk
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/make/unit-tests/varmod-defined.mk
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/varmod-loop-varname.exp \
src/usr.bin/make/unit-tests/varmod-loop-varname.mk \
src/usr.bin/make/unit-tests/varname-dot-make-save_dollars.mk
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/varmod-loop.exp
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/make/unit-tests/varmod-loop.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/var-op-expand.exp
diff -u src/usr.bin/make/unit-tests/var-op-expand.exp:1.5 src/usr.bin/make/unit-tests/var-op-expand.exp:1.6
--- src/usr.bin/make/unit-tests/var-op-expand.exp:1.5 Sat Nov 20 17:47:33 2021
+++ src/usr.bin/make/unit-tests/var-op-expand.exp Tue Nov 30 23:52:19 2021
@@ -1,7 +1,7 @@
-make: "var-op-expand.mk" line 259: Unknown modifier "s,value,replaced,"
-make: "var-op-expand.mk" line 262: warning: XXX Neither branch should be taken.
-make: "var-op-expand.mk" line 267: Unknown modifier "s,value,replaced,"
+make: "var-op-expand.mk" line 265: Unknown modifier "s,value,replaced,"
make: "var-op-expand.mk" line 268: warning: XXX Neither branch should be taken.
+make: "var-op-expand.mk" line 273: Unknown modifier "s,value,replaced,"
+make: "var-op-expand.mk" line 274: warning: XXX Neither branch should be taken.
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
Index: src/usr.bin/make/unit-tests/var-op-expand.mk
diff -u src/usr.bin/make/unit-tests/var-op-expand.mk:1.14 src/usr.bin/make/unit-tests/var-op-expand.mk:1.15
--- src/usr.bin/make/unit-tests/var-op-expand.mk:1.14 Sat Nov 20 17:47:33 2021
+++ src/usr.bin/make/unit-tests/var-op-expand.mk Tue Nov 30 23:52:19 2021
@@ -1,8 +1,14 @@
-# $NetBSD: var-op-expand.mk,v 1.14 2021/11/20 17:47:33 rillig Exp $
+# $NetBSD: var-op-expand.mk,v 1.15 2021/11/30 23:52:19 rillig Exp $
#
# Tests for the := variable assignment operator, which expands its
# right-hand side.
+#
+# See also:
+# varname-dot-make-save_dollars.mk
+# Force the test results to be independent of the default value of this
+# setting, which is 'yes' for NetBSD's usr.bin/make but 'no' for the bmake
+# distribution and pkgsrc/devel/bmake.
.MAKE.SAVE_DOLLARS:= yes
# If the right-hand side does not contain a dollar sign, the ':=' assignment
Index: src/usr.bin/make/unit-tests/varmisc.mk
diff -u src/usr.bin/make/unit-tests/varmisc.mk:1.30 src/usr.bin/make/unit-tests/varmisc.mk:1.31
--- src/usr.bin/make/unit-tests/varmisc.mk:1.30 Thu Feb 4 21:42:47 2021
+++ src/usr.bin/make/unit-tests/varmisc.mk Tue Nov 30 23:52:19 2021
@@ -1,4 +1,4 @@
-# $NetBSD: varmisc.mk,v 1.30 2021/02/04 21:42:47 rillig Exp $
+# $NetBSD: varmisc.mk,v 1.31 2021/11/30 23:52:19 rillig Exp $
#
# Miscellaneous variable tests.
@@ -65,7 +65,7 @@ cmpv:
@echo Literal=3.4.5 == ${3.4.5:L:${M_cmpv}}
@echo We have ${${.TARGET:T}.only}
-# catch misshandling of nested vars in .for loop
+# catch mishandling of nested variables in .for loop
MAN=
MAN1= make.1
.for s in 1 2
@@ -77,12 +77,13 @@ MAN+= ${MAN$s}
manok:
@echo MAN=${MAN}
+# Test parsing of boolean values.
# begin .MAKE.SAVE_DOLLARS; see Var_SetWithFlags and ParseBoolean.
SD_VALUES= 0 1 2 False True false true Yes No yes no On Off ON OFF on off
SD_4_DOLLARS= $$$$
.for val in ${SD_VALUES}
-.MAKE.SAVE_DOLLARS:= ${val} # Must be := since a simple = has no effect.
+.MAKE.SAVE_DOLLARS:= ${val} # Must be := since a simple '=' has no effect.
SD.${val}:= ${SD_4_DOLLARS}
.endfor
.MAKE.SAVE_DOLLARS:= yes
@@ -91,6 +92,7 @@ save-dollars:
.for val in ${SD_VALUES}
@printf '%s: %-8s = %s\n' $@ ${val} ${SD.${val}:Q}
.endfor
+# end .MAKE.SAVE_DOLLARS
# Appending to an undefined variable does not add a space in front.
.undef APPENDED
Index: src/usr.bin/make/unit-tests/varmod-defined.mk
diff -u src/usr.bin/make/unit-tests/varmod-defined.mk:1.11 src/usr.bin/make/unit-tests/varmod-defined.mk:1.12
--- src/usr.bin/make/unit-tests/varmod-defined.mk:1.11 Sun Apr 11 13:35:56 2021
+++ src/usr.bin/make/unit-tests/varmod-defined.mk Tue Nov 30 23:52:19 2021
@@ -1,8 +1,11 @@
-# $NetBSD: varmod-defined.mk,v 1.11 2021/04/11 13:35:56 rillig Exp $
+# $NetBSD: varmod-defined.mk,v 1.12 2021/11/30 23:52:19 rillig Exp $
#
# Tests for the :D variable modifier, which returns the given string
# if the variable is defined. It is closely related to the :U modifier.
+# Force the test results to be independent of the default value of this
+# setting, which is 'yes' for NetBSD's usr.bin/make but 'no' for the bmake
+# distribution and pkgsrc/devel/bmake.
.MAKE.SAVE_DOLLARS= yes
DEF= defined
Index: src/usr.bin/make/unit-tests/varmod-loop-varname.exp
diff -u src/usr.bin/make/unit-tests/varmod-loop-varname.exp:1.2 src/usr.bin/make/unit-tests/varmod-loop-varname.exp:1.3
--- src/usr.bin/make/unit-tests/varmod-loop-varname.exp:1.2 Sun Apr 4 13:35:26 2021
+++ src/usr.bin/make/unit-tests/varmod-loop-varname.exp Tue Nov 30 23:52:19 2021
@@ -1,11 +1,11 @@
-make: "varmod-loop-varname.mk" line 13: In the :@ modifier of "", the variable name "${:Ubar:S,b,v,}" must not contain a dollar.
-make: "varmod-loop-varname.mk" line 13: Malformed conditional (${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+")
-make: "varmod-loop-varname.mk" line 80: In the :@ modifier of "1 2 3", the variable name "v$" must not contain a dollar.
-make: "varmod-loop-varname.mk" line 80: Malformed conditional (${1 2 3:L:@v$@($v)@} != "(1) (2) (3)")
-make: "varmod-loop-varname.mk" line 85: In the :@ modifier of "1 2 3", the variable name "v$$" must not contain a dollar.
-make: "varmod-loop-varname.mk" line 85: Malformed conditional (${1 2 3:L:@v$$@($v)@} != "() () ()")
-make: "varmod-loop-varname.mk" line 90: In the :@ modifier of "1 2 3", the variable name "v$$$" must not contain a dollar.
-make: "varmod-loop-varname.mk" line 90: Malformed conditional (${1 2 3:L:@v$$$@($v)@} != "() () ()")
+make: "varmod-loop-varname.mk" line 16: In the :@ modifier of "", the variable name "${:Ubar:S,b,v,}" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 16: Malformed conditional (${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+")
+make: "varmod-loop-varname.mk" line 83: In the :@ modifier of "1 2 3", the variable name "v$" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 83: Malformed conditional (${1 2 3:L:@v$@($v)@} != "(1) (2) (3)")
+make: "varmod-loop-varname.mk" line 88: In the :@ modifier of "1 2 3", the variable name "v$$" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 88: Malformed conditional (${1 2 3:L:@v$$@($v)@} != "() () ()")
+make: "varmod-loop-varname.mk" line 93: In the :@ modifier of "1 2 3", the variable name "v$$$" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 93: Malformed conditional (${1 2 3:L:@v$$$@($v)@} != "() () ()")
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
Index: src/usr.bin/make/unit-tests/varmod-loop-varname.mk
diff -u src/usr.bin/make/unit-tests/varmod-loop-varname.mk:1.2 src/usr.bin/make/unit-tests/varmod-loop-varname.mk:1.3
--- src/usr.bin/make/unit-tests/varmod-loop-varname.mk:1.2 Sun Apr 4 13:35:26 2021
+++ src/usr.bin/make/unit-tests/varmod-loop-varname.mk Tue Nov 30 23:52:19 2021
@@ -1,8 +1,11 @@
-# $NetBSD: varmod-loop-varname.mk,v 1.2 2021/04/04 13:35:26 rillig Exp $
+# $NetBSD: varmod-loop-varname.mk,v 1.3 2021/11/30 23:52:19 rillig Exp $
#
# Tests for the first part of the variable modifier ':@var@...@', which
# contains the variable name to use during the loop.
+# Force the test results to be independent of the default value of this
+# setting, which is 'yes' for NetBSD's usr.bin/make but 'no' for the bmake
+# distribution and pkgsrc/devel/bmake.
.MAKE.SAVE_DOLLARS= yes
Index: src/usr.bin/make/unit-tests/varname-dot-make-save_dollars.mk
diff -u src/usr.bin/make/unit-tests/varname-dot-make-save_dollars.mk:1.2 src/usr.bin/make/unit-tests/varname-dot-make-save_dollars.mk:1.3
--- src/usr.bin/make/unit-tests/varname-dot-make-save_dollars.mk:1.2 Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/varname-dot-make-save_dollars.mk Tue Nov 30 23:52:19 2021
@@ -1,8 +1,59 @@
-# $NetBSD: varname-dot-make-save_dollars.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: varname-dot-make-save_dollars.mk,v 1.3 2021/11/30 23:52:19 rillig Exp $
#
-# Tests for the special .MAKE.SAVE_DOLLARS variable.
+# Tests for the special .MAKE.SAVE_DOLLARS variable, which controls whether
+# the assignment operator ':=' converts '$$' to a single '$' or keeps it
+# as-is.
+#
+# See also:
+# var-op-expand.mk
+# varmisc.mk for the boolean values
+
+# Initially, the variable .MAKE.SAVE_DOLLARS is undefined. At this point the
+# behavior of the assignment operator ':=' depends. NetBSD's usr.bin/make
+# preserves the '$$' as-is, while the bmake distribution replaces '$$' with
+# '$'.
+.if ${.MAKE.SAVE_DOLLARS:Uundefined} != "undefined"
+. error
+.endif
+
+
+# Even when dollars are preserved, it only applies to literal dollars, not
+# those that come indirectly from other expressions.
+.MAKE.SAVE_DOLLARS= yes
+DOLLARS= $$$$$$$$
+VAR:= ${DOLLARS}
+# The reduction from 8 '$' to 4 '$' happens when ${VAR} is evaluated in the
+# condition; .MAKE.SAVE_DOLLARS only applies to the operator ':='.
+.if ${VAR} != "\$\$\$\$"
+. error
+.endif
+
+# Dollars from the literal value are preserved now.
+.MAKE.SAVE_DOLLARS= yes
+VAR:= $$$$$$$$
+.if ${VAR} != "\$\$\$\$"
+. error
+.endif
+
+.MAKE.SAVE_DOLLARS= no
+VAR:= $$$$$$$$
+.if ${VAR} != "\$\$"
+. error
+.endif
+
+# It's even possible to change the dollar interpretation in the middle of
+# evaluating an expression, even though there is no practical need for it.
+.MAKE.SAVE_DOLLARS= no
+VAR:= $$$$-${.MAKE.SAVE_DOLLARS::=yes}-$$$$
+.if ${VAR} != "\$--\$\$"
+. error
+.endif
-# TODO: Implementation
+# The '$' from the ':U' expressions are indirect, therefore SAVE_DOLLARS
+# doesn't apply to them.
+VAR:= ${:U\$\$\$\$}-${.MAKE.SAVE_DOLLARS::=yes}-${:U\$\$\$\$}
+.if ${VAR} != "\$\$--\$\$"
+. error
+.endif
all:
- @:;
Index: src/usr.bin/make/unit-tests/varmod-loop.exp
diff -u src/usr.bin/make/unit-tests/varmod-loop.exp:1.10 src/usr.bin/make/unit-tests/varmod-loop.exp:1.11
--- src/usr.bin/make/unit-tests/varmod-loop.exp:1.10 Sun Apr 4 13:20:52 2021
+++ src/usr.bin/make/unit-tests/varmod-loop.exp Tue Nov 30 23:52:19 2021
@@ -1,10 +1,10 @@
-ParseReadLine (75): 'USE_8_DOLLARS= ${:U1:@var@${8_DOLLARS}@} ${8_DOLLARS} $$$$$$$$'
+ParseReadLine (78): 'USE_8_DOLLARS= ${:U1:@var@${8_DOLLARS}@} ${8_DOLLARS} $$$$$$$$'
CondParser_Eval: ${USE_8_DOLLARS} != "\$\$\$\$ \$\$\$\$ \$\$\$\$"
lhs = "$$$$ $$$$ $$$$", rhs = "$$$$ $$$$ $$$$", op = !=
-ParseReadLine (80): 'SUBST_CONTAINING_LOOP:= ${USE_8_DOLLARS}'
+ParseReadLine (83): 'SUBST_CONTAINING_LOOP:= ${USE_8_DOLLARS}'
CondParser_Eval: ${SUBST_CONTAINING_LOOP} != "\$\$ \$\$\$\$ \$\$\$\$"
lhs = "$$ $$$$ $$$$", rhs = "$$ $$$$ $$$$", op = !=
-ParseReadLine (105): '.MAKEFLAGS: -d0'
+ParseReadLine (108): '.MAKEFLAGS: -d0'
ParseDependency(.MAKEFLAGS: -d0)
:varname-overwriting-target: :x1y x2y x3y: ::
mod-loop-dollar:1:
Index: src/usr.bin/make/unit-tests/varmod-loop.mk
diff -u src/usr.bin/make/unit-tests/varmod-loop.mk:1.15 src/usr.bin/make/unit-tests/varmod-loop.mk:1.16
--- src/usr.bin/make/unit-tests/varmod-loop.mk:1.15 Sun Apr 11 13:35:56 2021
+++ src/usr.bin/make/unit-tests/varmod-loop.mk Tue Nov 30 23:52:19 2021
@@ -1,7 +1,10 @@
-# $NetBSD: varmod-loop.mk,v 1.15 2021/04/11 13:35:56 rillig Exp $
+# $NetBSD: varmod-loop.mk,v 1.16 2021/11/30 23:52:19 rillig Exp $
#
# Tests for the :@var@...${var}...@ variable modifier.
+# Force the test results to be independent of the default value of this
+# setting, which is 'yes' for NetBSD's usr.bin/make but 'no' for the bmake
+# distribution and pkgsrc/devel/bmake.
.MAKE.SAVE_DOLLARS= yes
all: varname-overwriting-target