Module Name: src
Committed By: rillig
Date: Mon Feb 22 22:04:28 UTC 2021
Modified Files:
src/usr.bin/make/unit-tests: var-class-cmdline.exp var-class-cmdline.mk
Log Message:
make: add test for cmdline variables overriding global variables
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/var-class-cmdline.exp
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/var-class-cmdline.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-class-cmdline.exp
diff -u src/usr.bin/make/unit-tests/var-class-cmdline.exp:1.1 src/usr.bin/make/unit-tests/var-class-cmdline.exp:1.2
--- src/usr.bin/make/unit-tests/var-class-cmdline.exp:1.1 Sun Aug 16 12:07:51 2020
+++ src/usr.bin/make/unit-tests/var-class-cmdline.exp Mon Feb 22 22:04:28 2021
@@ -1 +1,4 @@
+make: "var-class-cmdline.mk" line 23: global
+make: "var-class-cmdline.mk" line 30: makeflags
+makeflags
exit status 0
Index: src/usr.bin/make/unit-tests/var-class-cmdline.mk
diff -u src/usr.bin/make/unit-tests/var-class-cmdline.mk:1.2 src/usr.bin/make/unit-tests/var-class-cmdline.mk:1.3
--- src/usr.bin/make/unit-tests/var-class-cmdline.mk:1.2 Sun Aug 16 14:25:16 2020
+++ src/usr.bin/make/unit-tests/var-class-cmdline.mk Mon Feb 22 22:04:28 2021
@@ -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.
+#
+# 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.
+
+# A normal global variable, without any cmdline variable nearby.
+VAR= global
+.info ${VAR}
-# TODO: Implementation
+# 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}
-all:
- @:;
+# 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