Module Name: src
Committed By: rillig
Date: Sun Aug 25 20:44:31 UTC 2024
Modified Files:
src/usr.bin/make: main.c make.h var.c
src/usr.bin/make/unit-tests: var-recursive.exp var-recursive.mk
Log Message:
make: add more context to error message about recursive variables
To generate a diff of this commit:
cvs rdiff -u -r1.632 -r1.633 src/usr.bin/make/main.c
cvs rdiff -u -r1.344 -r1.345 src/usr.bin/make/make.h
cvs rdiff -u -r1.1136 -r1.1137 src/usr.bin/make/var.c
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/var-recursive.exp
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/var-recursive.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/main.c
diff -u src/usr.bin/make/main.c:1.632 src/usr.bin/make/main.c:1.633
--- src/usr.bin/make/main.c:1.632 Thu Jul 11 20:09:16 2024
+++ src/usr.bin/make/main.c Sun Aug 25 20:44:31 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.632 2024/07/11 20:09:16 sjg Exp $ */
+/* $NetBSD: main.c,v 1.633 2024/08/25 20:44:31 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -111,7 +111,7 @@
#include "trace.h"
/* "@(#)main.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.632 2024/07/11 20:09:16 sjg Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.633 2024/08/25 20:44:31 rillig Exp $");
#if defined(MAKE_NATIVE)
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
"The Regents of the University of California. "
@@ -1859,6 +1859,13 @@ Error(const char *fmt, ...)
main_errors++;
}
+void
+WaitForJobs(void)
+{
+ if (jobsRunning)
+ Job_Wait();
+}
+
/*
* Wait for any running jobs to finish, then produce an error message,
* finally exit immediately.
@@ -1871,8 +1878,7 @@ Fatal(const char *fmt, ...)
{
va_list ap;
- if (jobsRunning)
- Job_Wait();
+ WaitForJobs();
(void)fflush(stdout);
fprintf(stderr, "%s: ", progname);
Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.344 src/usr.bin/make/make.h:1.345
--- src/usr.bin/make/make.h:1.344 Thu Jul 11 20:09:16 2024
+++ src/usr.bin/make/make.h Sun Aug 25 20:44:31 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: make.h,v 1.344 2024/07/11 20:09:16 sjg Exp $ */
+/* $NetBSD: make.h,v 1.345 2024/08/25 20:44:31 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -864,6 +864,7 @@ char *getTmpdir(void) MAKE_ATTR_USE;
bool ParseBoolean(const char *, bool) MAKE_ATTR_USE;
const char *cached_realpath(const char *, char *);
bool GetBooleanExpr(const char *, bool);
+void WaitForJobs(void);
/* parse.c */
extern int parseErrors;
Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.1136 src/usr.bin/make/var.c:1.1137
--- src/usr.bin/make/var.c:1.1136 Sat Jul 20 08:54:19 2024
+++ src/usr.bin/make/var.c Sun Aug 25 20:44:31 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.1136 2024/07/20 08:54:19 rillig Exp $ */
+/* $NetBSD: var.c,v 1.1137 2024/08/25 20:44:31 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -126,9 +126,10 @@
#include "dir.h"
#include "job.h"
#include "metachar.h"
+#include "trace.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1136 2024/07/20 08:54:19 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1137 2024/08/25 20:44:31 rillig Exp $");
/*
* Variables are defined using one of the VAR=value assignments. Their
@@ -4576,7 +4577,12 @@ Var_Parse(const char **pp, GNode *scope,
fprintf(stderr, "In a command near ");
PrintLocation(stderr, false, scope);
}
- Fatal("Variable %s is recursive.", v->name.str);
+ WaitForJobs();
+ Parse_Error(PARSE_FATAL, "Variable %s is recursive.",
+ v->name.str);
+ PrintOnError(NULL, "\n");
+ Trace_Log(MAKEERROR, NULL);
+ exit(2); /* Not 1 so -q can distinguish error */
}
/*
Index: src/usr.bin/make/unit-tests/var-recursive.exp
diff -u src/usr.bin/make/unit-tests/var-recursive.exp:1.9 src/usr.bin/make/unit-tests/var-recursive.exp:1.10
--- src/usr.bin/make/unit-tests/var-recursive.exp:1.9 Thu Jul 4 20:18:40 2024
+++ src/usr.bin/make/unit-tests/var-recursive.exp Sun Aug 25 20:44:31 2024
@@ -1,22 +1,23 @@
make: "var-recursive.mk" line 21: still there
-make: Variable DIRECT is recursive.
- in var-recursive.mk:22
+make: "var-recursive.mk" line 23: while evaluating variable "DIRECT" with value "${DIRECT}": Variable DIRECT is recursive.
in directory <curdir>
make: stopped in unit-tests
-make: Variable INDIRECT1 is recursive.
- in var-recursive.mk:29
+sub-exit status 2
+make: "var-recursive.mk" line 31: while evaluating variable "INDIRECT1" with value "${INDIRECT2}": while evaluating variable "INDIRECT2" with value "${INDIRECT1}": Variable INDIRECT1 is recursive.
in directory <curdir>
make: stopped in unit-tests
-make: "var-recursive.mk" line 37: ok
-make: Variable V is recursive.
- in var-recursive.mk:45
+sub-exit status 2
+make: "var-recursive.mk" line 39: ok
+make: "var-recursive.mk" line 48: while evaluating variable "V" with value "$V": Variable V is recursive.
in directory <curdir>
make: stopped in unit-tests
+sub-exit status 2
: OK
-In a command near "var-recursive.mk" line 57: make[1]: Variable VAR is recursive.
+In a command near "var-recursive.mk" line 60: make[1]: in target "target": while evaluating variable "VAR" with value "${VAR}": Variable VAR is recursive.
make: stopped making "target" in unit-tests
+sub-exit status 2
exit status 0
Index: src/usr.bin/make/unit-tests/var-recursive.mk
diff -u src/usr.bin/make/unit-tests/var-recursive.mk:1.6 src/usr.bin/make/unit-tests/var-recursive.mk:1.7
--- src/usr.bin/make/unit-tests/var-recursive.mk:1.6 Sun Nov 19 21:47:52 2023
+++ src/usr.bin/make/unit-tests/var-recursive.mk Sun Aug 25 20:44:31 2024
@@ -1,4 +1,4 @@
-# $NetBSD: var-recursive.mk,v 1.6 2023/11/19 21:47:52 rillig Exp $
+# $NetBSD: var-recursive.mk,v 1.7 2024/08/25 20:44:31 rillig Exp $
#
# Tests for expressions that refer to themselves and thus
# cannot be evaluated.
@@ -11,7 +11,7 @@ TEST?= # none
.if ${TEST} == ""
all:
.for test in ${TESTS}
- @${.MAKE} -f ${MAKEFILE} TEST=${test} || :
+ @${.MAKE} -f ${MAKEFILE} TEST=${test} || echo "sub-exit status $$?"
.endfor
.elif ${TEST} == direct
@@ -19,6 +19,7 @@ all:
DIRECT= ${DIRECT} # Defining a recursive variable is not yet an error.
# expect+1: still there
. info still there # Therefore this line is printed.
+# expect+1: while evaluating variable "DIRECT" with value "${DIRECT}": Variable DIRECT is recursive.
. info ${DIRECT} # But expanding the variable is an error.
.elif ${TEST} == indirect
@@ -26,6 +27,7 @@ DIRECT= ${DIRECT} # Defining a recursive
# The chain of variables that refer to each other may be long.
INDIRECT1= ${INDIRECT2}
INDIRECT2= ${INDIRECT1}
+# expect+1: while evaluating variable "INDIRECT1" with value "${INDIRECT2}": while evaluating variable "INDIRECT2" with value "${INDIRECT1}": Variable INDIRECT1 is recursive.
. info ${INDIRECT1}
.elif ${TEST} == conditional
@@ -42,6 +44,7 @@ CONDITIONAL= ${1:?ok:${CONDITIONAL}}
# which takes a different code path in Var_Parse for parsing the variable
# name. Ensure that these are checked as well.
V= $V
+# expect+1: while evaluating variable "V" with value "$V": Variable V is recursive.
. info $V
.elif ${TEST} == target