Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 10 Jan 2026 21:34:09 +0000
From:      Simon J. Gerraty <sjg@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: eb560911563f - stable/14 - Merge bmake-20250618
Message-ID:  <6962c5d1.24eb2.78b5d6b8@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch stable/14 has been updated by sjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=eb560911563f13e56a74167e323fda1cf111e008

commit eb560911563f13e56a74167e323fda1cf111e008
Author:     Simon J. Gerraty <sjg@FreeBSD.org>
AuthorDate: 2025-06-28 02:47:23 +0000
Commit:     Simon J. Gerraty <sjg@FreeBSD.org>
CommitDate: 2026-01-10 21:33:13 +0000

    Merge bmake-20250618
    
    (cherry picked from commit 0b46a53a2f50b5ab0f4598104119a049b9c42cc9)
---
 contrib/bmake/ChangeLog                            |  85 ++
 contrib/bmake/FILES                                |   5 +
 contrib/bmake/VERSION                              |   2 +-
 contrib/bmake/bmake.1                              |  11 +-
 contrib/bmake/bmake.cat1                           |   7 +-
 contrib/bmake/compat.c                             |  32 +-
 contrib/bmake/cond.c                               |  10 +-
 contrib/bmake/dir.c                                |   6 +-
 contrib/bmake/for.c                                |  28 +-
 contrib/bmake/hash.c                               |  30 +-
 contrib/bmake/hash.h                               |  16 +-
 contrib/bmake/job.c                                | 860 ++++++++++-----------
 contrib/bmake/job.h                                | 116 +--
 contrib/bmake/main.c                               | 152 ++--
 contrib/bmake/make.1                               |  11 +-
 contrib/bmake/make.c                               | 173 ++---
 contrib/bmake/make.h                               |  20 +-
 contrib/bmake/make_malloc.c                        |   6 +-
 contrib/bmake/meta.c                               |  24 +-
 contrib/bmake/meta.h                               |   4 +-
 contrib/bmake/mk/ChangeLog                         |  40 +
 contrib/bmake/mk/FILES                             |  29 +-
 contrib/bmake/mk/auto.obj.mk                       |   4 +-
 contrib/bmake/mk/dirdeps2dplibs.mk                 |  35 +
 contrib/bmake/mk/gendirdeps.mk                     |  21 +-
 contrib/bmake/mk/install-mk                        |   4 +-
 contrib/bmake/mk/lib.mk                            |   4 +-
 contrib/bmake/mk/libs.mk                           |   4 +-
 contrib/bmake/mk/meta.autodep.mk                   |  55 +-
 contrib/bmake/mk/meta2deps.py                      |  23 +-
 contrib/bmake/mk/meta2deps.sh                      |  16 +-
 contrib/bmake/mk/mkopt.sh                          |   9 +-
 contrib/bmake/mk/newlog.sh                         |  64 +-
 contrib/bmake/mk/progs.mk                          |   4 +-
 contrib/bmake/mk/setopts.sh                        |  20 +-
 contrib/bmake/mk/sys.mk                            |   3 +-
 contrib/bmake/parse.c                              |  90 ++-
 contrib/bmake/suff.c                               |  64 +-
 contrib/bmake/targ.c                               |   9 +-
 contrib/bmake/trace.c                              |  12 +-
 contrib/bmake/unit-tests/Makefile                  |  35 +-
 contrib/bmake/unit-tests/archive.exp               |   4 +-
 contrib/bmake/unit-tests/check-expect.lua          | 190 +++++
 contrib/bmake/unit-tests/cmd-errors-jobs.exp       |   6 +
 contrib/bmake/unit-tests/cond-func-empty.exp       |   3 +-
 contrib/bmake/unit-tests/cond-func-empty.mk        |   3 +-
 contrib/bmake/unit-tests/cond-late.exp             |   2 +-
 contrib/bmake/unit-tests/dep-op-missing.exp        |   2 +-
 contrib/bmake/unit-tests/deptgt-suffixes.exp       |   1 +
 contrib/bmake/unit-tests/directive-for-errors.exp  |   2 +-
 contrib/bmake/unit-tests/directive-for-errors.mk   |   7 +-
 contrib/bmake/unit-tests/directive-for-null.exp    |   2 +-
 contrib/bmake/unit-tests/gnode-submake.exp         |   2 +-
 contrib/bmake/unit-tests/job-output.exp            |  13 +
 contrib/bmake/unit-tests/job-output.mk             |  41 +
 contrib/bmake/unit-tests/objdir-writable.exp       |   2 +-
 contrib/bmake/unit-tests/opt-debug-graph1.exp      |   3 +-
 contrib/bmake/unit-tests/opt-debug-graph2.exp      |   3 +-
 contrib/bmake/unit-tests/opt-debug-graph3.exp      |   3 +-
 contrib/bmake/unit-tests/opt-debug-jobs.exp        |  20 +-
 contrib/bmake/unit-tests/opt-file.exp              |   2 +-
 contrib/bmake/unit-tests/opt-jobs-internal.exp     |  33 +-
 contrib/bmake/unit-tests/opt-jobs-internal.mk      |  70 +-
 contrib/bmake/unit-tests/opt-jobs.mk               |   2 +-
 contrib/bmake/unit-tests/opt-touch-jobs.mk         |   4 +-
 contrib/bmake/unit-tests/opt-tracefile.exp         |  16 +-
 contrib/bmake/unit-tests/opt-tracefile.mk          |   5 +-
 contrib/bmake/unit-tests/sh-errctl.exp             |  14 +-
 contrib/bmake/unit-tests/shell-csh.mk              |   6 +-
 contrib/bmake/unit-tests/shell-ksh.exp             |  11 +-
 contrib/bmake/unit-tests/shell-ksh.mk              |  42 +-
 contrib/bmake/unit-tests/suff-main-several.exp     |   3 +-
 contrib/bmake/unit-tests/suff-transform-debug.exp  |   3 +-
 contrib/bmake/unit-tests/var-op-expand.exp         |  14 +-
 contrib/bmake/unit-tests/var-op-expand.mk          |  11 +-
 contrib/bmake/unit-tests/var-recursive.exp         |   9 +-
 contrib/bmake/unit-tests/varmod-assign.exp         |   3 +
 contrib/bmake/unit-tests/varmod-ifelse.exp         |   9 +
 contrib/bmake/unit-tests/varmod-ifelse.mk          |   9 +-
 contrib/bmake/unit-tests/varmod-mtime.exp          |   4 +-
 contrib/bmake/unit-tests/varmod-mtime.mk           |   6 +-
 .../bmake/unit-tests/varname-dot-make-level.exp    |   1 +
 contrib/bmake/unit-tests/varname-dot-makeflags.mk  |   2 +-
 contrib/bmake/unit-tests/varname-dot-newline.exp   |   6 +-
 .../bmake/unit-tests/varname-make_stack_trace.exp  |  40 +
 .../bmake/unit-tests/varname-make_stack_trace.mk   |  37 +
 contrib/bmake/unit-tests/varname.exp               |  17 +-
 contrib/bmake/unit-tests/varname.mk                |  68 +-
 contrib/bmake/unit-tests/varparse-errors.mk        |   4 +-
 contrib/bmake/var.c                                | 108 ++-
 usr.bin/bmake/Makefile.config                      |   2 +-
 usr.bin/bmake/unit-tests/Makefile                  |  35 +-
 92 files changed, 1870 insertions(+), 1178 deletions(-)

diff --git a/contrib/bmake/ChangeLog b/contrib/bmake/ChangeLog
index 1ec90b7bccc8..0a5eced2d439 100644
--- a/contrib/bmake/ChangeLog
+++ b/contrib/bmake/ChangeLog
@@ -1,3 +1,88 @@
+2025-06-18  Simon J Gerraty  <sjg@beast.crufty.net>
+
+	* VERSION (_MAKE_VERSION): 20250618
+	Merge with NetBSD make, pick up
+	o parse.c: in a warning without location information,
+	print the stack trace
+
+2025-06-15  Simon J Gerraty  <sjg@beast.crufty.net>
+
+	* VERSION (_MAKE_VERSION): 20250615
+	Merge with NetBSD make, pick up
+	o add on-demand inter-process stack traces
+	o job.c,meta.c: do not discard empty lines in the output of a command
+	o job.c: add job prefix if necessary in non-default filtered mode
+	o parse.c,var.c: skip inter-process stack trace when
+	MAKE_STACK_TRACE=no
+
+2025-06-12  Simon J Gerraty  <sjg@beast.crufty.net>
+
+	* VERSION (_MAKE_VERSION): 20250612
+	Merge with NetBSD make, pick up
+	o use a common style for unexpected error messages
+	o parse.c: add program name to stack traces from sub-makes
+	add quotes to "in directory" line in stack traces
+	o var.c: check variable names for invalid characters when there
+	are no modifiers to apply.  This detects and warns about gmake
+	syntax like: $(addprefix -I, $(LIST))
+
+2025-06-09  Simon J Gerraty  <sjg@beast.crufty.net>
+
+	* VERSION (_MAKE_VERSION): 20250606
+	Merge with NetBSD make, pick up
+	o main.c: fix bug in handling of output of children in jobs mode
+
+2025-05-28  Simon J Gerraty  <sjg@beast.crufty.net>
+
+	* VERSION (_MAKE_VERSION): 20250528
+	Merge with NetBSD make, pick up
+	o show contents of MAKEFLAGS in the stack trace.
+	o main.c: delay warning about bogus -J flag, if we end up in
+	compat mode before the call to InitMaxJobs, the warning isn't
+	necessary.
+
+2025-05-25  Simon J Gerraty  <sjg@beast.crufty.net>
+
+	* VERSION (_MAKE_VERSION): 20250525
+	Merge with NetBSD make, pick up
+	o main.c: set .CURDIR earlier so it can be reported in some errors.
+
+2025-05-20  Simon J Gerraty  <sjg@beast.crufty.net>
+
+	* VERSION (_MAKE_VERSION): 20250520
+	Merge with NetBSD make, pick up
+	o rename variables, remove now-redundant comments
+	o job.c: clean up building the shell commands in parallel mode
+	remove timeout for polling in parallel mode
+	o main.c: clean up error message for malformed internal -J option
+
+2025-05-11  Simon J Gerraty  <sjg@beast.crufty.net>
+
+	* VERSION (_MAKE_VERSION): 20250511
+	Merge with NetBSD make, pick up
+	o job.c: rename token pool variables to be more descriptive
+	move ContinueJobs further up, to eliminate a forward declaration
+	error out if writing to an internal pipe fails
+	clean up constant names and function names
+	use uniform debug log messages for the token pool
+	in the debug log, replace magic numbers with identifiers
+	o main.c: clean up error message for malformed internal -J option
+	o make.c: replace bitset in trace output with descriptive node
+	attributes
+	o targ.c: add end marker for -dg1, -dg2 and -dg3 debug log
+	o var.c: fix order of error messages in the ":?" modifier
+
+2025-04-25  Simon J Gerraty  <sjg@beast.crufty.net>
+
+	* VERSION (_MAKE_VERSION): 20250424
+	Merge with NetBSD make, pick up
+	o cleanup; replace unsigned int with just unsigned
+	Inline the TMPPAT macro, as it is only needed in a single place
+	o move struct Job from job.h to job.c
+	o job.c: group the code for handling the job token pool
+	avoid excessive values of -j
+	o make.c: fix grammar in debug log message
+
 2025-04-14  Simon J Gerraty  <sjg@beast.crufty.net>
 
 	* VERSION (_MAKE_VERSION): 20250414
diff --git a/contrib/bmake/FILES b/contrib/bmake/FILES
index 553f3211f29c..8bed07d546a3 100644
--- a/contrib/bmake/FILES
+++ b/contrib/bmake/FILES
@@ -76,6 +76,7 @@ unit-tests/archive-suffix.exp
 unit-tests/archive-suffix.mk
 unit-tests/archive.exp
 unit-tests/archive.mk
+unit-tests/check-expect.lua
 unit-tests/cmd-errors-jobs.exp
 unit-tests/cmd-errors-jobs.mk
 unit-tests/cmd-errors-lint.exp
@@ -410,6 +411,8 @@ unit-tests/job-output-long-lines.exp
 unit-tests/job-output-long-lines.mk
 unit-tests/job-output-null.exp
 unit-tests/job-output-null.mk
+unit-tests/job-output.exp
+unit-tests/job-output.mk
 unit-tests/jobs-empty-commands-error.exp
 unit-tests/jobs-empty-commands-error.mk
 unit-tests/jobs-empty-commands.exp
@@ -859,6 +862,8 @@ unit-tests/varname-make_print_var_on_error-jobs.exp
 unit-tests/varname-make_print_var_on_error-jobs.mk
 unit-tests/varname-make_print_var_on_error.exp
 unit-tests/varname-make_print_var_on_error.mk
+unit-tests/varname-make_stack_trace.exp
+unit-tests/varname-make_stack_trace.mk
 unit-tests/varname-makefile.exp
 unit-tests/varname-makefile.mk
 unit-tests/varname-makeflags.exp
diff --git a/contrib/bmake/VERSION b/contrib/bmake/VERSION
index 4e4949c5fd3e..1467403891f1 100644
--- a/contrib/bmake/VERSION
+++ b/contrib/bmake/VERSION
@@ -1,2 +1,2 @@
 # keep this compatible with sh and make
-_MAKE_VERSION=20250414
+_MAKE_VERSION=20250618
diff --git a/contrib/bmake/bmake.1 b/contrib/bmake/bmake.1
index 9e9f2d03a450..92ed9e201ea5 100644
--- a/contrib/bmake/bmake.1
+++ b/contrib/bmake/bmake.1
@@ -1,4 +1,4 @@
-.\"	$NetBSD: make.1,v 1.384 2025/04/04 18:36:47 sjg Exp $
+.\"	$NetBSD: make.1,v 1.385 2025/06/13 03:51:18 rillig Exp $
 .\"
 .\" Copyright (c) 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	from: @(#)make.1	8.4 (Berkeley) 3/19/94
 .\"
-.Dd April  4, 2025
+.Dd June 12, 2025
 .Dt BMAKE 1
 .Os
 .Sh NAME
@@ -2688,6 +2688,7 @@ uses the following environment variables, if they exist:
 .Ev MAKEOBJDIR ,
 .Ev MAKEOBJDIRPREFIX ,
 .Ev MAKESYSPATH ,
+.Ev MAKE_STACK_TRACE ,
 .Ev PWD ,
 and
 .Ev TMPDIR .
@@ -2707,6 +2708,12 @@ very early and the
 target is used to reset
 .Sq Va .OBJDIR ,
 there may be unexpected side effects.
+.Pp
+If the
+.Ev MAKE_STACK_TRACE
+environment variable is set to
+.Dq yes ,
+any stack traces include the call chain of the parent processes.
 .Sh FILES
 .Bl -tag -width /usr/share/mk -compact
 .It .depend
diff --git a/contrib/bmake/bmake.cat1 b/contrib/bmake/bmake.cat1
index e1340e1c78e0..667c80898def 100644
--- a/contrib/bmake/bmake.cat1
+++ b/contrib/bmake/bmake.cat1
@@ -1728,7 +1728,7 @@ SSPPEECCIIAALL TTAARRGGEETTSS
 EENNVVIIRROONNMMEENNTT
      bbmmaakkee uses the following environment variables, if they exist: MACHINE,
      MACHINE_ARCH, MAKE, MAKEFLAGS, MAKEOBJDIR, MAKEOBJDIRPREFIX, MAKESYSPATH,
-     PWD, and TMPDIR.
+     MAKE_STACK_TRACE, PWD, and TMPDIR.
 
      MAKEOBJDIRPREFIX and MAKEOBJDIR should be set in the environment or on
      the command line to bbmmaakkee and not as makefile variables; see the
@@ -1736,6 +1736,9 @@ EENNVVIIRROONNMMEENNTT
      via makefile variables but unless done very early and the `..OOBBJJDDIIRR'
      target is used to reset `_._O_B_J_D_I_R', there may be unexpected side effects.
 
+     If the MAKE_STACK_TRACE environment variable is set to "yes", any stack
+     traces include the call chain of the parent processes.
+
 FFIILLEESS
      .depend        list of dependencies
      makefile       first default makefile if no makefile is specified on the
@@ -1828,4 +1831,4 @@ BBUUGGSS
      attempt to suppress a cascade of unnecessary errors, can result in a
      seemingly unexplained `*** Error code 6'
 
-FreeBSD 14.2-RELEASE-p1          April 4, 2025         FreeBSD 14.2-RELEASE-p1
+FreeBSD 14.2-RELEASE-p1          June 12, 2025         FreeBSD 14.2-RELEASE-p1
diff --git a/contrib/bmake/compat.c b/contrib/bmake/compat.c
index 0da929e35b82..7a51a99be4ba 100644
--- a/contrib/bmake/compat.c
+++ b/contrib/bmake/compat.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat.c,v 1.262 2025/01/19 10:57:10 rillig Exp $	*/
+/*	$NetBSD: compat.c,v 1.267 2025/06/13 03:51:18 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -90,13 +90,16 @@
 #include "make.h"
 #include "dir.h"
 #include "job.h"
+#ifdef USE_META
+# include "meta.h"
+#endif
 #include "metachar.h"
 #include "pathnames.h"
 
 /*	"@(#)compat.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: compat.c,v 1.262 2025/01/19 10:57:10 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.267 2025/06/13 03:51:18 rillig Exp $");
 
-static GNode *curTarg = NULL;
+static GNode *curTarg;
 static pid_t compatChild;
 static int compatSigno;
 
@@ -107,7 +110,7 @@ static int compatSigno;
 static void
 CompatDeleteTarget(GNode *gn)
 {
-	if (gn != NULL && !GNode_IsPrecious(gn) &&
+	if (!GNode_IsPrecious(gn) &&
 	    (gn->type & OP_PHONY) == 0) {
 		const char *file = GNode_VarTarget(gn);
 		if (!opts.noExecute && unlink_file(file) == 0)
@@ -127,11 +130,9 @@ CompatDeleteTarget(GNode *gn)
 static void
 CompatInterrupt(int signo)
 {
-	CompatDeleteTarget(curTarg);
-
-	if (curTarg != NULL && !GNode_IsPrecious(curTarg)) {
-		/* Run .INTERRUPT only if hit with interrupt signal. */
-		if (signo == SIGINT) {
+	if (curTarg != NULL) {
+		CompatDeleteTarget(curTarg);
+		if (signo == SIGINT && !GNode_IsPrecious(curTarg)) {
 			GNode *gn = Targ_FindNode(".INTERRUPT");
 			if (gn != NULL)
 				Compat_Make(gn, gn);
@@ -309,8 +310,6 @@ Compat_RunCommand(const char *cmdp, GNode *gn, StringListNode *ln)
 		cmd++;
 	}
 
-	while (ch_isspace(*cmd))
-		cmd++;
 	if (cmd[0] == '\0')
 		goto register_command;
 
@@ -337,7 +336,7 @@ Compat_RunCommand(const char *cmdp, GNode *gn, StringListNode *ln)
 
 		if (Cmd_Argv(cmd, cmd_len, shargv, 5,
 			cmd_file, sizeof(cmd_file),
-			(errCheck && shellErrFlag != NULL),
+			errCheck && shellErrFlag != NULL,
 			DEBUG(SHELL)) < 0)
 			Fatal("cannot run \"%s\"", cmd);
 		av = shargv;
@@ -356,6 +355,7 @@ Compat_RunCommand(const char *cmdp, GNode *gn, StringListNode *ln)
 #endif
 
 	Var_ReexportVars(gn);
+	Var_ExportStackTrace(gn->name, cmd);
 
 	compatChild = Compat_Spawn(av);
 	free(mav);
@@ -730,7 +730,7 @@ InitSignals(void)
 }
 
 void
-Compat_MakeAll(GNodeList *targs)
+Compat_MakeAll(GNodeList *targets)
 {
 	GNode *errorNode = NULL;
 
@@ -753,10 +753,10 @@ Compat_MakeAll(GNodeList *targs)
 	 * Expand .USE nodes right now, because they can modify the structure
 	 * of the tree.
 	 */
-	Make_ExpandUse(targs);
+	Make_ExpandUse(targets);
 
-	while (!Lst_IsEmpty(targs)) {
-		GNode *gn = Lst_Dequeue(targs);
+	while (!Lst_IsEmpty(targets)) {
+		GNode *gn = Lst_Dequeue(targets);
 		Compat_Make(gn, gn);
 
 		if (gn->made == UPTODATE) {
diff --git a/contrib/bmake/cond.c b/contrib/bmake/cond.c
index 31fe21c4c8b6..f83163cbb50e 100644
--- a/contrib/bmake/cond.c
+++ b/contrib/bmake/cond.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.372 2025/04/10 21:41:35 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.373 2025/04/22 19:28:50 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -91,7 +91,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.372 2025/04/10 21:41:35 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.373 2025/04/22 19:28:50 rillig Exp $");
 
 /*
  * Conditional expressions conform to this grammar:
@@ -166,7 +166,7 @@ typedef struct CondParser {
 
 static CondResult CondParser_Or(CondParser *, bool);
 
-unsigned int cond_depth = 0;	/* current .if nesting level */
+unsigned cond_depth = 0;	/* current .if nesting level */
 
 /* Names for ComparisonOp. */
 static const char opname[][3] = { "<", "<=", ">", ">=", "==", "!=" };
@@ -1028,7 +1028,7 @@ Cond_EvalLine(const char *line)
 	} IfState;
 
 	static enum IfState *cond_states = NULL;
-	static unsigned int cond_states_cap = 128;
+	static unsigned cond_states_cap = 128;
 
 	bool plain;
 	bool (*evalBare)(const char *);
@@ -1221,7 +1221,7 @@ found_variable:
 void
 Cond_EndFile(void)
 {
-	unsigned int open_conds = cond_depth - CurFile_CondMinDepth();
+	unsigned open_conds = cond_depth - CurFile_CondMinDepth();
 
 	if (open_conds != 0) {
 		Parse_Error(PARSE_FATAL, "%u open conditional%s",
diff --git a/contrib/bmake/dir.c b/contrib/bmake/dir.c
index 106b475bda2a..217fd04e162b 100644
--- a/contrib/bmake/dir.c
+++ b/contrib/bmake/dir.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: dir.c,v 1.296 2025/04/11 17:21:31 rillig Exp $	*/
+/*	$NetBSD: dir.c,v 1.297 2025/06/12 18:51:05 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -132,7 +132,7 @@
 #include "job.h"
 
 /*	"@(#)dir.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: dir.c,v 1.296 2025/04/11 17:21:31 rillig Exp $");
+MAKE_RCSID("$NetBSD: dir.c,v 1.297 2025/06/12 18:51:05 rillig Exp $");
 
 /*
  * A search path is a list of CachedDir structures. A CachedDir has in it the
@@ -492,7 +492,7 @@ Dir_InitDot(void)
 
 	dir = SearchPath_Add(NULL, ".");
 	if (dir == NULL) {
-		Error("Cannot open `.' (%s)", strerror(errno));
+		Error("Cannot open \".\": %s", strerror(errno));
 		exit(2);	/* Not 1 so -q can distinguish error */
 	}
 
diff --git a/contrib/bmake/for.c b/contrib/bmake/for.c
index 2aa1398b1c4c..438fb4e84de0 100644
--- a/contrib/bmake/for.c
+++ b/contrib/bmake/for.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: for.c,v 1.184 2025/04/11 18:08:17 rillig Exp $	*/
+/*	$NetBSD: for.c,v 1.185 2025/04/22 19:28:50 rillig Exp $	*/
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -58,14 +58,14 @@
 #include "make.h"
 
 /*	"@(#)for.c	8.1 (Berkeley) 6/6/93"	*/
-MAKE_RCSID("$NetBSD: for.c,v 1.184 2025/04/11 18:08:17 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.185 2025/04/22 19:28:50 rillig Exp $");
 
 
 typedef struct ForLoop {
 	Vector /* of 'char *' */ vars; /* Iteration variables */
 	SubstringWords items;	/* Substitution items */
 	Buffer body;		/* Unexpanded body of the loop */
-	unsigned int nextItem;	/* Where to continue iterating */
+	unsigned nextItem;	/* Where to continue iterating */
 } ForLoop;
 
 
@@ -330,7 +330,7 @@ ExprLen(const char *s, const char *e)
  * by ApplyModifier_Defined.
  */
 static void
-AddEscaped(Buffer *cmds, Substring item, char endc)
+AddEscaped(Buffer *body, Substring item, char endc)
 {
 	const char *p;
 	char ch;
@@ -344,18 +344,18 @@ AddEscaped(Buffer *cmds, Substring item, char endc)
 				 * XXX: Should a '\' be added here?
 				 * See directive-for-escape.mk, ExprLen.
 				 */
-				Buf_AddBytes(cmds, p, 1 + len);
+				Buf_AddBytes(body, p, 1 + len);
 				p += 1 + len;
 				continue;
 			}
-			Buf_AddByte(cmds, '\\');
+			Buf_AddByte(body, '\\');
 		} else if (ch == ':' || ch == '\\' || ch == endc)
-			Buf_AddByte(cmds, '\\');
+			Buf_AddByte(body, '\\');
 		else if (ch == '\n') {
 			Parse_Error(PARSE_FATAL, "newline in .for value");
 			ch = ' ';	/* prevent newline injection */
 		}
-		Buf_AddByte(cmds, ch);
+		Buf_AddByte(body, ch);
 		p++;
 	}
 }
@@ -365,7 +365,7 @@ AddEscaped(Buffer *cmds, Substring item, char endc)
  * expression like ${i} or ${i:...} or $(i) or $(i:...) with ":Uvalue".
  */
 static void
-ForLoop_SubstVarLong(ForLoop *f, unsigned int firstItem, Buffer *body,
+ForLoop_SubstVarLong(ForLoop *f, unsigned firstItem, Buffer *body,
 		     const char **pp, char endc, const char **inout_mark)
 {
 	size_t i;
@@ -400,7 +400,7 @@ ForLoop_SubstVarLong(ForLoop *f, unsigned int firstItem, Buffer *body,
  * expressions like $i with their ${:U...} expansion.
  */
 static void
-ForLoop_SubstVarShort(ForLoop *f, unsigned int firstItem, Buffer *body,
+ForLoop_SubstVarShort(ForLoop *f, unsigned firstItem, Buffer *body,
 		      const char *p, const char **inout_mark)
 {
 	char ch = *p;
@@ -444,7 +444,7 @@ found:
  * See unit-tests/directive-for-escape.mk.
  */
 static void
-ForLoop_SubstBody(ForLoop *f, unsigned int firstItem, Buffer *body)
+ForLoop_SubstBody(ForLoop *f, unsigned firstItem, Buffer *body)
 {
 	const char *p, *end;
 	const char *mark;	/* where the last substitution left off */
@@ -479,8 +479,8 @@ For_NextIteration(ForLoop *f, Buffer *body)
 	if (f->nextItem == f->items.len)
 		return false;
 
-	f->nextItem += (unsigned int)f->vars.len;
-	ForLoop_SubstBody(f, f->nextItem - (unsigned int)f->vars.len, body);
+	f->nextItem += (unsigned)f->vars.len;
+	ForLoop_SubstBody(f, f->nextItem - (unsigned)f->vars.len, body);
 	if (DEBUG(FOR)) {
 		char *details = ForLoop_Details(f);
 		debug_printf("For: loop body with %s:\n%s",
@@ -494,7 +494,7 @@ For_NextIteration(ForLoop *f, Buffer *body)
 void
 For_Break(ForLoop *f)
 {
-	f->nextItem = (unsigned int)f->items.len;
+	f->nextItem = (unsigned)f->items.len;
 }
 
 /* Run the .for loop, imitating the actions of an include file. */
diff --git a/contrib/bmake/hash.c b/contrib/bmake/hash.c
index e84ef412bdef..663378626b89 100644
--- a/contrib/bmake/hash.c
+++ b/contrib/bmake/hash.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: hash.c,v 1.79 2024/07/07 09:37:00 rillig Exp $	*/
+/*	$NetBSD: hash.c,v 1.80 2025/04/22 19:28:50 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -74,7 +74,7 @@
 #include "make.h"
 
 /*	"@(#)hash.c	8.1 (Berkeley) 6/6/93"	*/
-MAKE_RCSID("$NetBSD: hash.c,v 1.79 2024/07/07 09:37:00 rillig Exp $");
+MAKE_RCSID("$NetBSD: hash.c,v 1.80 2025/04/22 19:28:50 rillig Exp $");
 
 /*
  * The ratio of # entries to # buckets at which we rebuild the table to
@@ -83,10 +83,10 @@ MAKE_RCSID("$NetBSD: hash.c,v 1.79 2024/07/07 09:37:00 rillig Exp $");
 #define rebuildLimit 3
 
 /* This hash function matches Gosling's Emacs and java.lang.String. */
-static unsigned int
+static unsigned
 Hash_String(const char *key, const char **out_keyEnd)
 {
-	unsigned int h;
+	unsigned h;
 	const char *p;
 
 	h = 0;
@@ -98,10 +98,10 @@ Hash_String(const char *key, const char **out_keyEnd)
 }
 
 /* This hash function matches Gosling's Emacs and java.lang.String. */
-unsigned int
+unsigned
 Hash_Substring(Substring key)
 {
-	unsigned int h;
+	unsigned h;
 	const char *p;
 
 	h = 0;
@@ -111,7 +111,7 @@ Hash_Substring(Substring key)
 }
 
 static HashEntry *
-HashTable_Find(HashTable *t, Substring key, unsigned int h)
+HashTable_Find(HashTable *t, Substring key, unsigned h)
 {
 	HashEntry *he;
 	size_t keyLen = Substring_Length(key);
@@ -135,7 +135,7 @@ HashTable_Find(HashTable *t, Substring key, unsigned int h)
 void
 HashTable_Init(HashTable *t)
 {
-	unsigned int n = 16, i;
+	unsigned n = 16, i;
 	HashEntry **buckets = bmake_malloc(sizeof *buckets * n);
 	for (i = 0; i < n; i++)
 		buckets[i] = NULL;
@@ -176,7 +176,7 @@ HashEntry *
 HashTable_FindEntry(HashTable *t, const char *key)
 {
 	const char *keyEnd;
-	unsigned int h = Hash_String(key, &keyEnd);
+	unsigned h = Hash_String(key, &keyEnd);
 	return HashTable_Find(t, Substring_Init(key, keyEnd), h);
 }
 
@@ -193,7 +193,7 @@ HashTable_FindValue(HashTable *t, const char *key)
  * or return NULL.
  */
 void *
-HashTable_FindValueBySubstringHash(HashTable *t, Substring key, unsigned int h)
+HashTable_FindValueBySubstringHash(HashTable *t, Substring key, unsigned h)
 {
 	HashEntry *he = HashTable_Find(t, key, h);
 	return he != NULL ? he->value : NULL;
@@ -220,10 +220,10 @@ HashTable_MaxChain(const HashTable *t)
 static void
 HashTable_Enlarge(HashTable *t)
 {
-	unsigned int oldSize = t->bucketsSize;
+	unsigned oldSize = t->bucketsSize;
 	HashEntry **oldBuckets = t->buckets;
-	unsigned int newSize = 2 * oldSize;
-	unsigned int newMask = newSize - 1;
+	unsigned newSize = 2 * oldSize;
+	unsigned newMask = newSize - 1;
 	HashEntry **newBuckets = bmake_malloc(sizeof *newBuckets * newSize);
 	size_t i;
 
@@ -257,7 +257,7 @@ HashEntry *
 HashTable_CreateEntry(HashTable *t, const char *key, bool *out_isNew)
 {
 	const char *keyEnd;
-	unsigned int h = Hash_String(key, &keyEnd);
+	unsigned h = Hash_String(key, &keyEnd);
 	HashEntry *he = HashTable_Find(t, Substring_Init(key, keyEnd), h);
 
 	if (he != NULL) {
@@ -313,7 +313,7 @@ HashIter_Next(HashIter *hi)
 	HashTable *t = hi->table;
 	HashEntry *he = hi->entry;
 	HashEntry **buckets = t->buckets;
-	unsigned int bucketsSize = t->bucketsSize;
+	unsigned bucketsSize = t->bucketsSize;
 
 	if (he != NULL)
 		he = he->next;	/* skip the most recently returned entry */
diff --git a/contrib/bmake/hash.h b/contrib/bmake/hash.h
index d6f9d03fb3ab..d9cf708dbd91 100644
--- a/contrib/bmake/hash.h
+++ b/contrib/bmake/hash.h
@@ -1,4 +1,4 @@
-/*	$NetBSD: hash.h,v 1.51 2024/07/07 09:37:00 rillig Exp $	*/
+/*	$NetBSD: hash.h,v 1.52 2025/04/22 19:28:50 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -82,22 +82,22 @@ typedef struct HashEntry {
 	struct HashEntry *next;	/* Used to link together all the entries
 				 * associated with the same bucket. */
 	void *value;
-	unsigned int hash;	/* hash value of the key */
+	unsigned hash;		/* hash value of the key */
 	char key[1];		/* key string, variable length */
 } HashEntry;
 
 /* The hash table containing the entries. */
 typedef struct HashTable {
 	HashEntry **buckets;
-	unsigned int bucketsSize;
-	unsigned int numEntries;
-	unsigned int bucketsMask; /* Used to select the bucket for a hash. */
+	unsigned bucketsSize;
+	unsigned numEntries;
+	unsigned bucketsMask;	/* Used to select the bucket for a hash. */
 } HashTable;
 
 /* State of an iteration over all entries in a table. */
 typedef struct HashIter {
 	HashTable *table;	/* Table being searched. */
-	unsigned int nextBucket; /* Next bucket to check (after current). */
+	unsigned nextBucket;	/* Next bucket to check (after current). */
 	HashEntry *entry;	/* Next entry to check in current bucket. */
 } HashIter;
 
@@ -131,8 +131,8 @@ void HashTable_Init(HashTable *);
 void HashTable_Done(HashTable *);
 HashEntry *HashTable_FindEntry(HashTable *, const char *) MAKE_ATTR_USE;
 void *HashTable_FindValue(HashTable *, const char *) MAKE_ATTR_USE;
-unsigned int Hash_Substring(Substring) MAKE_ATTR_USE;
-void *HashTable_FindValueBySubstringHash(HashTable *, Substring, unsigned int)
+unsigned Hash_Substring(Substring) MAKE_ATTR_USE;
+void *HashTable_FindValueBySubstringHash(HashTable *, Substring, unsigned)
     MAKE_ATTR_USE;
 HashEntry *HashTable_CreateEntry(HashTable *, const char *, bool *);
 void HashTable_Set(HashTable *, const char *, void *);
diff --git a/contrib/bmake/job.c b/contrib/bmake/job.c
index 2e6f44f722f2..582870088f2d 100644
--- a/contrib/bmake/job.c
+++ b/contrib/bmake/job.c
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.492 2025/04/12 13:00:21 rillig Exp $	*/
+/*	$NetBSD: job.c,v 1.516 2025/06/13 06:13:19 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -73,45 +73,29 @@
  * Create child processes and collect their output.
  *
  * Interface:
- *	Job_Init	Called to initialize this module. In addition,
- *			the .BEGIN target is made, including all of its
- *			dependencies before this function returns.
- *			Hence, the makefiles must have been parsed
- *			before this function is called.
+ *	Job_Init	Initialize this module and make the .BEGIN target.
  *
  *	Job_End		Clean up any memory used.
  *
- *	Job_Make	Start the creation of the given target.
+ *	Job_Make	Start making the given target.
  *
  *	Job_CatchChildren
- *			Check for and handle the termination of any
- *			children. This must be called reasonably
- *			frequently to keep the whole make going at
- *			a decent clip, since job table entries aren't
- *			removed until their process is caught this way.
+ *			Handle the termination of any children.
  *
  *	Job_CatchOutput
- *			Print any output our children have produced.
- *			Should also be called fairly frequently to
- *			keep the user informed of what's going on.
- *			If no output is waiting, it will block for
- *			a time given by the SEL_* constants, below,
- *			or until output is ready.
+ *			Print any output the child processes have produced.
  *
  *	Job_ParseShell	Given a special dependency line with target '.SHELL',
  *			define the shell that is used for the creation
  *			commands in jobs mode.
  *
- *	Job_Finish	Make the .END target. Should only be called when the
+ *	Job_Finish	Make the .END target. Must only be called when the
  *			job table is empty.
  *
- *	Job_AbortAll	Abort all currently running jobs. Do not handle
- *			output or do anything for the jobs, just kill them.
- *			Should only be called in an emergency.
+ *	Job_AbortAll	Kill all currently running jobs, in an emergency.
  *
  *	Job_CheckCommands
- *			Verify that the commands for a target are
- *			ok. Provide them if necessary and possible.
+ *			Add fallback commands to a target, if necessary.
  *
  *	Job_Touch	Update a target without really updating it.
  *
@@ -123,7 +107,6 @@
 #endif
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/file.h>
 #include <sys/time.h>
 #include "wait.h"
 
@@ -147,11 +130,111 @@
 #include "make.h"
 #include "dir.h"
 #include "job.h"
+#ifdef USE_META
+# include "meta.h"
+#endif
 #include "pathnames.h"
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.492 2025/04/12 13:00:21 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.516 2025/06/13 06:13:19 rillig Exp $");
+
+
+#ifdef USE_SELECT
+/*
+ * Emulate poll() in terms of select().  This is not a complete
+ * emulation but it is sufficient for make's purposes.
+ */
+
+#define poll emul_poll
+#define pollfd emul_pollfd
+
+struct emul_pollfd {
+	int fd;
+	short events;
+	short revents;
+};
+
+#define POLLIN		0x0001
+#define POLLOUT		0x0004
+
+int emul_poll(struct pollfd *, int, int);
+#endif
+
+struct pollfd;
+
+
+enum JobStatus {
+	JOB_ST_FREE,		/* Job is available */
+	JOB_ST_SET_UP,		/* Job is allocated but otherwise invalid */
+	JOB_ST_RUNNING,		/* Job is running, pid valid */
+	JOB_ST_FINISHED		/* Job is done (i.e. after SIGCHLD) */
+};
+
+static const char JobStatus_Name[][9] = {
+	"free",
+	"set-up",
+	"running",
+	"finished",
+};
+
+/*
+ * A Job manages the shell commands that are run to create a single target.
+ * Each job is run in a separate subprocess by a shell.  Several jobs can run
+ * in parallel.
+ *
+ * The shell commands for the target are written to a temporary file,
+ * then the shell is run with the temporary file as stdin, and the output
+ * of that shell is captured via a pipe.
+ *
+ * When a job is finished, Make_Update updates all parents of the node
+ * that was just remade, marking them as ready to be made next if all
+ * other dependencies are finished as well.
+ */
+struct Job {
+	/* The process ID of the shell running the commands */
+	int pid;
+
+	/* The target the child is making */
+	GNode *node;
+
+	/*
+	 * If one of the shell commands is "...", all following commands are
+	 * delayed until the .END node is made.  This list node points to the
+	 * first of these commands, if any.
+	 */
+	StringListNode *tailCmds;
+
+	/* This is where the shell commands go. */
+	FILE *cmdFILE;
+
+	int exit_status;	/* from wait4() in signal handler */
+
+	enum JobStatus status;
+
+	bool suspended;
+
+	/* Ignore non-zero exits */
+	bool ignerr;
+	/* Output the command before or instead of running it. */
+	bool echo;
+	/* Target is a special one. */
+	bool special;
+
+	int inPipe;		/* Pipe for reading output from job */
+	int outPipe;		/* Pipe for writing control commands */
+	struct pollfd *inPollfd; /* pollfd associated with inPipe */
+
+#define JOB_BUFSIZE	1024
+	/* Buffer for storing the output of the job, line by line. */
+	char outBuf[JOB_BUFSIZE + 1];
+	size_t outBufLen;
+
+#ifdef USE_META
+	struct BuildMon bm;
+#endif
+};
+
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -280,6 +363,8 @@ static enum {			/* Why is the make aborting? */
 } aborting = ABORT_NONE;
 #define JOB_TOKENS "+EI+"	/* Token to requeue for each abort state */
 
+static const char aborting_name[][6] = { "NONE", "ERROR", "INTR", "WAIT" };
+
 /* Tracks the number of tokens currently "out" to build jobs. */
 int jobTokensRunning = 0;
 
@@ -442,11 +527,12 @@ static void watchfd(Job *);
 static void clearfd(Job *);
 
 static char *targPrefix = NULL;	/* To identify a job change in the output. */
-static Job tokenWaitJob;	/* token wait pseudo-job */
+
+static Job tokenPoolJob;	/* token wait pseudo-job */
 
 static Job childExitJob;	/* child exit pseudo-job */
-#define CHILD_EXIT "."
-#define DO_JOB_RESUME "R"
+#define CEJ_CHILD_EXITED '.'
+#define CEJ_RESUME_JOBS 'R'
 
 enum {
 	npseudojobs = 2		/* number of pseudo-jobs */
@@ -457,7 +543,6 @@ static volatile sig_atomic_t caught_sigchld;
 
 static void CollectOutput(Job *, bool);
 static void JobInterrupt(bool, int) MAKE_ATTR_DEAD;
-static void JobRestartJobs(void);
 static void JobSigReset(void);
 
 static void
@@ -493,17 +578,38 @@ Job_FlagsToString(const Job *job, char *buf, size_t bufsize)
 	    job->special ? 'S' : '-');
 }
 
+#ifdef USE_META
+struct BuildMon *
+Job_BuildMon(Job *job)
+{
+	return &job->bm;
+}
+#endif
+
+GNode *
+Job_Node(Job *job)
+{
+	return job->node;
+}
+
*** 5506 LINES SKIPPED ***


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6962c5d1.24eb2.78b5d6b8>