Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make make(1): do not export variable names starting ...



details:   https://anonhg.NetBSD.org/src/rev/871b56f11349
branches:  trunk
changeset: 944538:871b56f11349
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Oct 03 10:31:05 2020 +0000

description:
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.

diffstat:

 usr.bin/make/unit-tests/make-exported.exp |  1 -
 usr.bin/make/unit-tests/make-exported.mk  |  4 +++-
 usr.bin/make/var.c                        |  6 ++++--
 3 files changed, 7 insertions(+), 4 deletions(-)

diffs (52 lines):

diff -r 2354188c63ae -r 871b56f11349 usr.bin/make/unit-tests/make-exported.exp
--- a/usr.bin/make/unit-tests/make-exported.exp Sat Oct 03 10:13:39 2020 +0000
+++ b/usr.bin/make/unit-tests/make-exported.exp Sat Oct 03 10:31:05 2020 +0000
@@ -1,3 +1,2 @@
--literal=make-exported-value-literal
 UT_VAR=
 exit status 0
diff -r 2354188c63ae -r 871b56f11349 usr.bin/make/unit-tests/make-exported.mk
--- a/usr.bin/make/unit-tests/make-exported.mk  Sat Oct 03 10:13:39 2020 +0000
+++ b/usr.bin/make/unit-tests/make-exported.mk  Sat Oct 03 10:31:05 2020 +0000
@@ -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 @@
 # 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:
diff -r 2354188c63ae -r 871b56f11349 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sat Oct 03 10:13:39 2020 +0000
+++ b/usr.bin/make/var.c        Sat Oct 03 10:31:05 2020 +0000
@@ -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 @@
 
     if (name[0] == '.')
        return FALSE;           /* skip internals */
+    if (name[0] == '-')
+       return FALSE;           /* skip misnamed variables */
     if (name[1] == '\0') {
        /*
         * A single char.



Home | Main Index | Thread Index | Old Index