Module Name:    src
Committed By:   rillig
Date:           Sat Mar 29 21:30:48 UTC 2025

Modified Files:
        src/usr.bin/make: make.h parse.c var.c
        src/usr.bin/make/unit-tests: varparse-errors.exp varparse-errors.mk

Log Message:
make: in a stack trace with details and includes, list the current file


To generate a diff of this commit:
cvs rdiff -u -r1.350 -r1.351 src/usr.bin/make/make.h
cvs rdiff -u -r1.738 -r1.739 src/usr.bin/make/parse.c
cvs rdiff -u -r1.1151 -r1.1152 src/usr.bin/make/var.c
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/make/unit-tests/varparse-errors.exp
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/make/unit-tests/varparse-errors.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/make.h
diff -u src/usr.bin/make/make.h:1.350 src/usr.bin/make/make.h:1.351
--- src/usr.bin/make/make.h:1.350	Fri Mar  7 06:50:34 2025
+++ src/usr.bin/make/make.h	Sat Mar 29 21:30:47 2025
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.350 2025/03/07 06:50:34 rillig Exp $	*/
+/*	$NetBSD: make.h,v 1.351 2025/03/29 21:30:47 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -1055,7 +1055,7 @@ void Global_Append(const char *, const c
 void Global_Delete(const char *);
 void Global_Set_ReadOnly(const char *, const char *);
 
-void EvalStack_PrintDetails(void);
+bool EvalStack_PrintDetails(void) MAKE_ATTR_USE;
 
 /* util.c */
 typedef void (*SignalProc)(int);

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.738 src/usr.bin/make/parse.c:1.739
--- src/usr.bin/make/parse.c:1.738	Tue Jan 14 21:34:09 2025
+++ src/usr.bin/make/parse.c	Sat Mar 29 21:30:47 2025
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.738 2025/01/14 21:34:09 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.739 2025/03/29 21:30:47 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -105,7 +105,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.738 2025/01/14 21:34:09 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.739 2025/03/29 21:30:47 rillig Exp $");
 
 /* Detects a multiple-inclusion guard in a makefile. */
 typedef enum {
@@ -395,14 +395,15 @@ PrintStackTrace(bool includingInnermost)
 	const IncludedFile *entries;
 	size_t i, n;
 
-	EvalStack_PrintDetails();
+	bool hasDetails = EvalStack_PrintDetails();
 
 	n = includes.len;
 	if (n == 0)
 		return;
 
 	entries = GetInclude(0);
-	if (!includingInnermost && entries[n - 1].forLoop == NULL)
+	if (!includingInnermost && !(hasDetails && n > 1)
+	    && entries[n - 1].forLoop == NULL)
 		n--;		/* already in the diagnostic */
 
 	for (i = n; i-- > 0;) {

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.1151 src/usr.bin/make/var.c:1.1152
--- src/usr.bin/make/var.c:1.1151	Sat Mar 29 19:08:52 2025
+++ src/usr.bin/make/var.c	Sat Mar 29 21:30:47 2025
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.1151 2025/03/29 19:08:52 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.1152 2025/03/29 21:30:47 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -128,7 +128,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1151 2025/03/29 19:08:52 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1152 2025/03/29 21:30:47 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -370,7 +370,7 @@ EvalStack_Pop(void)
 	evalStack.len--;
 }
 
-void
+bool
 EvalStack_PrintDetails(void)
 {
 	size_t i;
@@ -397,6 +397,7 @@ EvalStack_PrintDetails(void)
 		    value != NULL ? "\" with value \"" : "",
 		    value != NULL ? value : "");
 	}
+	return evalStack.len > 0;
 }
 
 static Var *

Index: src/usr.bin/make/unit-tests/varparse-errors.exp
diff -u src/usr.bin/make/unit-tests/varparse-errors.exp:1.17 src/usr.bin/make/unit-tests/varparse-errors.exp:1.18
--- src/usr.bin/make/unit-tests/varparse-errors.exp:1.17	Sat Mar 29 19:08:53 2025
+++ src/usr.bin/make/unit-tests/varparse-errors.exp	Sat Mar 29 21:30:47 2025
@@ -40,6 +40,13 @@ make: "varparse-errors.mk" line 105: Unc
 	while evaluating "${:U:gmtime" with value "<timestamp>"
 make: "varparse-errors.mk" line 107: Unclosed expression, expecting '}' for modifier "localtime"
 	while evaluating "${:U:localtime" with value "<timestamp>"
+make: "varparse-errors.tmp" line 1: Unknown modifier ":Z"
+	while evaluating "${:Z}" with value ""
+	while evaluating variable "INDIRECT" with value "${:Z}"
+	while evaluating variable "VALUE" with value "${INDIRECT}"
+	in varparse-errors.tmp:1
+	in varparse-errors.mk:126
+make: "varparse-errors.tmp" line 1: 
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/varparse-errors.mk
diff -u src/usr.bin/make/unit-tests/varparse-errors.mk:1.20 src/usr.bin/make/unit-tests/varparse-errors.mk:1.21
--- src/usr.bin/make/unit-tests/varparse-errors.mk:1.20	Sat Mar 29 19:08:53 2025
+++ src/usr.bin/make/unit-tests/varparse-errors.mk	Sat Mar 29 21:30:48 2025
@@ -1,4 +1,4 @@
-# $NetBSD: varparse-errors.mk,v 1.20 2025/03/29 19:08:53 rillig Exp $
+# $NetBSD: varparse-errors.mk,v 1.21 2025/03/29 21:30:48 rillig Exp $
 
 # Tests for parsing and evaluating all kinds of expressions.
 #
@@ -105,3 +105,23 @@ UNCLOSED:=	${:U:_
 UNCLOSED:=	${:U:gmtime
 # expect+1: Unclosed expression, expecting '}' for modifier "localtime"
 UNCLOSED:=	${:U:localtime
+
+
+# In a stack trace that has both evaluation details and included files, list
+# the current file twice: Once in the first line and once in the call
+# hierarchy. While this is redundant, omitting the current file from the
+# call hierarchy is more confusing, as the '.include' line does not contain
+# the faulty expression.
+#
+# expect: make: "varparse-errors.tmp" line 1: Unknown modifier ":Z"
+# expect:	while evaluating "${:Z}" with value ""
+# expect:	while evaluating variable "INDIRECT" with value "${:Z}"
+# expect:	while evaluating variable "VALUE" with value "${INDIRECT}"
+# expect:	in varparse-errors.tmp:1
+# expect:	in varparse-errors.mk:126
+_!=	echo '.info $${VALUE}' > varparse-errors.tmp
+VALUE=	${INDIRECT}
+INDIRECT=	${:Z}
+# The "./" is necessary to skip the directory cache.
+.include "./varparse-errors.tmp"
+_!=	rm -f varparse-errors.tmp

Reply via email to