Module Name:    src
Committed By:   rillig
Date:           Sat Oct  3 10:31:05 UTC 2020

Modified Files:
        src/usr.bin/make: var.c
        src/usr.bin/make/unit-tests: make-exported.exp make-exported.mk

Log Message:
make(1): do not export variable names starting with '-'

By convention, names of environment variables consist of uppercase
letters and underscores.  Most of them start with an uppercase letter.
In a few cases, the names also contain lowercase letters, such as in
http_proxy.

Variable names starting with a hyphen are confusing and might be
mistaken as command line options.  Therefore don't export these.

This also affects a few edge cases that don't occur in practice, such as
setting .MAKE.EXPORTED=-env or .MAKE.EXPORTED=-literal.  These had not
worked as expected anyway.


To generate a diff of this commit:
cvs rdiff -u -r1.557 -r1.558 src/usr.bin/make/var.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/make-exported.exp \
    src/usr.bin/make/unit-tests/make-exported.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/var.c
diff -u src/usr.bin/make/var.c:1.557 src/usr.bin/make/var.c:1.558
--- src/usr.bin/make/var.c:1.557	Sat Oct  3 10:13:39 2020
+++ src/usr.bin/make/var.c	Sat Oct  3 10:31:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.557 2020/10/03 10:13:39 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.558 2020/10/03 10:31:05 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -121,7 +121,7 @@
 #include    "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.557 2020/10/03 10:13:39 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.558 2020/10/03 10:31:05 rillig Exp $");
 
 #define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
 #define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
@@ -470,6 +470,8 @@ Var_Export1(const char *name, VarExportF
 
     if (name[0] == '.')
 	return FALSE;		/* skip internals */
+    if (name[0] == '-')
+	return FALSE;		/* skip misnamed variables */
     if (name[1] == '\0') {
 	/*
 	 * A single char.

Index: src/usr.bin/make/unit-tests/make-exported.exp
diff -u src/usr.bin/make/unit-tests/make-exported.exp:1.2 src/usr.bin/make/unit-tests/make-exported.exp:1.3
--- src/usr.bin/make/unit-tests/make-exported.exp:1.2	Sat Oct  3 09:48:40 2020
+++ src/usr.bin/make/unit-tests/make-exported.exp	Sat Oct  3 10:31:05 2020
@@ -1,3 +1,2 @@
--literal=make-exported-value-literal
 UT_VAR=
 exit status 0
Index: src/usr.bin/make/unit-tests/make-exported.mk
diff -u src/usr.bin/make/unit-tests/make-exported.mk:1.2 src/usr.bin/make/unit-tests/make-exported.mk:1.3
--- src/usr.bin/make/unit-tests/make-exported.mk:1.2	Sat Oct  3 09:48:40 2020
+++ src/usr.bin/make/unit-tests/make-exported.mk	Sat Oct  3 10:31:05 2020
@@ -1,4 +1,4 @@
-# $NetBSD: make-exported.mk,v 1.2 2020/10/03 09:48:40 rillig Exp $
+# $NetBSD: make-exported.mk,v 1.3 2020/10/03 10:31:05 rillig Exp $
 #
 # As of 2020-08-09, the code in Var_Export is shared between the .export
 # directive and the .MAKE.EXPORTED variable.  This leads to non-obvious
@@ -23,6 +23,8 @@ UT_VAR=		${UNEXPANDED}
 # Var_ExportVars is called, which treats "-literal" as an ordinary variable
 # name, therefore exports it and also overwrites the previously exported
 # UT_VAR with the expanded value.
+#
+# Since 2020-10-03, the "variable" named "-literal" is not exported anymore.
 .MAKE.EXPORTED=		-literal UT_VAR
 
 all:

Reply via email to