Module Name:    src
Committed By:   rillig
Date:           Sun Nov  1 00:24:57 UTC 2020

Modified Files:
        src/usr.bin/make: main.c nonints.h parse.c
        src/usr.bin/make/unit-tests: lint.exp

Log Message:
make(1): in lint mode, exit with error status on errors

Calling Parse_Error during parsing has always led to a nonzero exit
status.  Calling Parse_Error later, when expanding the shell commands,
has had no effect on the exit status.  Neither had calling Error.

To make make a reliable tool, it has to report errors as they occur.
Enable this strict behavior in lint mode for now.  Lint mode has to be
enabled explicitly, preserving the default behavior.


To generate a diff of this commit:
cvs rdiff -u -r1.420 -r1.421 src/usr.bin/make/main.c
cvs rdiff -u -r1.148 -r1.149 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.419 -r1.420 src/usr.bin/make/parse.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/lint.exp

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.420 src/usr.bin/make/main.c:1.421
--- src/usr.bin/make/main.c:1.420	Sat Oct 31 21:09:22 2020
+++ src/usr.bin/make/main.c	Sun Nov  1 00:24:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.420 2020/10/31 21:09:22 sjg Exp $	*/
+/*	$NetBSD: main.c,v 1.421 2020/11/01 00:24:57 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -118,7 +118,7 @@
 #include "trace.h"
 
 /*	"@(#)main.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: main.c,v 1.420 2020/10/31 21:09:22 sjg Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.421 2020/11/01 00:24:57 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	    "The Regents of the University of California.  "
@@ -156,6 +156,7 @@ pid_t myPid;
 int makelevel;
 
 Boolean forceJobs = FALSE;
+static int errors = 0;
 
 extern SearchPath *parseIncPath;
 
@@ -1600,6 +1601,8 @@ main(int argc, char **argv)
 
 	CleanUp();
 
+	if (DEBUG(LINT) && (errors > 0 || Parse_GetFatals() > 0))
+	    return 2;		/* Not 1 so -q can distinguish error */
 	return outOfDate ? 1 : 0;
 }
 
@@ -1825,6 +1828,7 @@ Error(const char *fmt, ...)
 			break;
 		err_file = stderr;
 	}
+	errors++;
 }
 
 /* Produce a Fatal error message, then exit immediately.
@@ -1889,11 +1893,11 @@ DieHorribly(void)
  * The program exits.
  * Errors is the number of errors encountered in Make_Make. */
 void
-Finish(int errors)
+Finish(int errs)
 {
 	if (dieQuietly(NULL, -1))
 		exit(2);
-	Fatal("%d error%s", errors, errors == 1 ? "" : "s");
+	Fatal("%d error%s", errs, errs == 1 ? "" : "s");
 }
 
 /*

Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.148 src/usr.bin/make/nonints.h:1.149
--- src/usr.bin/make/nonints.h:1.148	Sat Oct 31 11:54:33 2020
+++ src/usr.bin/make/nonints.h	Sun Nov  1 00:24:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nonints.h,v 1.148 2020/10/31 11:54:33 rillig Exp $	*/
+/*	$NetBSD: nonints.h,v 1.149 2020/11/01 00:24:57 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -147,6 +147,7 @@ void Parse_AddIncludeDir(const char *);
 void Parse_File(const char *, int);
 void Parse_SetInput(const char *, int, int, NextBufProc, void *);
 GNodeList *Parse_MainName(void);
+int Parse_GetFatals(void);
 
 /* str.c */
 typedef struct Words {

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.419 src/usr.bin/make/parse.c:1.420
--- src/usr.bin/make/parse.c:1.419	Sat Oct 31 23:44:42 2020
+++ src/usr.bin/make/parse.c	Sun Nov  1 00:24:57 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.419 2020/10/31 23:44:42 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.420 2020/11/01 00:24:57 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.419 2020/10/31 23:44:42 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.420 2020/11/01 00:24:57 rillig Exp $");
 
 /* types and constants */
 
@@ -3221,3 +3221,9 @@ Parse_MainName(void)
     Var_Append(".TARGETS", mainNode->name, VAR_GLOBAL);
     return mainList;
 }
+
+int
+Parse_GetFatals(void)
+{
+    return fatals;
+}

Index: src/usr.bin/make/unit-tests/lint.exp
diff -u src/usr.bin/make/unit-tests/lint.exp:1.1 src/usr.bin/make/unit-tests/lint.exp:1.2
--- src/usr.bin/make/unit-tests/lint.exp:1.1	Mon Aug  3 15:43:32 2020
+++ src/usr.bin/make/unit-tests/lint.exp	Sun Nov  1 00:24:57 2020
@@ -1,4 +1,4 @@
 make: In the :@ modifier of "VAR", the variable name "${:Ubar:S,b,v,}" must not contain a dollar.
 y@:Q}
 xvaluey
-exit status 0
+exit status 2

Reply via email to