Module Name:    src
Committed By:   rillig
Date:           Mon Feb 22 21:14:15 UTC 2021

Modified Files:
        src/usr.bin/make: var.c

Log Message:
make: document interaction between cmdline and global variables

Make prevents global variables from being or becoming visible when a
command line variable of the same name is already defined.

There is a double safety net here.  Even if the call to Var_DeleteExpand
were removed, there would be no noticeable effect, other than one less
line in the debug log.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.831 -r1.832 src/usr.bin/make/var.c

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/var.c
diff -u src/usr.bin/make/var.c:1.831 src/usr.bin/make/var.c:1.832
--- src/usr.bin/make/var.c:1.831	Tue Feb 16 19:46:15 2021
+++ src/usr.bin/make/var.c	Mon Feb 22 21:14:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.831 2021/02/16 19:46:15 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.832 2021/02/22 21:14:15 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.831 2021/02/16 19:46:15 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.832 2021/02/22 21:14:15 rillig Exp $");
 
 typedef enum VarFlags {
 	VFL_NONE	= 0,
@@ -945,6 +945,14 @@ Var_SetWithFlags(GNode *scope, const cha
 	if (scope == SCOPE_GLOBAL) {
 		v = VarFind(name, SCOPE_CMDLINE, FALSE);
 		if (v != NULL) {
+			/*
+			 * When there is a variable of the same name in the
+			 * command line scope, the global variable would not
+			 * be visible anywhere.  Therefore there is no point
+			 * in setting it at all.
+			 *
+			 * See 'scope == SCOPE_CMDLINE' below.
+			 */
 			if (v->flags & VFL_FROM_CMD) {
 				DEBUG3(VAR, "%s:%s = %s ignored!\n",
 				    scope->name, name, val);
@@ -966,6 +974,8 @@ Var_SetWithFlags(GNode *scope, const cha
 			 * This var would normally prevent the same name being
 			 * added to SCOPE_GLOBAL, so delete it from there if
 			 * needed. Otherwise -V name may show the wrong value.
+			 *
+			 * See 'scope == SCOPE_GLOBAL' above.
 			 */
 			/* XXX: name is expanded for the second time */
 			Var_DeleteExpand(SCOPE_GLOBAL, name);

Reply via email to