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 make: add test for cmdline variables...



details:   https://anonhg.NetBSD.org/src/rev/d100b1ef8f31
branches:  trunk
changeset: 952979:d100b1ef8f31
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Feb 22 22:04:28 2021 +0000

description:
make: add test for cmdline variables overriding global variables

diffstat:

 usr.bin/make/unit-tests/var-class-cmdline.exp |   3 ++
 usr.bin/make/unit-tests/var-class-cmdline.mk  |  36 +++++++++++++++++++++++---
 2 files changed, 34 insertions(+), 5 deletions(-)

diffs (51 lines):

diff -r 285de65ab7be -r d100b1ef8f31 usr.bin/make/unit-tests/var-class-cmdline.exp
--- a/usr.bin/make/unit-tests/var-class-cmdline.exp     Mon Feb 22 21:43:57 2021 +0000
+++ b/usr.bin/make/unit-tests/var-class-cmdline.exp     Mon Feb 22 22:04:28 2021 +0000
@@ -1,1 +1,4 @@
+make: "var-class-cmdline.mk" line 23: global
+make: "var-class-cmdline.mk" line 30: makeflags
+makeflags
 exit status 0
diff -r 285de65ab7be -r d100b1ef8f31 usr.bin/make/unit-tests/var-class-cmdline.mk
--- a/usr.bin/make/unit-tests/var-class-cmdline.mk      Mon Feb 22 21:43:57 2021 +0000
+++ b/usr.bin/make/unit-tests/var-class-cmdline.mk      Mon Feb 22 22:04:28 2021 +0000
@@ -1,8 +1,34 @@
-# $NetBSD: var-class-cmdline.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: var-class-cmdline.mk,v 1.3 2021/02/22 22:04:28 rillig Exp $
 #
 # Tests for variables specified on the command line.
-
-# TODO: Implementation
+#
+# Variables that are specified on the command line override those from the
+# global scope.
+#
+# For performance reasons, variable lookup often starts in the global scope
+# since that is where most practically used variables are stored.  But even
+# in these cases, variables from the command line scope must override the
+# global variables.  Therefore, whenever a global variable is tried to be
+# set, it is ignored when there is already a variable of the same name in
+# the cmdline scope.  In the same vein, when a cmdline variable is set and
+# there is already a variable of the same name in the global scope, that
+# global variable is deleted first.
+#
+# 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.
 
-all:
-       @:;
+# 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 way to
+# undefine a cmdline variable, there is no need to remember the old value
+# of the global variable could become visible again.
+.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



Home | Main Index | Thread Index | Old Index