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: disallow '$' in the variable name of the ...



details:   https://anonhg.NetBSD.org/src/rev/fbfdd54aae30
branches:  trunk
changeset: 960972:fbfdd54aae30
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Apr 04 13:35:25 2021 +0000

description:
make: disallow '$' in the variable name of the modifier ':@'

If this restriction should break any existing makefile, the author of
that makefile was probably heading for the IOMCC.

diffstat:

 usr.bin/make/unit-tests/var-eval-short.exp         |  14 ++++++++------
 usr.bin/make/unit-tests/var-eval-short.mk          |   6 ++++--
 usr.bin/make/unit-tests/varmod-loop-varname.exp    |  12 +++++++++++-
 usr.bin/make/unit-tests/varmod-loop-varname.mk     |  18 +++++++++++++-----
 usr.bin/make/unit-tests/varmod-loop-varname.out    |  12 +++++++++++-
 usr.bin/make/unit-tests/varmod-loop-varname.rawout |  10 ++++++++++
 usr.bin/make/unit-tests/varmod-loop-varname.status |   2 +-
 usr.bin/make/var.c                                 |  16 +++++-----------
 8 files changed, 63 insertions(+), 27 deletions(-)

diffs (205 lines):

diff -r 1b76c883bf90 -r fbfdd54aae30 usr.bin/make/unit-tests/var-eval-short.exp
--- a/usr.bin/make/unit-tests/var-eval-short.exp        Sun Apr 04 13:24:07 2021 +0000
+++ b/usr.bin/make/unit-tests/var-eval-short.exp        Sun Apr 04 13:35:25 2021 +0000
@@ -1,14 +1,16 @@
-make: "var-eval-short.mk" line 77: Invalid time value: ${FAIL}}
-make: "var-eval-short.mk" line 77: Malformed conditional (0 && ${:Uword:gmtime=${FAIL}})
-make: "var-eval-short.mk" line 91: Invalid time value: ${FAIL}}
-make: "var-eval-short.mk" line 91: Malformed conditional (0 && ${:Uword:localtime=${FAIL}})
+make: "var-eval-short.mk" line 41: In the :@ modifier of "", the variable name "${FAIL}" must not contain a dollar.
+make: "var-eval-short.mk" line 41: Malformed conditional (0 && ${:Uword:@${FAIL}@expr@})
+make: "var-eval-short.mk" line 79: Invalid time value: ${FAIL}}
+make: "var-eval-short.mk" line 79: Malformed conditional (0 && ${:Uword:gmtime=${FAIL}})
+make: "var-eval-short.mk" line 93: Invalid time value: ${FAIL}}
+make: "var-eval-short.mk" line 93: Malformed conditional (0 && ${:Uword:localtime=${FAIL}})
 CondParser_Eval: 0 && ${0:?${FAIL}then:${FAIL}else}
 Var_Parse: ${0:?${FAIL}then:${FAIL}else} (parse-only)
 Applying ${0:?...} to "" (parse-only, undefined)
 Modifier part: "${FAIL}then"
 Modifier part: "${FAIL}else"
 Result of ${0:?${FAIL}then:${FAIL}else} is "" (parse-only, defined)
-ParseReadLine (156): 'DEFINED= defined'
+ParseReadLine (158): 'DEFINED= defined'
 Global:DEFINED = defined
 CondParser_Eval: 0 && ${DEFINED:L:?${FAIL}then:${FAIL}else}
 Var_Parse: ${DEFINED:L:?${FAIL}then:${FAIL}else} (parse-only)
@@ -18,7 +20,7 @@
 Modifier part: "${FAIL}then"
 Modifier part: "${FAIL}else"
 Result of ${DEFINED:?${FAIL}then:${FAIL}else} is "defined" (parse-only, regular)
-ParseReadLine (159): '.MAKEFLAGS: -d0'
+ParseReadLine (161): '.MAKEFLAGS: -d0'
 ParseDependency(.MAKEFLAGS: -d0)
 Global:.MAKEFLAGS =  -r -k -d cpv -d
 Global:.MAKEFLAGS =  -r -k -d cpv -d 0
diff -r 1b76c883bf90 -r fbfdd54aae30 usr.bin/make/unit-tests/var-eval-short.mk
--- a/usr.bin/make/unit-tests/var-eval-short.mk Sun Apr 04 13:24:07 2021 +0000
+++ b/usr.bin/make/unit-tests/var-eval-short.mk Sun Apr 04 13:35:25 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: var-eval-short.mk,v 1.4 2021/03/14 20:41:39 rillig Exp $
+# $NetBSD: var-eval-short.mk,v 1.5 2021/04/04 13:35:26 rillig Exp $
 #
 # Tests for each variable modifier to ensure that they only do the minimum
 # necessary computations.  If the result of the expression is not needed, they
@@ -34,8 +34,10 @@
 .if 0 && ${0:?${FAIL}:${FAIL}}
 .endif
 
-# Before var.c,v 1.870 from 2021-03-14, the expression ${FAIL} was evaluated
+# Before var.c 1.870 from 2021-03-14, the expression ${FAIL} was evaluated
 # after the loop, when undefining the temporary global loop variable.
+# Since var.c 1.907 from 2021-04-04, a '$' is no longer allowed in the
+# variable name.
 .if 0 && ${:Uword:@${FAIL}@expr@}
 .endif
 
diff -r 1b76c883bf90 -r fbfdd54aae30 usr.bin/make/unit-tests/varmod-loop-varname.exp
--- a/usr.bin/make/unit-tests/varmod-loop-varname.exp   Sun Apr 04 13:24:07 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-loop-varname.exp   Sun Apr 04 13:35:25 2021 +0000
@@ -1,1 +1,11 @@
-exit status 0
+make: "varmod-loop-varname.mk" line 13: In the :@ modifier of "", the variable name "${:Ubar:S,b,v,}" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 13: Malformed conditional (${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+")
+make: "varmod-loop-varname.mk" line 80: In the :@ modifier of "1 2 3", the variable name "v$" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 80: Malformed conditional (${1 2 3:L:@v$@($v)@} != "(1) (2) (3)")
+make: "varmod-loop-varname.mk" line 85: In the :@ modifier of "1 2 3", the variable name "v$$" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 85: Malformed conditional (${1 2 3:L:@v$$@($v)@} != "() () ()")
+make: "varmod-loop-varname.mk" line 90: In the :@ modifier of "1 2 3", the variable name "v$$$" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 90: Malformed conditional (${1 2 3:L:@v$$$@($v)@} != "() () ()")
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff -r 1b76c883bf90 -r fbfdd54aae30 usr.bin/make/unit-tests/varmod-loop-varname.mk
--- a/usr.bin/make/unit-tests/varmod-loop-varname.mk    Sun Apr 04 13:24:07 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-loop-varname.mk    Sun Apr 04 13:35:25 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-loop-varname.mk,v 1.1 2021/04/04 13:20:52 rillig Exp $
+# $NetBSD: varmod-loop-varname.mk,v 1.2 2021/04/04 13:35:26 rillig Exp $
 #
 # Tests for the first part of the variable modifier ':@var@...@', which
 # contains the variable name to use during the loop.
@@ -6,10 +6,10 @@
 .MAKE.SAVE_DOLLARS=    yes
 
 
-# In the :@ modifier, the name of the loop variable can be generated
-# dynamically.  There's no practical use-case for this, and hopefully nobody
-# will ever depend on this, but technically it's possible.
-# Therefore, in -dL mode, this is forbidden, see lint.mk.
+# Before 2021-04-04, the name of the loop variable could be generated
+# dynamically.  There was no practical use-case for this.
+# Since var.c 1.907 from 2021-04-04, a '$' is no longer allowed in the
+# variable name.
 .if ${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+"
 .  error
 .endif
@@ -75,14 +75,22 @@
 # Until 2020-07-20, the variable name of the :@ modifier could end with one
 # or two dollar signs, which were silently ignored.
 # There's no point in allowing a dollar sign in that position.
+# Since var.c 1.907 from 2021-04-04, a '$' is no longer allowed in the
+# variable name.
 .if ${1 2 3:L:@v$@($v)@} != "(1) (2) (3)"
 .  error
+.else
+.  error
 .endif
 .if ${1 2 3:L:@v$$@($v)@} != "() () ()"
 .  error
+.else
+.  error
 .endif
 .if ${1 2 3:L:@v$$$@($v)@} != "() () ()"
 .  error
+.else
+.  error
 .endif
 
 
diff -r 1b76c883bf90 -r fbfdd54aae30 usr.bin/make/unit-tests/varmod-loop-varname.out
--- a/usr.bin/make/unit-tests/varmod-loop-varname.out   Sun Apr 04 13:24:07 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-loop-varname.out   Sun Apr 04 13:35:25 2021 +0000
@@ -1,1 +1,11 @@
-exit status 0
+make: "varmod-loop-varname.mk" line 13: In the :@ modifier of "", the variable name "${:Ubar:S,b,v,}" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 13: Malformed conditional (${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+")
+make: "varmod-loop-varname.mk" line 80: In the :@ modifier of "1 2 3", the variable name "v$" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 80: Malformed conditional (${1 2 3:L:@v$@($v)@} != "(1) (2) (3)")
+make: "varmod-loop-varname.mk" line 85: In the :@ modifier of "1 2 3", the variable name "v$$" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 85: Malformed conditional (${1 2 3:L:@v$$@($v)@} != "() () ()")
+make: "varmod-loop-varname.mk" line 90: In the :@ modifier of "1 2 3", the variable name "v$$$" must not contain a dollar.
+make: "varmod-loop-varname.mk" line 90: Malformed conditional (${1 2 3:L:@v$$$@($v)@} != "() () ()")
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
diff -r 1b76c883bf90 -r fbfdd54aae30 usr.bin/make/unit-tests/varmod-loop-varname.rawout
--- a/usr.bin/make/unit-tests/varmod-loop-varname.rawout        Sun Apr 04 13:24:07 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-loop-varname.rawout        Sun Apr 04 13:35:25 2021 +0000
@@ -0,0 +1,10 @@
+make: "/home/rillig/proj/src/usr.bin/make/unit-tests/varmod-loop-varname.mk" line 13: In the :@ modifier of "", the variable name "${:Ubar:S,b,v,}" must not contain a dollar.
+make: "/home/rillig/proj/src/usr.bin/make/unit-tests/varmod-loop-varname.mk" line 13: Malformed conditional (${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@} != "+one+ +two+ +three+")
+make: "/home/rillig/proj/src/usr.bin/make/unit-tests/varmod-loop-varname.mk" line 80: In the :@ modifier of "1 2 3", the variable name "v$" must not contain a dollar.
+make: "/home/rillig/proj/src/usr.bin/make/unit-tests/varmod-loop-varname.mk" line 80: Malformed conditional (${1 2 3:L:@v$@($v)@} != "(1) (2) (3)")
+make: "/home/rillig/proj/src/usr.bin/make/unit-tests/varmod-loop-varname.mk" line 85: In the :@ modifier of "1 2 3", the variable name "v$$" must not contain a dollar.
+make: "/home/rillig/proj/src/usr.bin/make/unit-tests/varmod-loop-varname.mk" line 85: Malformed conditional (${1 2 3:L:@v$$@($v)@} != "() () ()")
+make: "/home/rillig/proj/src/usr.bin/make/unit-tests/varmod-loop-varname.mk" line 90: In the :@ modifier of "1 2 3", the variable name "v$$$" must not contain a dollar.
+make: "/home/rillig/proj/src/usr.bin/make/unit-tests/varmod-loop-varname.mk" line 90: Malformed conditional (${1 2 3:L:@v$$$@($v)@} != "() () ()")
+make: Fatal errors encountered -- cannot continue
+make: stopped in /home/rillig/proj/src/usr.bin/make/unit-tests
diff -r 1b76c883bf90 -r fbfdd54aae30 usr.bin/make/unit-tests/varmod-loop-varname.status
--- a/usr.bin/make/unit-tests/varmod-loop-varname.status        Sun Apr 04 13:24:07 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-loop-varname.status        Sun Apr 04 13:35:25 2021 +0000
@@ -1,1 +1,1 @@
-0
+1
diff -r 1b76c883bf90 -r fbfdd54aae30 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Apr 04 13:24:07 2021 +0000
+++ b/usr.bin/make/var.c        Sun Apr 04 13:35:25 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.906 2021/04/04 11:56:43 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.907 2021/04/04 13:35:25 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.906 2021/04/04 11:56:43 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.907 2021/04/04 13:35:25 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -1741,9 +1741,7 @@
                return;
 
        args = data;
-       /* XXX: The variable name should not be expanded here. */
-       Var_SetExpandWithFlags(args->scope, args->tvar, word,
-           VAR_SET_NO_EXPORT);
+       Var_SetWithFlags(args->scope, args->tvar, word, VAR_SET_NO_EXPORT);
        (void)Var_Subst(args->str, args->scope, args->emode, &s);
        /* TODO: handle errors */
 
@@ -2475,7 +2473,7 @@
        res = ParseModifierPart(pp, '@', VARE_PARSE_ONLY, ch, &args.tvar);
        if (res != VPR_OK)
                return AMR_CLEANUP;
-       if (opts.strict && strchr(args.tvar, '$') != NULL) {
+       if (strchr(args.tvar, '$') != NULL) {
                Parse_Error(PARSE_FATAL,
                    "In the :@ modifier of \"%s\", the variable name \"%s\" "
                    "must not contain a dollar.",
@@ -2496,11 +2494,7 @@
        ModifyWords(ch, ModifyWord_Loop, &args, ch->oneBigWord);
        ch->sep = prev_sep;
        /* XXX: Consider restoring the previous variable instead of deleting. */
-       /*
-        * XXX: The variable name should not be expanded here, see
-        * ModifyWord_Loop.
-        */
-       Var_DeleteExpand(expr->scope, args.tvar);
+       Var_Delete(expr->scope, args.tvar);
 
 done:
        free(args.tvar);



Home | Main Index | Thread Index | Old Index