Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make Fix parsing of nested variables during .for loop
details: https://anonhg.NetBSD.org/src/rev/29b3a2f529ed
branches: trunk
changeset: 973458:29b3a2f529ed
user: sjg <sjg%NetBSD.org@localhost>
date: Wed Jul 01 18:02:26 2020 +0000
description:
Fix parsing of nested variables during .for loop
Recent change to cond.c to avoid eval of unnecessary
terms had side effect on constructs like:
.for s in 1 2
.if defined(MAN$s) && !empty(MAN$s)
MAN+= ${MAN$s}
.endif
.endfor
resulting in MAN being flagged as recursive.
When Var_Parse encounters a variable within a variable name
we want to force it to be expanded.
But given the way get_mpt_arg calls Var_Parse we need to check
whether we actually started parsing a variable yet.
diffstat:
usr.bin/make/unit-tests/varmisc.exp | 1 +
usr.bin/make/unit-tests/varmisc.mk | 16 ++++++++++++++--
usr.bin/make/var.c | 15 ++++++++++-----
3 files changed, 25 insertions(+), 7 deletions(-)
diffs (86 lines):
diff -r ad2e728dc883 -r 29b3a2f529ed usr.bin/make/unit-tests/varmisc.exp
--- a/usr.bin/make/unit-tests/varmisc.exp Wed Jul 01 17:57:14 2020 +0000
+++ b/usr.bin/make/unit-tests/varmisc.exp Wed Jul 01 18:02:26 2020 +0000
@@ -22,4 +22,5 @@
Version=123.456.789 == 123456789
Literal=3.4.5 == 3004005
We have target specific vars
+MAN= make.1
exit status 0
diff -r ad2e728dc883 -r 29b3a2f529ed usr.bin/make/unit-tests/varmisc.mk
--- a/usr.bin/make/unit-tests/varmisc.mk Wed Jul 01 17:57:14 2020 +0000
+++ b/usr.bin/make/unit-tests/varmisc.mk Wed Jul 01 18:02:26 2020 +0000
@@ -1,9 +1,9 @@
-# $Id: varmisc.mk,v 1.8 2017/01/31 18:56:35 sjg Exp $
+# $Id: varmisc.mk,v 1.9 2020/07/01 18:02:26 sjg Exp $
#
# Miscellaneous variable tests.
all: unmatched_var_paren D_true U_true D_false U_false Q_lhs Q_rhs NQ_none \
- strftime cmpv
+ strftime cmpv manok
unmatched_var_paren:
@echo ${foo::=foo-text}
@@ -60,3 +60,15 @@
@echo Version=${Version} == ${Version:${M_cmpv}}
@echo Literal=3.4.5 == ${3.4.5:L:${M_cmpv}}
@echo We have ${${.TARGET:T}.only}
+
+# catch misshandling of nested vars in .for loop
+MAN=
+MAN1= make.1
+.for s in 1 2
+.if defined(MAN$s) && !empty(MAN$s)
+MAN+= ${MAN$s}
+.endif
+.endfor
+
+manok:
+ @echo MAN=${MAN}
diff -r ad2e728dc883 -r 29b3a2f529ed usr.bin/make/var.c
--- a/usr.bin/make/var.c Wed Jul 01 17:57:14 2020 +0000
+++ b/usr.bin/make/var.c Wed Jul 01 18:02:26 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.224 2020/06/05 19:20:46 sjg Exp $ */
+/* $NetBSD: var.c,v 1.225 2020/07/01 18:02:26 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.224 2020/06/05 19:20:46 sjg Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.225 2020/07/01 18:02:26 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: var.c,v 1.224 2020/06/05 19:20:46 sjg Exp $");
+__RCSID("$NetBSD: var.c,v 1.225 2020/07/01 18:02:26 sjg Exp $");
#endif
#endif /* not lint */
#endif
@@ -3859,12 +3859,17 @@
break;
}
/*
- * A variable inside a variable, expand
+ * A variable inside a variable, expand.
+ * If we really started looking at a variable
+ * (str[0] == '$'), then force VARF_WANTRES
+ * since we need the nested variable expanded to
+ * get the correct name to lookup.
*/
if (*tstr == '$') {
int rlen;
void *freeIt;
- char *rval = Var_Parse(tstr, ctxt, flags, &rlen, &freeIt);
+ char *rval = Var_Parse(tstr, ctxt,
+ flags|((*str == '$') ? VARF_WANTRES : 0), &rlen, &freeIt);
if (rval != NULL) {
Buf_AddBytes(&buf, strlen(rval), rval);
}
Home |
Main Index |
Thread Index |
Old Index