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: for recursive variables in commands, prin...



details:   https://anonhg.NetBSD.org/src/rev/07e8ec52929c
branches:  trunk
changeset: 359878:07e8ec52929c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jan 29 10:19:49 2022 +0000

description:
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.

diffstat:

 usr.bin/make/make.h                       |   3 ++-
 usr.bin/make/parse.c                      |   6 +++---
 usr.bin/make/unit-tests/var-recursive.exp |   2 +-
 usr.bin/make/var.c                        |  12 +++++++++---
 4 files changed, 15 insertions(+), 8 deletions(-)

diffs (90 lines):

diff -r 071653d40af3 -r 07e8ec52929c usr.bin/make/make.h
--- a/usr.bin/make/make.h       Sat Jan 29 10:09:37 2022 +0000
+++ b/usr.bin/make/make.h       Sat Jan 29 10:19:49 2022 +0000
@@ -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 @@
 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;
diff -r 071653d40af3 -r 07e8ec52929c usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sat Jan 29 10:09:37 2022 +0000
+++ b/usr.bin/make/parse.c      Sat Jan 29 10:19:49 2022 +0000
@@ -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 @@
        return -1;
 }
 
-static void
+void
 PrintLocation(FILE *f, bool useVars, const char *fname, size_t lineno)
 {
        char dirbuf[MAXPATHLEN + 1];
diff -r 071653d40af3 -r 07e8ec52929c usr.bin/make/unit-tests/var-recursive.exp
--- a/usr.bin/make/unit-tests/var-recursive.exp Sat Jan 29 10:09:37 2022 +0000
+++ b/usr.bin/make/unit-tests/var-recursive.exp Sat Jan 29 10:19:49 2022 +0000
@@ -13,7 +13,7 @@
 
 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
diff -r 071653d40af3 -r 07e8ec52929c usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sat Jan 29 10:09:37 2022 +0000
+++ b/usr.bin/make/var.c        Sat Jan 29 10:19:49 2022 +0000
@@ -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 @@
        }
 
        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



Home | Main Index | Thread Index | Old Index