Module Name: src Committed By: rillig Date: Sun Jan 23 16:25:54 UTC 2022
Modified Files: src/distrib/sets/lists/tests: mi src/usr.bin/make/unit-tests: Makefile Added Files: src/usr.bin/make/unit-tests: var-scope-cmdline.exp var-scope-cmdline.mk var-scope-env.exp var-scope-env.mk var-scope-global.exp var-scope-global.mk var-scope-local-legacy.exp var-scope-local-legacy.mk var-scope-local.exp var-scope-local.mk var-scope.exp var-scope.mk Removed Files: src/usr.bin/make/unit-tests: var-class-cmdline.exp var-class-cmdline.mk var-class-env.exp var-class-env.mk var-class-global.exp var-class-global.mk var-class-local-legacy.exp var-class-local-legacy.mk var-class-local.exp var-class-local.mk var-class.exp var-class.mk Log Message: tests/make: rename var-class to var-scope There is no such concept as a "variable class" in make, these tests focus on the variable scope instead. To generate a diff of this commit: cvs rdiff -u -r1.1183 -r1.1184 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.298 -r1.299 src/usr.bin/make/unit-tests/Makefile cvs rdiff -u -r1.4 -r0 src/usr.bin/make/unit-tests/var-class-cmdline.exp cvs rdiff -u -r1.5 -r0 src/usr.bin/make/unit-tests/var-class-cmdline.mk \ src/usr.bin/make/unit-tests/var-class-local.mk cvs rdiff -u -r1.1 -r0 src/usr.bin/make/unit-tests/var-class-env.exp \ src/usr.bin/make/unit-tests/var-class-global.exp \ src/usr.bin/make/unit-tests/var-class-local-legacy.exp \ src/usr.bin/make/unit-tests/var-class.exp cvs rdiff -u -r1.2 -r0 src/usr.bin/make/unit-tests/var-class-env.mk \ src/usr.bin/make/unit-tests/var-class-local-legacy.mk \ src/usr.bin/make/unit-tests/var-class.mk cvs rdiff -u -r1.3 -r0 src/usr.bin/make/unit-tests/var-class-global.mk \ src/usr.bin/make/unit-tests/var-class-local.exp cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/var-scope-cmdline.exp \ src/usr.bin/make/unit-tests/var-scope-cmdline.mk \ src/usr.bin/make/unit-tests/var-scope-env.exp \ src/usr.bin/make/unit-tests/var-scope-env.mk \ src/usr.bin/make/unit-tests/var-scope-global.exp \ src/usr.bin/make/unit-tests/var-scope-global.mk \ src/usr.bin/make/unit-tests/var-scope-local-legacy.exp \ src/usr.bin/make/unit-tests/var-scope-local-legacy.mk \ src/usr.bin/make/unit-tests/var-scope-local.exp \ src/usr.bin/make/unit-tests/var-scope-local.mk \ src/usr.bin/make/unit-tests/var-scope.exp \ src/usr.bin/make/unit-tests/var-scope.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.1183 src/distrib/sets/lists/tests/mi:1.1184 --- src/distrib/sets/lists/tests/mi:1.1183 Sun Jan 23 16:09:38 2022 +++ src/distrib/sets/lists/tests/mi Sun Jan 23 16:25:53 2022 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1183 2022/01/23 16:09:38 rillig Exp $ +# $NetBSD: mi,v 1.1184 2022/01/23 16:25:53 rillig Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -5931,18 +5931,18 @@ ./usr/tests/usr.bin/make/unit-tests/unexport.mk tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/use-inference.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/use-inference.mk tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/make/unit-tests/var-class-cmdline.exp tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/make/unit-tests/var-class-cmdline.mk tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/make/unit-tests/var-class-env.exp tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/make/unit-tests/var-class-env.mk tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/make/unit-tests/var-class-global.exp tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/make/unit-tests/var-class-global.mk tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/make/unit-tests/var-class-local-legacy.exp tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/make/unit-tests/var-class-local-legacy.mk tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/make/unit-tests/var-class-local.exp tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/make/unit-tests/var-class-local.mk tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/make/unit-tests/var-class.exp tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/make/unit-tests/var-class.mk tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/make/unit-tests/var-class-cmdline.exp tests-obsolete obsolete,atf +./usr/tests/usr.bin/make/unit-tests/var-class-cmdline.mk tests-obsolete obsolete,atf +./usr/tests/usr.bin/make/unit-tests/var-class-env.exp tests-obsolete obsolete,atf +./usr/tests/usr.bin/make/unit-tests/var-class-env.mk tests-obsolete obsolete,atf +./usr/tests/usr.bin/make/unit-tests/var-class-global.exp tests-obsolete obsolete,atf +./usr/tests/usr.bin/make/unit-tests/var-class-global.mk tests-obsolete obsolete,atf +./usr/tests/usr.bin/make/unit-tests/var-class-local-legacy.exp tests-obsolete obsolete,atf +./usr/tests/usr.bin/make/unit-tests/var-class-local-legacy.mk tests-obsolete obsolete,atf +./usr/tests/usr.bin/make/unit-tests/var-class-local.exp tests-obsolete obsolete,atf +./usr/tests/usr.bin/make/unit-tests/var-class-local.mk tests-obsolete obsolete,atf +./usr/tests/usr.bin/make/unit-tests/var-class.exp tests-obsolete obsolete,atf +./usr/tests/usr.bin/make/unit-tests/var-class.mk tests-obsolete obsolete,atf ./usr/tests/usr.bin/make/unit-tests/var-eval-short.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/var-eval-short.mk tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/var-op-append.exp tests-usr.bin-tests compattestfile,atf @@ -5961,6 +5961,18 @@ ./usr/tests/usr.bin/make/unit-tests/var-op.mk tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/var-recursive.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/var-recursive.mk tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/make/unit-tests/var-scope-cmdline.exp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/make/unit-tests/var-scope-cmdline.mk tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/make/unit-tests/var-scope-env.exp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/make/unit-tests/var-scope-env.mk tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/make/unit-tests/var-scope-global.exp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/make/unit-tests/var-scope-global.mk tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/make/unit-tests/var-scope-local-legacy.exp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/make/unit-tests/var-scope-local-legacy.mk tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/make/unit-tests/var-scope-local.exp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/make/unit-tests/var-scope-local.mk tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/make/unit-tests/var-scope.exp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/make/unit-tests/var-scope.mk tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/varcmd.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/varcmd.mk tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/make/unit-tests/vardebug.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.298 src/usr.bin/make/unit-tests/Makefile:1.299 --- src/usr.bin/make/unit-tests/Makefile:1.298 Sun Jan 23 16:09:38 2022 +++ src/usr.bin/make/unit-tests/Makefile Sun Jan 23 16:25:54 2022 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.298 2022/01/23 16:09:38 rillig Exp $ +# $NetBSD: Makefile,v 1.299 2022/01/23 16:25:54 rillig Exp $ # # Unit tests for make(1) # @@ -320,12 +320,12 @@ TESTS+= ternary TESTS+= unexport TESTS+= unexport-env TESTS+= use-inference -TESTS+= var-class -TESTS+= var-class-cmdline -TESTS+= var-class-env -TESTS+= var-class-global -TESTS+= var-class-local -TESTS+= var-class-local-legacy +TESTS+= var-scope +TESTS+= var-scope-cmdline +TESTS+= var-scope-env +TESTS+= var-scope-global +TESTS+= var-scope-local +TESTS+= var-scope-local-legacy TESTS+= var-eval-short TESTS+= var-op TESTS+= var-op-append Added files: Index: src/usr.bin/make/unit-tests/var-scope-cmdline.exp diff -u /dev/null src/usr.bin/make/unit-tests/var-scope-cmdline.exp:1.1 --- /dev/null Sun Jan 23 16:25:54 2022 +++ src/usr.bin/make/unit-tests/var-scope-cmdline.exp Sun Jan 23 16:25:54 2022 @@ -0,0 +1,4 @@ +make: "var-scope-cmdline.mk" line 67: global +make: "var-scope-cmdline.mk" line 76: makeflags +makeflags +exit status 0 Index: src/usr.bin/make/unit-tests/var-scope-cmdline.mk diff -u /dev/null src/usr.bin/make/unit-tests/var-scope-cmdline.mk:1.1 --- /dev/null Sun Jan 23 16:25:54 2022 +++ src/usr.bin/make/unit-tests/var-scope-cmdline.mk Sun Jan 23 16:25:54 2022 @@ -0,0 +1,80 @@ +# $NetBSD: var-scope-cmdline.mk,v 1.1 2022/01/23 16:25:54 rillig Exp $ +# +# Tests for variables specified on the command line. +# +# Variables that are specified on the command line override those from the +# global scope. +# +# For performance reasons, the actual implementation is more complex than the +# above single-sentence rule, in order to avoid unnecessary lookups in scopes, +# which before var.c 1.586 from 2020-10-25 calculated the hash value of the +# variable name once for each lookup. Instead, when looking up the value of +# a variable, the search often starts in the global scope since that is where +# most of the variables are stored. This conflicts with the statement that +# variables from the cmdline scope override global variables, since after the +# common case of finding a variable in the global scope, another lookup would +# be needed in the cmdline scope to ensure that there is no overriding +# variable there. +# +# Instead of this costly lookup scheme, make implements it in a different +# way: +# +# Whenever a global variable is created, this creation is ignored if +# there is a cmdline variable of the same name. +# +# Whenever a cmdline variable is created, any global variable of the +# same name is deleted. +# +# Whenever a global variable is deleted, nothing special happens. +# +# Deleting a cmdline variable is not possible. +# +# These 4 rules provide the guarantee that whenever a global variable exists, +# there cannot be a cmdline variable of the same name. Therefore, after +# finding a variable in the global scope, no additional lookup is needed in +# the cmdline scope. +# +# The above ruleset provides the same guarantees as the simple rule "cmdline +# overrides global". Due to an implementation mistake, the actual behavior +# was not entirely equivalent to the simple rule though. The mistake was +# that when a cmdline variable with '$$' in its name was added, a global +# variable was deleted, but not with the exact same name as the cmdline +# variable. Instead, the name of the global variable was expanded one more +# time than the name of the cmdline variable. For variable names that didn't +# have a '$$' in their name, it was implemented correctly all the time. +# +# The bug was added in var.c 1.183 on 2013-07-16, when Var_Set called +# Var_Delete to delete the global variable. Just two months earlier, in var.c +# 1.174 from 2013-05-18, Var_Delete had started to expand the variable name. +# Together, these two changes made the variable name be expanded twice in a +# row. This bug was fixed in var.c 1.835 from 2021-02-22. +# +# Another bug was the wrong assumption that "deleting a cmdline variable is +# not possible". Deleting such a variable has been possible since var.c 1.204 +# from 2016-02-19, when the variable modifier ':@' started to delete the +# temporary loop variable after finishing the loop. It was probably not +# intended back then that a side effect of this seemingly simple change was +# that both global and cmdline variables could now be undefined at will as a +# side effect of evaluating a variable expression. As of 2021-02-23, this is +# still possible. +# +# Most cmdline variables are set at the very beginning, when parsing the +# command line arguments. Using the special target '.MAKEFLAGS', it is +# possible to set cmdline variables at any later time. + +# A normal global variable, without any cmdline variable nearby. +VAR= global +.info ${VAR} + +# The global variable is "overridden" by simply deleting it and then +# installing the cmdline variable instead. Since there is no obvious way to +# undefine a cmdline variable, there is no need to remember the old value +# of the global variable could become visible again. +# +# See varmod-loop.mk for a non-obvious way to undefine a cmdline variable. +.MAKEFLAGS: VAR=makeflags +.info ${VAR} + +# If Var_SetWithFlags should ever forget to delete the global variable, +# the below line would print "global" instead of the current "makeflags". +.MAKEFLAGS: -V VAR Index: src/usr.bin/make/unit-tests/var-scope-env.exp diff -u /dev/null src/usr.bin/make/unit-tests/var-scope-env.exp:1.1 --- /dev/null Sun Jan 23 16:25:54 2022 +++ src/usr.bin/make/unit-tests/var-scope-env.exp Sun Jan 23 16:25:54 2022 @@ -0,0 +1 @@ +exit status 0 Index: src/usr.bin/make/unit-tests/var-scope-env.mk diff -u /dev/null src/usr.bin/make/unit-tests/var-scope-env.mk:1.1 --- /dev/null Sun Jan 23 16:25:54 2022 +++ src/usr.bin/make/unit-tests/var-scope-env.mk Sun Jan 23 16:25:54 2022 @@ -0,0 +1,8 @@ +# $NetBSD: var-scope-env.mk,v 1.1 2022/01/23 16:25:54 rillig Exp $ +# +# Tests for variables specified in the process environment. + +# TODO: Implementation + +all: + @:; Index: src/usr.bin/make/unit-tests/var-scope-global.exp diff -u /dev/null src/usr.bin/make/unit-tests/var-scope-global.exp:1.1 --- /dev/null Sun Jan 23 16:25:54 2022 +++ src/usr.bin/make/unit-tests/var-scope-global.exp Sun Jan 23 16:25:54 2022 @@ -0,0 +1 @@ +exit status 0 Index: src/usr.bin/make/unit-tests/var-scope-global.mk diff -u /dev/null src/usr.bin/make/unit-tests/var-scope-global.mk:1.1 --- /dev/null Sun Jan 23 16:25:54 2022 +++ src/usr.bin/make/unit-tests/var-scope-global.mk Sun Jan 23 16:25:54 2022 @@ -0,0 +1,18 @@ +# $NetBSD: var-scope-global.mk,v 1.1 2022/01/23 16:25:54 rillig Exp $ +# +# Tests for global variables, which are the most common variables. + +# Global variables can be assigned and appended to. +GLOBAL= value +GLOBAL+= addition +.if ${GLOBAL} != "value addition" +. error +.endif + +# Global variables can be removed from their scope. +.undef GLOBAL +.if defined(GLOBAL) +. error +.endif + +all: .PHONY Index: src/usr.bin/make/unit-tests/var-scope-local-legacy.exp diff -u /dev/null src/usr.bin/make/unit-tests/var-scope-local-legacy.exp:1.1 --- /dev/null Sun Jan 23 16:25:54 2022 +++ src/usr.bin/make/unit-tests/var-scope-local-legacy.exp Sun Jan 23 16:25:54 2022 @@ -0,0 +1 @@ +exit status 0 Index: src/usr.bin/make/unit-tests/var-scope-local-legacy.mk diff -u /dev/null src/usr.bin/make/unit-tests/var-scope-local-legacy.mk:1.1 --- /dev/null Sun Jan 23 16:25:54 2022 +++ src/usr.bin/make/unit-tests/var-scope-local-legacy.mk Sun Jan 23 16:25:54 2022 @@ -0,0 +1,8 @@ +# $NetBSD: var-scope-local-legacy.mk,v 1.1 2022/01/23 16:25:54 rillig Exp $ +# +# Tests for legacy target-local variables, such as ${<F} or ${@D}. + +# TODO: Implementation + +all: + @:; Index: src/usr.bin/make/unit-tests/var-scope-local.exp diff -u /dev/null src/usr.bin/make/unit-tests/var-scope-local.exp:1.1 --- /dev/null Sun Jan 23 16:25:54 2022 +++ src/usr.bin/make/unit-tests/var-scope-local.exp Sun Jan 23 16:25:54 2022 @@ -0,0 +1,5 @@ +: Making var-scope-local.c out of nothing. +: Making var-scope-local.o from var-scope-local.c. +: Making basename "var-scope-local.o" in "." from "var-scope-local.c" in ".". +: all overwritten +exit status 0 Index: src/usr.bin/make/unit-tests/var-scope-local.mk diff -u /dev/null src/usr.bin/make/unit-tests/var-scope-local.mk:1.1 --- /dev/null Sun Jan 23 16:25:54 2022 +++ src/usr.bin/make/unit-tests/var-scope-local.mk Sun Jan 23 16:25:54 2022 @@ -0,0 +1,45 @@ +# $NetBSD: var-scope-local.mk,v 1.1 2022/01/23 16:25:54 rillig Exp $ +# +# Tests for target-local variables, such as ${.TARGET} or $@. + +# TODO: Implementation + +# Ensure that the name of the variable is exactly the given one. +# The variable "@" is an alias for ".TARGET", so the implementation might +# canonicalize these aliases at some point, and that might be surprising. +# This aliasing happens for single-character variable names like $@ or $< +# (see VarFind, CanonicalVarname), but not for braced or parenthesized +# expressions like ${@}, ${.TARGET} ${VAR:Mpattern} (see Var_Parse, +# ParseVarname). +.if ${@:L} != "@" +. error +.endif +.if ${.TARGET:L} != ".TARGET" +. error +.endif +.if ${@F:L} != "@F" +. error +.endif +.if ${@D:L} != "@D" +. error +.endif + +all: + +.SUFFIXES: .c .o + +var-scope-local.c: + : Making ${.TARGET} out of nothing. + +.c.o: + : Making ${.TARGET} from ${.IMPSRC}. + + # The local variables @F, @D, <F, <D are legacy forms. + # See the manual page for details. + : Making basename "${@F}" in "${@D}" from "${<F}" in "${<D}". + +all: var-scope-local.o + # The ::= modifier overwrites the .TARGET variable in the node + # 'all', not in the global scope. This can be seen with the -dv + # option, looking for "all:@ = overwritten". + : ${.TARGET} ${.TARGET::=overwritten}${.TARGET} Index: src/usr.bin/make/unit-tests/var-scope.exp diff -u /dev/null src/usr.bin/make/unit-tests/var-scope.exp:1.1 --- /dev/null Sun Jan 23 16:25:54 2022 +++ src/usr.bin/make/unit-tests/var-scope.exp Sun Jan 23 16:25:54 2022 @@ -0,0 +1 @@ +exit status 0 Index: src/usr.bin/make/unit-tests/var-scope.mk diff -u /dev/null src/usr.bin/make/unit-tests/var-scope.mk:1.1 --- /dev/null Sun Jan 23 16:25:54 2022 +++ src/usr.bin/make/unit-tests/var-scope.mk Sun Jan 23 16:25:54 2022 @@ -0,0 +1,9 @@ +# $NetBSD: var-scope.mk,v 1.1 2022/01/23 16:25:54 rillig Exp $ +# +# Tests for the different variable scopes (local, command-line, global, +# environment), and which of them takes precedence over the others. + +# TODO: Implementation + +all: + @:;