Module Name: src Committed By: rillig Date: Tue Aug 23 21:13:47 UTC 2022
Modified Files: src/usr.bin/make/unit-tests: varmod-loop.exp varmod-loop.mk Log Message: tests/make: document how the modifier ':@' works To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/make/unit-tests/varmod-loop.exp cvs rdiff -u -r1.20 -r1.21 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/varmod-loop.exp diff -u src/usr.bin/make/unit-tests/varmod-loop.exp:1.17 src/usr.bin/make/unit-tests/varmod-loop.exp:1.18 --- src/usr.bin/make/unit-tests/varmod-loop.exp:1.17 Tue Aug 23 19:22:01 2022 +++ src/usr.bin/make/unit-tests/varmod-loop.exp Tue Aug 23 21:13:46 2022 @@ -14,4 +14,9 @@ mod-loop-dollar:$${word}$$: mod-loop-dollar:$$5$$: mod-loop-dollar:$$${word}$$$: : t=$(( ${t:-0} + 1 )) +: dollar=end +: backslash=\ end +: dollar=$ at=@ backslash=\ end +: dollar=$$ at=@@ backslash=\\ end +: dollar=$$ at=@@ backslash=\\ end exit status 0 Index: src/usr.bin/make/unit-tests/varmod-loop.mk diff -u src/usr.bin/make/unit-tests/varmod-loop.mk:1.20 src/usr.bin/make/unit-tests/varmod-loop.mk:1.21 --- src/usr.bin/make/unit-tests/varmod-loop.mk:1.20 Tue Aug 23 19:22:01 2022 +++ src/usr.bin/make/unit-tests/varmod-loop.mk Tue Aug 23 21:13:46 2022 @@ -1,4 +1,4 @@ -# $NetBSD: varmod-loop.mk,v 1.20 2022/08/23 19:22:01 rillig Exp $ +# $NetBSD: varmod-loop.mk,v 1.21 2022/08/23 21:13:46 rillig Exp $ # # Tests for the :@var@...${var}...@ variable modifier. @@ -199,4 +199,36 @@ varmod-loop-literal-dollar: .PHONY : ${:U1:@i@ t=$$(( $${t:-0} + $i ))@} +# When parsing the loop body, each '\$', '\@' and '\\' is unescaped to '$', +# '@' and '\'; all other backslashes are retained. +# +# In practice, the '$' is not escaped as '\$', as there is a second round of +# unescaping '$$' to '$' later when the loop body is expanded after setting the +# iteration variable. +# +# After the iteration variable has been set, the loop body is expanded with +# this unescaping, regardless of whether .MAKE.SAVE_DOLLARS is set or not: +# $$ a literal '$' +# $x, ${var}, $(var) a nested expression +# any other character itself +all: escape-modifier +escape-modifier: .PHONY + # In the first round, '\$ ' is unescaped to '$ ', and since the + # variable named ' ' is not defined, the expression '$ ' expands to an + # empty string. + # expect: : dollar=end + : ${:U1:@i@ dollar=\$ end@} + + # Like in other modifiers, '\ ' is preserved, since ' ' is not one of + # the characters that _must_ be escaped. + # expect: : backslash=\ end + : ${:U1:@i@ backslash=\ end@} + + # expect: : dollar=$ at=@ backslash=\ end + : ${:U1:@i@ dollar=\$\$ at=\@ backslash=\\ end@} + # expect: : dollar=$$ at=@@ backslash=\\ end + : ${:U1:@i@ dollar=\$\$\$\$ at=\@\@ backslash=\\\\ end@} + # expect: : dollar=$$ at=@@ backslash=\\ end + : ${:U1:@i@ dollar=$$$$ at=\@\@ backslash=\\\\ end@} + all: .PHONY