Module Name: src Committed By: rillig Date: Sun Jan 24 19:48:11 UTC 2021
Modified Files: src/usr.bin/make/unit-tests: directive-for-escape.exp directive-for-escape.mk Log Message: make(1): describe expansion of nested variables in .for values These edge cases are not documented anywhere, and their behavior is non-intuitive. For now, just describe them, don't try to fix them. There may be people out there relying on exactly this behavior. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/directive-for-escape.exp \ src/usr.bin/make/unit-tests/directive-for-escape.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/directive-for-escape.exp diff -u src/usr.bin/make/unit-tests/directive-for-escape.exp:1.4 src/usr.bin/make/unit-tests/directive-for-escape.exp:1.5 --- src/usr.bin/make/unit-tests/directive-for-escape.exp:1.4 Sun Jan 24 19:30:18 2021 +++ src/usr.bin/make/unit-tests/directive-for-escape.exp Sun Jan 24 19:48:11 2021 @@ -27,25 +27,29 @@ make: "directive-for-escape.mk" line 41: For: end for 1 For: loop body: . info ${:U\${UNDEF\:U\\$\\$} -make: "directive-for-escape.mk" line 52: ${UNDEF:U\$ +make: "directive-for-escape.mk" line 55: ${UNDEF:U\$ For: loop body: . info ${:U{{\}\}} -make: "directive-for-escape.mk" line 52: {{}} +make: "directive-for-escape.mk" line 55: {{}} For: loop body: . info ${:Uend\}} -make: "directive-for-escape.mk" line 52: end} +make: "directive-for-escape.mk" line 55: end} +For: end for 1 +For: loop body: +. info ${:Ubegin<${UNDEF:Ufallback:N{{{}}}}>end} +make: "directive-for-escape.mk" line 66: begin<fallback>end For: end for 1 For: loop body: . info ${:U\$} -make: "directive-for-escape.mk" line 60: $ +make: "directive-for-escape.mk" line 74: $ For: end for 1 For: loop body: . info ${NUMBERS} ${:Ureplaced} -make: "directive-for-escape.mk" line 68: one two three replaced +make: "directive-for-escape.mk" line 82: one two three replaced For: end for 1 For: loop body: . info ${:Ureplaced} -make: "directive-for-escape.mk" line 78: replaced +make: "directive-for-escape.mk" line 92: replaced For: end for 1 For: loop body: . info . $$i: ${:Uinner} @@ -58,14 +62,14 @@ For: loop body: . info . $${i2}: ${i2} . info . $${i,}: ${i,} . info . adjacent: ${:Uinner}${:Uinner}${:Uinner:M*}${:Uinner} -make: "directive-for-escape.mk" line 86: . $i: inner -make: "directive-for-escape.mk" line 87: . ${i}: inner -make: "directive-for-escape.mk" line 88: . ${i:M*}: inner -make: "directive-for-escape.mk" line 89: . $(i): inner -make: "directive-for-escape.mk" line 90: . $(i:M*): inner -make: "directive-for-escape.mk" line 91: . ${i${:U}}: outer -make: "directive-for-escape.mk" line 92: . ${i\}}: inner} -make: "directive-for-escape.mk" line 93: . ${i2}: two -make: "directive-for-escape.mk" line 94: . ${i,}: comma -make: "directive-for-escape.mk" line 95: . adjacent: innerinnerinnerinner +make: "directive-for-escape.mk" line 100: . $i: inner +make: "directive-for-escape.mk" line 101: . ${i}: inner +make: "directive-for-escape.mk" line 102: . ${i:M*}: inner +make: "directive-for-escape.mk" line 103: . $(i): inner +make: "directive-for-escape.mk" line 104: . $(i:M*): inner +make: "directive-for-escape.mk" line 105: . ${i${:U}}: outer +make: "directive-for-escape.mk" line 106: . ${i\}}: inner} +make: "directive-for-escape.mk" line 107: . ${i2}: two +make: "directive-for-escape.mk" line 108: . ${i,}: comma +make: "directive-for-escape.mk" line 109: . adjacent: innerinnerinnerinner exit status 0 Index: src/usr.bin/make/unit-tests/directive-for-escape.mk diff -u src/usr.bin/make/unit-tests/directive-for-escape.mk:1.4 src/usr.bin/make/unit-tests/directive-for-escape.mk:1.5 --- src/usr.bin/make/unit-tests/directive-for-escape.mk:1.4 Sun Jan 24 19:30:18 2021 +++ src/usr.bin/make/unit-tests/directive-for-escape.mk Sun Jan 24 19:48:11 2021 @@ -1,4 +1,4 @@ -# $NetBSD: directive-for-escape.mk,v 1.4 2021/01/24 19:30:18 rillig Exp $ +# $NetBSD: directive-for-escape.mk,v 1.5 2021/01/24 19:48:11 rillig Exp $ # # Test escaping of special characters in the iteration values of a .for loop. # These values get expanded later using the :U variable modifier, and this @@ -41,17 +41,31 @@ VALUES= $$ $${V} $${V:=-with-modifier} . info $i .endfor -# Cover the code for nested '{}' in for_var_len. +# Try to cover the code for nested '{}' in for_var_len, without success. # -# The value of VALUES is not a variable expression. Instead, it is meant to -# represent dollar, lbrace, "UNDEF:U", backslash, dollar, backslash, dollar, -# space, nested braces, space, "end}". +# The value of VALUES is not meant to be a variable expression. Instead, it +# is meant to represent dollar, lbrace, "UNDEF:U", backslash, dollar, +# backslash, dollar, space, nested braces, space, "end}". +# +# The .for loop splits ${VALUES} into 3 words, at the space characters, since +# these are not escaped. VALUES= $${UNDEF:U\$$\$$ {{}} end} # XXX: Where does the '\$$\$$' get converted into a single '\$'? .for i in ${VALUES} . info $i .endfor +# Second try to cover the code for nested '{}' in for_var_len. +# +# XXX: It is wrong that for_var_len requires the braces to be balanced. +# Each variable modifier has its own inconsistent way of parsing nested +# variable expressions, braces and parentheses. The only sensible thing +# to do is therefore to let Var_Parse do all the parsing work. +VALUES= begin<$${UNDEF:Ufallback:N{{{}}}}>end +.for i in ${VALUES} +. info $i +.endfor + # A single trailing dollar doesn't happen in practice. # The dollar sign is correctly passed through to the body of the .for loop. # There, it is expanded by the .info directive, but even there a trailing