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): fix parsing of the :sh assignment oper...
details: https://anonhg.NetBSD.org/src/rev/33cc8798aeb1
branches: trunk
changeset: 976792:33cc8798aeb1
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Oct 04 07:49:45 2020 +0000
description:
make(1): fix parsing of the :sh assignment operator modifier
diffstat:
usr.bin/make/parse.c | 12 +++--
usr.bin/make/unit-tests/var-op-sunsh.exp | 2 -
usr.bin/make/unit-tests/var-op-sunsh.mk | 73 +++++++++++++++++--------------
3 files changed, 48 insertions(+), 39 deletions(-)
diffs (151 lines):
diff -r bd64c75eb18d -r 33cc8798aeb1 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c Sun Oct 04 06:53:15 2020 +0000
+++ b/usr.bin/make/parse.c Sun Oct 04 07:49:45 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.348 2020/10/03 21:52:50 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.349 2020/10/04 07:49:45 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.348 2020/10/03 21:52:50 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.349 2020/10/04 07:49:45 rillig Exp $");
/* types and constants */
@@ -1826,12 +1826,14 @@
default:
#ifdef SUNSHCMD
- while (opc > line && *opc != ':')
+ while (opc > line && *opc == '\0')
opc--;
- if (strncmp(opc, ":sh", 3) == 0) {
+ if (opc >= line + 2 &&
+ opc[-2] == ':' && opc[-1] == 's' && opc[0] == 'h')
+ {
type = VAR_SHELL;
- *opc = '\0';
+ opc[-2] = '\0';
break;
}
#endif
diff -r bd64c75eb18d -r 33cc8798aeb1 usr.bin/make/unit-tests/var-op-sunsh.exp
--- a/usr.bin/make/unit-tests/var-op-sunsh.exp Sun Oct 04 06:53:15 2020 +0000
+++ b/usr.bin/make/unit-tests/var-op-sunsh.exp Sun Oct 04 07:49:45 2020 +0000
@@ -1,3 +1,1 @@
-make: Unclosed variable specification (expecting '}') for "" (value "echo 123") modifier U
-make: Unclosed variable specification (expecting '}') for "" (value " echo\") modifier U
exit status 0
diff -r bd64c75eb18d -r 33cc8798aeb1 usr.bin/make/unit-tests/var-op-sunsh.mk
--- a/usr.bin/make/unit-tests/var-op-sunsh.mk Sun Oct 04 06:53:15 2020 +0000
+++ b/usr.bin/make/unit-tests/var-op-sunsh.mk Sun Oct 04 07:49:45 2020 +0000
@@ -1,8 +1,8 @@
-# $NetBSD: var-op-sunsh.mk,v 1.1 2020/10/04 06:53:15 rillig Exp $
+# $NetBSD: var-op-sunsh.mk,v 1.2 2020/10/04 07:49:45 rillig Exp $
#
# Tests for the :sh= variable assignment operator, which runs its right-hand
# side through the shell. It is a seldom-used alternative to the !=
-# assignment operator.
+# assignment operator, adopted from Sun make.
.MAKEFLAGS: -dL # Enable sane error messages
@@ -13,54 +13,63 @@
. error
.endif
-# XXX: As of 2020-10-04, the ':sh' can even be followed by other characters.
-# This is neither documented by NetBSD make nor by Solaris make.
-VAR:shell= echo colon-shell
-.if ${VAR} != "colon-shell"
+# It is also possible to have whitespace around the :sh assignment
+# operator modifier.
+VAR :sh = echo colon-sh-spaced
+.if ${VAR} != "colon-sh-spaced"
. error
.endif
-# XXX: Several colons can syntactically appear in a variable name.
-# Neither of these should be interpreted as the ':sh' assignment operator
-# modifier.
-VAR:shoe:shore= echo two-colons
-.if ${VAR${:U\:}shoe} != "two-colons"
+# Until 2020-10-04, the ':sh' could even be followed by other characters.
+# This was neither documented by NetBSD make nor by Solaris make and was
+# an implementation error.
+#
+# Since 2020-10-04, this is a normal variable assignment using the '='
+# assignment operator.
+VAR:shell= echo colon-shell
+.if ${${:UVAR\:shell}} != "echo colon-shell"
. error
.endif
-#.MAKEFLAGS: -dcpv
+# Several colons can syntactically appear in a variable name.
+# Until 2020-10-04, the last of them was interpreted as the ':sh'
+# assignment operator.
+#
+# Since 2020-10-04, the colons are part of the variable name.
+VAR:shoe:shore= echo two-colons
+.if ${${:UVAR\:shoe\:shore}} != "echo two-colons"
+. error
+.endif
-# XXX: As of 2020-10-04, the following expression is wrongly marked as
-# a parse error. This is caused by the ':sh' modifier.
+# Until 2020-10-04, the following expression was wrongly marked as
+# a parse error. This was because the parser for variable assignments
+# just looked for the previous ":sh", without taking any contextual
+# information into account.
#
# There are two different syntactical elements that look exactly the same:
# The variable modifier ':sh' and the assignment operator modifier ':sh'.
-# Intuitively this variable name contains the variable modifier, but the
-# parser sees it as operator modifier, in Parse_DoVar.
-#
-VAR.${:Uecho 123:sh}= echo oops
-.if ${VAR.echo 123} != "oops"
+# Intuitively this variable name contains the variable modifier, but until
+# 2020-10-04, the parser regarded it as an assignment operator modifier, in
+# Parse_DoVar.
+VAR.${:Uecho 123:sh}= ok-123
+.if ${VAR.123} != "ok-123"
. error
.endif
-# XXX: Same pattern here. The ':sh' inside the nested expression is taken
-# for the assignment operator, even though it is escaped by a backslash.
-#
-VAR.${:U echo\:shell}= echo oops
-.if ${VAR.${:U echo\\}} != "oops"
+# Same pattern here. Until 2020-10-04, the ':sh' inside the nested expression
+# was taken for the :sh assignment operator modifier, even though it was
+# escaped by a backslash.
+VAR.${:U echo\:shell}= ok-shell
+.if ${VAR.${:U echo\:shell}} != "ok-shell"
. error
.endif
-# XXX: The word 'shift' is also affected since it starts with ':sh'.
-#
-VAR.key:shift= echo Shift
-.if ${VAR.key} != "Shift"
+# Until 2020-10-04, the word 'shift' was also affected since it starts with
+# ':sh'.
+VAR.key:shift= Shift
+.if ${${:UVAR.key\:shift}} != "Shift"
. error
.endif
-.MAKEFLAGS: -d0
-
-# XXX: Despite the error messages the exit status is still 0.
-
all:
@:;
Home |
Main Index |
Thread Index |
Old Index