Module Name: src
Committed By: rillig
Date: Sat Nov 28 14:08:38 UTC 2020
Modified Files:
src/usr.bin/make/unit-tests: cond-func-empty.mk varmisc.mk
Log Message:
make(1): move test for recursive variable to cond-func-empty
Previously, the documentation of that test was much too short to explain
all the effects that happened in the bug situation from 2020-06-28 until
2020-07-02.
To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/cond-func-empty.mk
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/make/unit-tests/varmisc.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/cond-func-empty.mk
diff -u src/usr.bin/make/unit-tests/cond-func-empty.mk:1.10 src/usr.bin/make/unit-tests/cond-func-empty.mk:1.11
--- src/usr.bin/make/unit-tests/cond-func-empty.mk:1.10 Sun Nov 15 14:07:53 2020
+++ src/usr.bin/make/unit-tests/cond-func-empty.mk Sat Nov 28 14:08:37 2020
@@ -1,4 +1,4 @@
-# $NetBSD: cond-func-empty.mk,v 1.10 2020/11/15 14:07:53 rillig Exp $
+# $NetBSD: cond-func-empty.mk,v 1.11 2020/11/28 14:08:37 rillig Exp $
#
# Tests for the empty() function in .if conditions, which tests a variable
# expression for emptiness.
@@ -155,5 +155,30 @@ ${:U WORD }= variable name with spaces
. error
.endif
+# Between 2020-06-28 and var.c 1.226 from 2020-07-02, this paragraph generated
+# a wrong error message "Variable VARNAME is recursive".
+#
+# The bug was that the !empty() condition was evaluated, even though this was
+# not necessary since the defined() condition already evaluated to false.
+#
+# When evaluating the !empty condition, the variable name was parsed as
+# "VARNAME${:U2}", but without expanding any nested variable expression, in
+# this case the ${:U2}. Therefore, the variable name came out as simply
+# "VARNAME". Since this variable name should have been discarded quickly after
+# parsing it, this unrealistic variable name should have done no harm.
+#
+# The variable expression was expanded though, and this was wrong. The
+# expansion was done without the VARE_WANTRES flag (called VARF_WANTRES back
+# then) though. This had the effect that the ${:U1} from the value of VARNAME
+# expanded to an empty string. This in turn created the seemingly recursive
+# definition VARNAME=${VARNAME}, and that definition was never meant to be
+# expanded.
+#
+# This was fixed by expanding nested variable expressions in the variable name
+# only if the flag VARE_WANTRES is given.
+VARNAME= ${VARNAME${:U1}}
+.if defined(VARNAME${:U2}) && !empty(VARNAME${:U2})
+.endif
+
all:
@:;
Index: src/usr.bin/make/unit-tests/varmisc.mk
diff -u src/usr.bin/make/unit-tests/varmisc.mk:1.28 src/usr.bin/make/unit-tests/varmisc.mk:1.29
--- src/usr.bin/make/unit-tests/varmisc.mk:1.28 Sat Nov 7 00:07:02 2020
+++ src/usr.bin/make/unit-tests/varmisc.mk Sat Nov 28 14:08:37 2020
@@ -1,4 +1,4 @@
-# $NetBSD: varmisc.mk,v 1.28 2020/11/07 00:07:02 rillig Exp $
+# $NetBSD: varmisc.mk,v 1.29 2020/11/28 14:08:37 rillig Exp $
#
# Miscellaneous variable tests.
@@ -77,16 +77,6 @@ MAN+= ${MAN$s}
manok:
@echo MAN=${MAN}
-# This is an expanded variant of the above .for loop.
-# Between 2020-06-28 and 2020-07-02 this paragraph generated a wrong
-# error message "Variable VARNAME is recursive".
-# When evaluating the !empty expression, the ${:U1} was not expanded and
-# thus resulted in the seeming definition VARNAME=${VARNAME}, which is
-# obviously recursive.
-VARNAME= ${VARNAME${:U1}}
-.if defined(VARNAME${:U2}) && !empty(VARNAME${:U2})
-.endif
-
# 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= $$$$