Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make/unit-tests Unit test for local variables



details:   https://anonhg.NetBSD.org/src/rev/d983bb751524
branches:  trunk
changeset: 359842:d983bb751524
user:      sjg <sjg%NetBSD.org@localhost>
date:      Thu Jan 27 06:56:27 2022 +0000

description:
Unit test for local variables

diffstat:

 usr.bin/make/unit-tests/var-scope-local.exp |   9 ++++++-
 usr.bin/make/unit-tests/var-scope-local.mk  |  33 ++++++++++++++++++++++++----
 2 files changed, 35 insertions(+), 7 deletions(-)

diffs (71 lines):

diff -r 0797646aa942 -r d983bb751524 usr.bin/make/unit-tests/var-scope-local.exp
--- a/usr.bin/make/unit-tests/var-scope-local.exp       Thu Jan 27 06:02:59 2022 +0000
+++ b/usr.bin/make/unit-tests/var-scope-local.exp       Thu Jan 27 06:56:27 2022 +0000
@@ -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
diff -r 0797646aa942 -r d983bb751524 usr.bin/make/unit-tests/var-scope-local.mk
--- a/usr.bin/make/unit-tests/var-scope-local.mk        Thu Jan 27 06:02:59 2022 +0000
+++ b/usr.bin/make/unit-tests/var-scope-local.mk        Thu Jan 27 06:56:27 2022 +0000
@@ -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 @@
 
 .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 @@
 
        # 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



Home | Main Index | Thread Index | Old Index