Module Name: src Committed By: rillig Date: Sat Jan 29 10:19:49 UTC 2022
Modified Files: src/usr.bin/make: make.h parse.c var.c src/usr.bin/make/unit-tests: var-recursive.exp Log Message: make: for recursive variables in commands, print location Print the approximate location based on the last command that has been defined for the target. It would be possible to get more detailed location information by counting the number of commands of the target, but that would get messy due to .USEBEFORE, .USE and .DEFAULT, and still, this is an edge case, so don't waste too much code for it now. Having this hint about the location is more helpful than just a plain "Variable X is recursive" without any further details. To generate a diff of this commit: cvs rdiff -u -r1.293 -r1.294 src/usr.bin/make/make.h cvs rdiff -u -r1.659 -r1.660 src/usr.bin/make/parse.c cvs rdiff -u -r1.1007 -r1.1008 src/usr.bin/make/var.c cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/var-recursive.exp 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/make.h diff -u src/usr.bin/make/make.h:1.293 src/usr.bin/make/make.h:1.294 --- src/usr.bin/make/make.h:1.293 Sat Jan 29 09:38:26 2022 +++ src/usr.bin/make/make.h Sat Jan 29 10:19:49 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: make.h,v 1.293 2022/01/29 09:38:26 rillig Exp $ */ +/* $NetBSD: make.h,v 1.294 2022/01/29 10:19:49 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -832,6 +832,7 @@ bool GetBooleanExpr(const char *, bool); void Parse_Init(void); void Parse_End(void); +void PrintLocation(FILE *, bool, const char *, size_t); void PrintStackTrace(bool); void Parse_Error(ParseErrorLevel, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3); bool Parse_VarAssign(const char *, bool, GNode *) MAKE_ATTR_USE; Index: src/usr.bin/make/parse.c diff -u src/usr.bin/make/parse.c:1.659 src/usr.bin/make/parse.c:1.660 --- src/usr.bin/make/parse.c:1.659 Sat Jan 29 09:38:26 2022 +++ src/usr.bin/make/parse.c Sat Jan 29 10:19:49 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.659 2022/01/29 09:38:26 rillig Exp $ */ +/* $NetBSD: parse.c,v 1.660 2022/01/29 10:19:49 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -106,7 +106,7 @@ #include "pathnames.h" /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: parse.c,v 1.659 2022/01/29 09:38:26 rillig Exp $"); +MAKE_RCSID("$NetBSD: parse.c,v 1.660 2022/01/29 10:19:49 rillig Exp $"); /* * A file being read. @@ -435,7 +435,7 @@ FindKeyword(const char *str) return -1; } -static void +void PrintLocation(FILE *f, bool useVars, const char *fname, size_t lineno) { char dirbuf[MAXPATHLEN + 1]; Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.1007 src/usr.bin/make/var.c:1.1008 --- src/usr.bin/make/var.c:1.1007 Sat Jan 29 01:07:31 2022 +++ src/usr.bin/make/var.c Sat Jan 29 10:19:49 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.1007 2022/01/29 01:07:31 rillig Exp $ */ +/* $NetBSD: var.c,v 1.1008 2022/01/29 10:19:49 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -139,7 +139,7 @@ #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.1007 2022/01/29 01:07:31 rillig Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.1008 2022/01/29 10:19:49 rillig Exp $"); /* * Variables are defined using one of the VAR=value assignments. Their @@ -4520,8 +4520,14 @@ Var_Parse(const char **pp, GNode *scope, } expr.name = v->name.str; - if (v->inUse) + if (v->inUse) { + if (scope->fname != NULL) { + fprintf(stderr, "In a command near "); + PrintLocation(stderr, false, + scope->fname, scope->lineno); + } Fatal("Variable %s is recursive.", v->name.str); + } /* * XXX: This assignment creates an alias to the current value of the Index: src/usr.bin/make/unit-tests/var-recursive.exp diff -u src/usr.bin/make/unit-tests/var-recursive.exp:1.4 src/usr.bin/make/unit-tests/var-recursive.exp:1.5 --- src/usr.bin/make/unit-tests/var-recursive.exp:1.4 Sat Jan 29 10:09:37 2022 +++ src/usr.bin/make/unit-tests/var-recursive.exp Sat Jan 29 10:19:49 2022 @@ -13,7 +13,7 @@ Variable V is recursive. make: stopped in unit-tests : OK -Variable VAR is recursive. +In a command near "var-recursive.mk" line 55: Variable VAR is recursive. make: stopped in unit-tests exit status 0