Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): in lint mode, exit with error status o...



details:   https://anonhg.NetBSD.org/src/rev/bd1e0b7a95ab
branches:  trunk
changeset: 956525:bd1e0b7a95ab
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Nov 01 00:24:57 2020 +0000

description:
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.

diffstat:

 usr.bin/make/main.c              |  12 ++++++++----
 usr.bin/make/nonints.h           |   3 ++-
 usr.bin/make/parse.c             |  10 ++++++++--
 usr.bin/make/unit-tests/lint.exp |   2 +-
 4 files changed, 19 insertions(+), 8 deletions(-)

diffs (111 lines):

diff -r 7c09ebe95abe -r bd1e0b7a95ab usr.bin/make/main.c
--- a/usr.bin/make/main.c       Sat Oct 31 23:44:42 2020 +0000
+++ b/usr.bin/make/main.c       Sun Nov 01 00:24:57 2020 +0000
@@ -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 @@
 int makelevel;
 
 Boolean forceJobs = FALSE;
+static int errors = 0;
 
 extern SearchPath *parseIncPath;
 
@@ -1600,6 +1601,8 @@
 
        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 @@
                        break;
                err_file = stderr;
        }
+       errors++;
 }
 
 /* Produce a Fatal error message, then exit immediately.
@@ -1889,11 +1893,11 @@
  * 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");
 }
 
 /*
diff -r 7c09ebe95abe -r bd1e0b7a95ab usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Sat Oct 31 23:44:42 2020 +0000
+++ b/usr.bin/make/nonints.h    Sun Nov 01 00:24:57 2020 +0000
@@ -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_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 {
diff -r 7c09ebe95abe -r bd1e0b7a95ab usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sat Oct 31 23:44:42 2020 +0000
+++ b/usr.bin/make/parse.c      Sun Nov 01 00:24:57 2020 +0000
@@ -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 @@
     Var_Append(".TARGETS", mainNode->name, VAR_GLOBAL);
     return mainList;
 }
+
+int
+Parse_GetFatals(void)
+{
+    return fatals;
+}
diff -r 7c09ebe95abe -r bd1e0b7a95ab usr.bin/make/unit-tests/lint.exp
--- a/usr.bin/make/unit-tests/lint.exp  Sat Oct 31 23:44:42 2020 +0000
+++ b/usr.bin/make/unit-tests/lint.exp  Sun Nov 01 00:24:57 2020 +0000
@@ -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



Home | Main Index | Thread Index | Old Index