Module Name:    src
Committed By:   sjg
Date:           Sun Mar 10 02:53:38 UTC 2024

Modified Files:
        src/usr.bin/make: compat.c job.c main.c make.1 make.h targ.c

Log Message:
make: record exit status in GNode

SetErrorVars can now set .ERROR_EXIT which allows
a .ERROR target to ignore the case of .ERROR_EXIT == 6
which means failure happened elsewhere.

Reviewed by:


To generate a diff of this commit:
cvs rdiff -u -r1.253 -r1.254 src/usr.bin/make/compat.c
cvs rdiff -u -r1.466 -r1.467 src/usr.bin/make/job.c
cvs rdiff -u -r1.611 -r1.612 src/usr.bin/make/main.c
cvs rdiff -u -r1.374 -r1.375 src/usr.bin/make/make.1
cvs rdiff -u -r1.328 -r1.329 src/usr.bin/make/make.h
cvs rdiff -u -r1.179 -r1.180 src/usr.bin/make/targ.c

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/compat.c
diff -u src/usr.bin/make/compat.c:1.253 src/usr.bin/make/compat.c:1.254
--- src/usr.bin/make/compat.c:1.253	Fri Mar  1 16:41:42 2024
+++ src/usr.bin/make/compat.c	Sun Mar 10 02:53:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat.c,v 1.253 2024/03/01 16:41:42 sjg Exp $	*/
+/*	$NetBSD: compat.c,v 1.254 2024/03/10 02:53:37 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -91,7 +91,7 @@
 #include "pathnames.h"
 
 /*	"@(#)compat.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: compat.c,v 1.253 2024/03/01 16:41:42 sjg Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.254 2024/03/10 02:53:37 sjg Exp $");
 
 static GNode *curTarg = NULL;
 static pid_t compatChild;
@@ -390,6 +390,8 @@ Compat_RunCommand(const char *cmdp, GNod
 				meta_job_error(NULL, gn, false, status);
 #endif
 			gn->made = ERROR;
+			if (WIFEXITED(reason))
+				gn->exit_status = status;
 			if (opts.keepgoing) {
 				/*
 				 * Abort the current target,

Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.466 src/usr.bin/make/job.c:1.467
--- src/usr.bin/make/job.c:1.466	Fri Mar  1 16:41:42 2024
+++ src/usr.bin/make/job.c	Sun Mar 10 02:53:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: job.c,v 1.466 2024/03/01 16:41:42 sjg Exp $	*/
+/*	$NetBSD: job.c,v 1.467 2024/03/10 02:53:37 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -141,7 +141,7 @@
 #include "trace.h"
 
 /*	"@(#)job.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: job.c,v 1.466 2024/03/01 16:41:42 sjg Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.467 2024/03/10 02:53:37 sjg Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -2044,6 +2044,8 @@ JobReapChild(pid_t pid, int status, bool
 
 	job->status = JOB_ST_FINISHED;
 	job->exit_status = status;
+	if (WIFEXITED(status))
+		job->node->exit_status = WEXITSTATUS(status);
 
 	JobFinish(job, status);
 }

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.611 src/usr.bin/make/main.c:1.612
--- src/usr.bin/make/main.c:1.611	Fri Mar  1 16:41:42 2024
+++ src/usr.bin/make/main.c	Sun Mar 10 02:53:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.611 2024/03/01 16:41:42 sjg Exp $	*/
+/*	$NetBSD: main.c,v 1.612 2024/03/10 02:53:37 sjg 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.611 2024/03/01 16:41:42 sjg Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.612 2024/03/10 02:53:37 sjg Exp $");
 #if defined(MAKE_NATIVE)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	    "The Regents of the University of California.  "
@@ -2037,10 +2037,13 @@ static void
 SetErrorVars(GNode *gn)
 {
 	StringListNode *ln;
+	char sts[16];
 
 	/*
 	 * We can print this even if there is no .ERROR target.
 	 */
+	snprintf(sts, sizeof(sts), "%d", gn->exit_status);
+	Global_Set(".ERROR_EXIT", sts);
 	Global_Set(".ERROR_TARGET", gn->name);
 	Global_Delete(".ERROR_CMD");
 

Index: src/usr.bin/make/make.1
diff -u src/usr.bin/make/make.1:1.374 src/usr.bin/make/make.1:1.375
--- src/usr.bin/make/make.1:1.374	Thu Jan 25 21:00:59 2024
+++ src/usr.bin/make/make.1	Sun Mar 10 02:53:37 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: make.1,v 1.374 2024/01/25 21:00:59 sjg Exp $
+.\"	$NetBSD: make.1,v 1.375 2024/03/10 02:53:37 sjg 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 January 24, 2024
+.Dd March 9, 2024
 .Dt MAKE 1
 .Os
 .Sh NAME
@@ -879,6 +879,9 @@ Is used in error handling, see
 .It Va .ERROR_CWD
 Is used in error handling, see
 .Va MAKE_PRINT_VAR_ON_ERROR .
+.It Va .ERROR_EXIT
+Is used in error handling, see
+.Va MAKE_PRINT_VAR_ON_ERROR .
 .It Va .ERROR_META_FILE
 Is used in error handling in
 .Dq meta
@@ -1185,6 +1188,8 @@ When
 stops due to an error, it sets
 .Sq Va .ERROR_TARGET
 to the name of the target that failed,
+.Sq Va .ERROR_EXIT
+to the exit status of the failed target,
 .Sq Va .ERROR_CMD
 to the commands of the failed target,
 and in
@@ -2405,11 +2410,9 @@ Any command lines attached to this targe
 else is done successfully.
 .It Ic .ERROR
 Any command lines attached to this target are executed when another target fails.
-The
-.Va .ERROR_TARGET
-variable is set to the target that failed.
-See also
-.Va MAKE_PRINT_VAR_ON_ERROR .
+See 
+.Va MAKE_PRINT_VAR_ON_ERROR
+for the variables that will be set.
 .It Ic .IGNORE
 Mark each of the sources with the
 .Ic .IGNORE

Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.328 src/usr.bin/make/make.h:1.329
--- src/usr.bin/make/make.h:1.328	Fri Mar  1 16:41:42 2024
+++ src/usr.bin/make/make.h	Sun Mar 10 02:53:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.h,v 1.328 2024/03/01 16:41:42 sjg Exp $	*/
+/*	$NetBSD: make.h,v 1.329 2024/03/10 02:53:37 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -504,6 +504,7 @@ typedef struct GNode {
 	const char *fname;
 	/* Line number where the GNode got defined, 1-based */
 	unsigned lineno;
+	int exit_status;
 } GNode;
 
 /*

Index: src/usr.bin/make/targ.c
diff -u src/usr.bin/make/targ.c:1.179 src/usr.bin/make/targ.c:1.180
--- src/usr.bin/make/targ.c:1.179	Tue Dec  6 00:12:44 2022
+++ src/usr.bin/make/targ.c	Sun Mar 10 02:53:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: targ.c,v 1.179 2022/12/06 00:12:44 rillig Exp $	*/
+/*	$NetBSD: targ.c,v 1.180 2024/03/10 02:53:37 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -107,7 +107,7 @@
 #include "dir.h"
 
 /*	"@(#)targ.c	8.2 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: targ.c,v 1.179 2022/12/06 00:12:44 rillig Exp $");
+MAKE_RCSID("$NetBSD: targ.c,v 1.180 2024/03/10 02:53:37 sjg Exp $");
 
 /*
  * All target nodes that appeared on the left-hand side of one of the
@@ -201,6 +201,7 @@ GNode_New(const char *name)
 	gn->suffix = NULL;
 	gn->fname = NULL;
 	gn->lineno = 0;
+	gn->exit_status = 0;
 
 #ifdef CLEANUP
 	Lst_Append(&allNodes, gn);

Reply via email to