Module Name: src Committed By: sjg Date: Wed Jul 1 18:02:27 UTC 2020
Modified Files: src/usr.bin/make: var.c src/usr.bin/make/unit-tests: varmisc.exp varmisc.mk Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.224 -r1.225 src/usr.bin/make/var.c cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/varmisc.exp cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/varmisc.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.224 src/usr.bin/make/var.c:1.225 --- src/usr.bin/make/var.c:1.224 Fri Jun 5 19:20:46 2020 +++ src/usr.bin/make/var.c Wed Jul 1 18:02:26 2020 @@ -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 @@ Var_Parse(const char *str, GNode *ctxt, 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); } Index: src/usr.bin/make/unit-tests/varmisc.exp diff -u src/usr.bin/make/unit-tests/varmisc.exp:1.7 src/usr.bin/make/unit-tests/varmisc.exp:1.8 --- src/usr.bin/make/unit-tests/varmisc.exp:1.7 Tue Jan 31 18:56:35 2017 +++ src/usr.bin/make/unit-tests/varmisc.exp Wed Jul 1 18:02:26 2020 @@ -22,4 +22,5 @@ date=20160401 Version=123.456.789 == 123456789 Literal=3.4.5 == 3004005 We have target specific vars +MAN= make.1 exit status 0 Index: src/usr.bin/make/unit-tests/varmisc.mk diff -u src/usr.bin/make/unit-tests/varmisc.mk:1.8 src/usr.bin/make/unit-tests/varmisc.mk:1.9 --- src/usr.bin/make/unit-tests/varmisc.mk:1.8 Tue Jan 31 18:56:35 2017 +++ src/usr.bin/make/unit-tests/varmisc.mk Wed Jul 1 18:02:26 2020 @@ -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 @@ cmpv: @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}