Module Name: src Committed By: rillig Date: Thu Dec 2 22:41:01 UTC 2021
Modified Files: src/usr.bin/make/unit-tests: varname-dot-make-save_dollars.mk Log Message: tests/make: fix test for .MAKE.SAVE_DOLLARS The previous assumption was wrong that only literal '$$' that occur directly in the right-hand side of a variable assignment would be affected. Indirect variable definitions are affected as well when they are evaluated nestedly, as long as the '$$' appears in the text of the variable that is actually parsed. Whether the '$$' ends up in the expanded value of the expression doesn't matter though. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 \ src/usr.bin/make/unit-tests/varname-dot-make-save_dollars.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/varname-dot-make-save_dollars.mk diff -u src/usr.bin/make/unit-tests/varname-dot-make-save_dollars.mk:1.5 src/usr.bin/make/unit-tests/varname-dot-make-save_dollars.mk:1.6 --- src/usr.bin/make/unit-tests/varname-dot-make-save_dollars.mk:1.5 Wed Dec 1 23:15:38 2021 +++ src/usr.bin/make/unit-tests/varname-dot-make-save_dollars.mk Thu Dec 2 22:41:01 2021 @@ -1,4 +1,4 @@ -# $NetBSD: varname-dot-make-save_dollars.mk,v 1.5 2021/12/01 23:15:38 rillig Exp $ +# $NetBSD: varname-dot-make-save_dollars.mk,v 1.6 2021/12/02 22:41:01 rillig Exp $ # # Tests for the special .MAKE.SAVE_DOLLARS variable, which controls whether # the assignment operator ':=' converts '$$' to a single '$' or keeps it @@ -17,8 +17,8 @@ .endif -# Even when dollars are preserved, it only applies to literal dollars, not -# to those that come indirectly from other expressions. +# When dollars are preserved, this setting not only applies to literal +# dollars, but also to those that come indirectly from other expressions. DOLLARS= $$$$$$$$ .MAKE.SAVE_DOLLARS= yes VAR:= ${DOLLARS} @@ -29,6 +29,15 @@ VAR:= ${DOLLARS} . error .endif +# When dollars are preserved, this setting not only applies to literal +# dollars, but also to those that come indirectly from other expressions. +DOLLARS= $$$$$$$$ +.MAKE.SAVE_DOLLARS= no +VAR:= ${DOLLARS} +.if ${VAR} != "\$\$" +. error +.endif + # The 'yes' preserves the dollars from the literal. .MAKE.SAVE_DOLLARS= yes VAR:= $$$$$$$$ @@ -51,8 +60,10 @@ VAR:= $$$$-${.MAKE.SAVE_DOLLARS::=yes}- . error .endif -# The '$' from the ':U' expressions are indirect, therefore .MAKE.SAVE_DOLLARS -# doesn't apply to them. +# The '$' from the ':U' expressions do not appear as literal '$$' to the +# parser (no matter whether directly or indirectly), they only appear as '$$' +# in the value of an expression, therefore .MAKE.SAVE_DOLLARS doesn't apply +# here. .MAKE.SAVE_DOLLARS= no VAR:= ${:U\$\$\$\$}-${.MAKE.SAVE_DOLLARS::=yes}-${:U\$\$\$\$} .if ${VAR} != "\$\$--\$\$" @@ -77,4 +88,24 @@ VAR:= $$$$$$$$ . error .endif +# The variable '.MAKE.SAVE_DOLLARS' not only affects literal '$$' on the +# right-hand side of the assignment operator ':=', it also affects dollars +# in indirect expressions. +# +# In this example, it affects the command in CMD itself, not the result of +# running that command. +.MAKE.SAVE_DOLLARS= no +CMD= echo '$$$$$$$$' +VAR:= ${CMD:sh} +.if ${VAR} != "\$\$" +. error +.endif + +.MAKE.SAVE_DOLLARS= yes +CMD= echo '$$$$$$$$' +VAR:= ${CMD:sh} +.if ${VAR} != "\$\$\$\$" +. error +.endif + all: