From 7d6be9ffc4ef51af2d953245348ec6d8dbf5080a Mon Sep 17 00:00:00 2001 From: rillig Date: Sat, 22 Aug 2020 21:22:24 +0000 Subject: [PATCH] make(1): try to set the variable named "" using the command line Before 2020-08-22, the command line argument '=cmline-plain' triggered undefined behavior, just like the assignment '=assigned' in the Makefile. --- usr.bin/make/unit-tests/Makefile | 4 +++- usr.bin/make/unit-tests/varname-empty.exp | 12 ++++++++++-- usr.bin/make/unit-tests/varname-empty.mk | 8 ++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/usr.bin/make/unit-tests/Makefile b/usr.bin/make/unit-tests/Makefile index 19aef769d55e..275a77deef7b 100644 --- a/usr.bin/make/unit-tests/Makefile +++ b/usr.bin/make/unit-tests/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.111 2020/08/22 20:50:43 sjg Exp $ +# $NetBSD: Makefile,v 1.112 2020/08/22 21:22:24 rillig Exp $ # # Unit tests for make(1) # @@ -323,6 +323,7 @@ FLAGS.order= -j1 FLAGS.recursive= -dL FLAGS.vardebug= -k -dv FROM_CMDLINE= FLAGS.varmod-match-escape= -dv +FLAGS.varname-empty= -dv '$${:U}=cmdline-u' '=cmline-plain' # Some tests need extra post-processing. SED_CMDS.sh-dots+= -e 's,^${.SHELL}: ,,' @@ -336,6 +337,7 @@ SED_CMDS.varshell+= -e '/command/s,No such.*,not found,' POSTPROC.counter= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p' POSTPROC.vardebug= ${TOOL_SED} -n -e '/:RELEVANT = yes/,/:RELEVANT = no/p' POSTPROC.varmod-match-escape= ${TOOL_SED} -n -e '/^Pattern/p' +POSTPROC.varname-empty= ${TOOL_SED} -n -e '/^Var_Set/p' -e '/^out:/p' # Some tests reuse other tests, which makes them unnecessarily fragile. export-all.rawout: export.mk diff --git a/usr.bin/make/unit-tests/varname-empty.exp b/usr.bin/make/unit-tests/varname-empty.exp index 565cfb54fd61..77cb7c517e9d 100644 --- a/usr.bin/make/unit-tests/varname-empty.exp +++ b/usr.bin/make/unit-tests/varname-empty.exp @@ -1,3 +1,11 @@ -fallback -1 2 3 +Var_Set("${:U}", "cmdline-u", ...) name expands to empty string - ignored +Var_Set("", "cmline-plain", ...) name expands to empty string - ignored +Var_Set("", "default", ...) name expands to empty string - ignored +Var_Set("", "assigned", ...) name expands to empty string - ignored +Var_Set("", "appended", ...) name expands to empty string - ignored +Var_Set("", "", ...) name expands to empty string - ignored +Var_Set("", "subst", ...) name expands to empty string - ignored +Var_Set("", "shell-output", ...) name expands to empty string - ignored +out: fallback +out: 1 2 3 exit status 0 diff --git a/usr.bin/make/unit-tests/varname-empty.mk b/usr.bin/make/unit-tests/varname-empty.mk index 87de6ab09224..b4ce05c3017b 100644 --- a/usr.bin/make/unit-tests/varname-empty.mk +++ b/usr.bin/make/unit-tests/varname-empty.mk @@ -1,4 +1,4 @@ -# $NetBSD: varname-empty.mk,v 1.4 2020/08/22 21:12:29 rillig Exp $ +# $NetBSD: varname-empty.mk,v 1.5 2020/08/22 21:22:24 rillig Exp $ # # Tests for the special variable with the empty name. # @@ -12,7 +12,7 @@ = assigned # undefined behavior until 2020-08-22 += appended := subst -!= echo 'value' +!= echo 'shell-output' # The .for loop expands the expression ${i} to ${:U1}, ${:U2} and so on. # This only works if the variable with the empty name is guaranteed to @@ -22,5 +22,5 @@ NUMBERS+= ${i} .endfor all: - @echo ${:Ufallback} - @echo ${NUMBERS} + @echo out: ${:Ufallback} + @echo out: ${NUMBERS}