Module Name:    src
Committed By:   sjg
Date:           Thu Jan 27 06:56:27 UTC 2022

Modified Files:
        src/usr.bin/make/unit-tests: var-scope-local.exp var-scope-local.mk

Log Message:
Unit test for local variables


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/var-scope-local.exp \
    src/usr.bin/make/unit-tests/var-scope-local.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/var-scope-local.exp
diff -u src/usr.bin/make/unit-tests/var-scope-local.exp:1.1 src/usr.bin/make/unit-tests/var-scope-local.exp:1.2
--- src/usr.bin/make/unit-tests/var-scope-local.exp:1.1	Sun Jan 23 16:25:54 2022
+++ src/usr.bin/make/unit-tests/var-scope-local.exp	Thu Jan 27 06:56:27 2022
@@ -1,5 +1,10 @@
 : 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
+: Making basename "var-scope-local.o" in "." from "var-scope-local.c" in "." VAR="local".
+: Making var-scope-local2.c out of nothing.
+: Making var-scope-local2.o from var-scope-local2.c.
+: Making basename "var-scope-local2.o" in "." from "var-scope-local2.c" in "." VAR="local to var-scope-local2.o".
+: Making var-scope-local3.c out of nothing.
+: var-scope-local3.o uses .USE VAR="global+local"
+: all overwritten VAR="global"
 exit status 0
Index: src/usr.bin/make/unit-tests/var-scope-local.mk
diff -u src/usr.bin/make/unit-tests/var-scope-local.mk:1.1 src/usr.bin/make/unit-tests/var-scope-local.mk:1.2
--- src/usr.bin/make/unit-tests/var-scope-local.mk:1.1	Sun Jan 23 16:25:54 2022
+++ src/usr.bin/make/unit-tests/var-scope-local.mk	Thu Jan 27 06:56:27 2022
@@ -1,4 +1,4 @@
-# $NetBSD: var-scope-local.mk,v 1.1 2022/01/23 16:25:54 rillig Exp $
+# $NetBSD: var-scope-local.mk,v 1.2 2022/01/27 06:56:27 sjg Exp $
 #
 # Tests for target-local variables, such as ${.TARGET} or $@.
 
@@ -28,7 +28,7 @@ all:
 
 .SUFFIXES: .c .o
 
-var-scope-local.c:
+var-scope-local.c var-scope-local2.c var-scope-local3.c:
 	: Making ${.TARGET} out of nothing.
 
 .c.o:
@@ -36,10 +36,33 @@ var-scope-local.c:
 
 	# 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}".
+	: Making basename "${@F}" in "${@D}" from "${<F}" in "${<D}" VAR="${VAR}".
 
-all: var-scope-local.o
+all: var-scope-local.o var-scope-local2.o var-scope-local3.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}
+	: ${.TARGET} ${.TARGET::=overwritten}${.TARGET} VAR="${VAR}"
+
+# we can set variables per target with some limitations
+.MAKE.TARGET_LOCAL_VARIABLES= yes
+VAR= global
+# the rest of the line is the value
+var-scope-local.o: VAR= local
+# += will *not* take global value and add to it in local context
+var-scope-local2.o: VAR+= local
+# but once defined in local context += behaves as expected.
+var-scope-local2.o: VAR += to ${.TARGET}
+# we can get the global value though
+# so complex values can always be set via global variable and then
+# assigned to local context
+# Note: that the global ${VAR} is expanded at this point
+# just as with any dependency line.
+var-scope-local3.o: VAR= ${VAR}+local
+
+# while VAR=use will be set for a .USE node, it will never be seen
+# since only the ultimate target's context is searched
+a_use: .USE VAR=use
+	: ${.TARGET} uses .USE VAR="${VAR}"
+
+var-scope-local3.o: a_use

Reply via email to