Module Name: src Committed By: rillig Date: Sun Dec 12 22:16:49 UTC 2021
Modified Files: src/distrib/sets/lists/tests: mi src/usr.bin/make/unit-tests: Makefile Added Files: src/usr.bin/make/unit-tests: varname-dot-suffixes.exp varname-dot-suffixes.mk Log Message: tests/make: test and document the newly added "variable" .SUFFIXES To generate a diff of this commit: cvs rdiff -u -r1.1175 -r1.1176 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.287 -r1.288 src/usr.bin/make/unit-tests/Makefile cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/varname-dot-suffixes.exp \ src/usr.bin/make/unit-tests/varname-dot-suffixes.mk Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.1175 src/distrib/sets/lists/tests/mi:1.1176 --- src/distrib/sets/lists/tests/mi:1.1175 Mon Dec 6 23:20:26 2021 +++ src/distrib/sets/lists/tests/mi Sun Dec 12 22:16:48 2021 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1175 2021/12/06 23:20:26 rillig Exp $ +# $NetBSD: mi,v 1.1176 2021/12/12 22:16:48 rillig Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -6121,6 +6121,8 @@ ./usr/tests/usr.bin/make/unit-tests/varname-dot-path.mk tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/varname-dot-shell.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/varname-dot-shell.mk tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/make/unit-tests/varname-dot-suffixes.exp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/make/unit-tests/varname-dot-suffixes.mk tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/varname-dot-targets.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/varname-dot-targets.mk tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/varname-empty.exp tests-usr.bin-tests compattestfile,atf Index: src/usr.bin/make/unit-tests/Makefile diff -u src/usr.bin/make/unit-tests/Makefile:1.287 src/usr.bin/make/unit-tests/Makefile:1.288 --- src/usr.bin/make/unit-tests/Makefile:1.287 Thu Dec 9 20:47:33 2021 +++ src/usr.bin/make/unit-tests/Makefile Sun Dec 12 22:16:48 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.287 2021/12/09 20:47:33 rillig Exp $ +# $NetBSD: Makefile,v 1.288 2021/12/12 22:16:48 rillig Exp $ # # Unit tests for make(1) # @@ -418,6 +418,7 @@ TESTS+= varname-dot-parsedir TESTS+= varname-dot-parsefile TESTS+= varname-dot-path TESTS+= varname-dot-shell +TESTS+= varname-dot-suffixes TESTS+= varname-dot-targets TESTS+= varname-empty TESTS+= varname-make @@ -444,7 +445,6 @@ TESTS:= ${TESTS:${BROKEN_TESTS:S,^,N,:ts # char-005C-backslash.mk # escape-cond-str.mk # escape-cond-func-arg.mk -# escape-cond-func-arg.mk # escape-varmod.mk # escape-varmod-define.mk # escape-varmod-match.mk Added files: Index: src/usr.bin/make/unit-tests/varname-dot-suffixes.exp diff -u /dev/null src/usr.bin/make/unit-tests/varname-dot-suffixes.exp:1.1 --- /dev/null Sun Dec 12 22:16:49 2021 +++ src/usr.bin/make/unit-tests/varname-dot-suffixes.exp Sun Dec 12 22:16:48 2021 @@ -0,0 +1,39 @@ +Global:delete .SUFFIXES (not found) +Global: .MAKEFLAGS = -r -k -d v -d +Global: .MAKEFLAGS = -r -k -d v -d 0 +Global: .SUFFIXES = set ignored (read-only) +Global: .SUFFIXES = append ignored (read-only) +Global: _ = +Var_Parse: ${.SUFFIXES::=assign} (eval-keep-dollar-and-undefined) +Evaluating modifier ${.SUFFIXES::...} on value ".c .o .1 .err .tar.gz" (eval-keep-dollar-and-undefined, regular) +Modifier part: "assign" +Global: .SUFFIXES = assign ignored (read-only) +Result of ${.SUFFIXES::=assign} is "" (eval-keep-dollar-and-undefined, regular) +Global: _ = +Var_Parse: ${preserve:L:_=.SUFFIXES} (eval-keep-dollar-and-undefined) +Evaluating modifier ${preserve:L} on value "" (eval-keep-dollar-and-undefined, undefined) +Result of ${preserve:L} is "preserve" (eval-keep-dollar-and-undefined, defined) +Evaluating modifier ${preserve:_...} on value "preserve" (eval-keep-dollar-and-undefined, defined) +Global: .SUFFIXES = preserve ignored (read-only) +Result of ${preserve:_=.SUFFIXES} is "preserve" (eval-keep-dollar-and-undefined, defined) +Global: _ = preserve +Global: .MAKEFLAGS = -r -k -d v -d 0 -d v -d +Global: .MAKEFLAGS = -r -k -d v -d 0 -d v -d 0 +Var_Parse: ${1 2:L:@.SUFFIXES@${.SUFFIXES}@} != ".c .o .1 .err .tar.gz .c .o .1 .err .tar.gz" (eval-defined) +Evaluating modifier ${1 2:L} on value "" (eval-defined, undefined) +Result of ${1 2:L} is "1 2" (eval-defined, defined) +Evaluating modifier ${1 2:@...} on value "1 2" (eval-defined, defined) +Modifier part: ".SUFFIXES" +Modifier part: "${.SUFFIXES}" +ModifyWords: split "1 2" into 2 words +Command: .SUFFIXES = 1 ignored (read-only) +Var_Parse: ${.SUFFIXES} (eval-defined) +ModifyWord_Loop: in "1", replace ".SUFFIXES" with "${.SUFFIXES}" to ".c .o .1 .err .tar.gz" +Command: .SUFFIXES = 2 ignored (read-only) +Var_Parse: ${.SUFFIXES} (eval-defined) +ModifyWord_Loop: in "2", replace ".SUFFIXES" with "${.SUFFIXES}" to ".c .o .1 .err .tar.gz" +Command:delete .SUFFIXES (not found) +Result of ${1 2:@.SUFFIXES@${.SUFFIXES}@} is ".c .o .1 .err .tar.gz .c .o .1 .err .tar.gz" (eval-defined, defined) +Global: .MAKEFLAGS = -r -k -d v -d 0 -d v -d 0 -d v -d +Global: .MAKEFLAGS = -r -k -d v -d 0 -d v -d 0 -d v -d 0 +exit status 0 Index: src/usr.bin/make/unit-tests/varname-dot-suffixes.mk diff -u /dev/null src/usr.bin/make/unit-tests/varname-dot-suffixes.mk:1.1 --- /dev/null Sun Dec 12 22:16:49 2021 +++ src/usr.bin/make/unit-tests/varname-dot-suffixes.mk Sun Dec 12 22:16:48 2021 @@ -0,0 +1,104 @@ +# $NetBSD: varname-dot-suffixes.mk,v 1.1 2021/12/12 22:16:48 rillig Exp $ +# +# Tests for the special "variable" .SUFFIXES, which lists the suffixes that +# have been registered for use in suffix transformation rules. Suffixes are +# listed even if there is no actual transformation rule that uses them. +# +# The name '.SUFFIXES' does not refer to a real variable, instead it can be +# used as a starting "variable name" for expressions like ${.SUFFIXES} or +# ${.SUFFIXES:M*o}. + +# In the beginning, there are no suffix rules, the expression is thus empty. +.if ${.SUFFIXES} != "" +.endif + +# There is no actual variable named '.SUFFIXES', it is all made up. +.if defined(.SUFFIXES) +. error +.endif + +# The suffixes list is still empty, and so is the "variable" '.SUFFIXES'. +.if !empty(.SUFFIXES) +. error +.endif + +.SUFFIXES: .c .o .1 .err + +# The suffixes are listed in declaration order. +.if ${.SUFFIXES} != ".c .o .1 .err" +. error +.endif + +# There is still no actual variable named '.SUFFIXES', it is all made up. +.if defined(.SUFFIXES) +. error +.endif + +# Now the suffixes list is not empty anymore. It may seem strange that there +# is no variable named '.SUFFIXES' but evaluating '${.SUFFIXES}' nevertheless +# returns something. For all practical use cases, it's good enough though. +.if empty(.SUFFIXES) +. error +.endif + +.SUFFIXES: .tar.gz + +# Changes to the suffixes list are reflected immediately. +.if ${.SUFFIXES} != ".c .o .1 .err .tar.gz" +. error +.endif + +# Deleting .SUFFIXES has no effect since there is no actual variable of that +# name. +.MAKEFLAGS: -dv +# expect: Global:delete .SUFFIXES (not found) +.undef .SUFFIXES +.MAKEFLAGS: -d0 +.if ${.SUFFIXES} != ".c .o .1 .err .tar.gz" +. error +.endif + +# The list of suffixes can only be modified using dependency declarations, any +# attempt at setting the variable named '.SUFFIXES' is rejected. +.MAKEFLAGS: -dv +# expect: Global: .SUFFIXES = set ignored (read-only) +.SUFFIXES= set +# expect: Global: .SUFFIXES = append ignored (read-only) +.SUFFIXES+= append +# expect: Global: .SUFFIXES = assign ignored (read-only) +_:= ${.SUFFIXES::=assign} +# expect: Command: .SUFFIXES = preserve ignored (read-only) +_:= ${preserve:L:_=.SUFFIXES} +.MAKEFLAGS: -d0 + +# Using the name '.SUFFIXES' in a .for loop looks strange because these +# variable names are typically in singular form, and .for loops do not use +# real variables either, they are made up as well, see directive-for.mk. The +# replacement mechanism for the iteration variables takes precedence. +.for .SUFFIXES in .c .o +. if ${.SUFFIXES} != ".c" && ${.SUFFIXES} != ".o" +. error +. endif +.endfor + +# After the .for loop, the expression '${.SUFFIXES}' refers to the list of +# suffixes again. +.if ${.SUFFIXES} != ".c .o .1 .err .tar.gz" +. error +.endif + +# Using the name '.SUFFIXES' in the modifier ':@var@body@' does not create an +# actual variable either. Like in the .for loop, choosing the name +# '.SUFFIXES' for the iteration variable is unusual. In ODE Make, the +# convention for these iteration variables is to have dots at both ends, so +# the name would be '.SUFFIXES.', furthermore the name of the iteration +# variable is typically in singular form. +.MAKEFLAGS: -dv +# expect: Command: .SUFFIXES = 1 ignored (read-only) +# expect: Command: .SUFFIXES = 2 ignored (read-only) +.if ${1 2:L:@.SUFFIXES@${.SUFFIXES}@} != ".c .o .1 .err .tar.gz .c .o .1 .err .tar.gz" +. error +.endif +.MAKEFLAGS: -d0 + +all: