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): fix exit status in -k mode if a depend...



details:   https://anonhg.NetBSD.org/src/rev/b07c5bbdc9e7
branches:  trunk
changeset: 946731:b07c5bbdc9e7
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Dec 07 00:53:30 2020 +0000

description:
make(1): fix exit status in -k mode if a dependency fails

Whether in -k mode or not, the exit status tells whether all requested
targets were made or not.  If a dependency could not be made, the main
target was not made as well, therefore the exit status must be nonzero
in such a case.

This part of the code lacked proper unit tests until today.  The unit
test deptgt-end-fail.mk is compatible with make>=2003 at least, allowing
to compare the output over time.

In 2003, in the ok-ok-ok-ok case, "Making all from all-dep." was printed
twice in a row, for whatever reason  ... (40 minutes later) ... If I had
just made the two commands for 'all' and '.END' more distinguishable.
Back in 2003, the local variables for .END had not been initialized,
instead the .END node was run with the local variables of the last
preceding node.  In this case, that node was 'all', therefore ${.TARGET}
had obviously expanded to 'all'.

Somewhere in 2004, the shell commands were no longer run with the -e
flag, which resulted in the "exit status $?" line to be printed in cases
that had stopped early before.

Somewhere in 2005, the local variables for the .END node had been fixed.
The variable ${.TARGET} now had the value '.END', just as expected.  In
addition, the dependencies for the .END node were made, although without
getting their proper local variables.  This resulted in the output
"Making  out of nothing" instead of the expected "Making end-dep out of
nothing".

Still in 2005, in the test case "all=ok all-dep=ok end=ok end-dep=ERR",
the error code of the failed 'end-dep' was first reported as "*** Error
code 1 (continuing)".  To compensate for this improvement, a new bug had
been introduced.  The test case "all=ok all-dep=ok end=ERR end-dep=ERR"
had properly exited with status 1 on 2005-01-01, but on 2006-01-01 it
exited with status 0, thereby ignoring errors in the .END node.

Somewhere in 2008, some of the error messages (but not all) were
directed to stderr instead of stdout.  The actual output stayed the same
though.

Somewhere in 2011, the dependency of the .END node got its own local
variables, and ${.TARGET} now expanded to 'end-dep', as expected.

Somewhere in 2016, the two empty lines between the "*** Error code 1
(continuing)" and the "Stop." got compressed into a single empty line.

On 2020-12-07 (that is, today), the exit status 1 has been restored in
the error cases, after it had been wrong for at least 14 years.

diffstat:

 usr.bin/make/compat.c                              |   6 +-
 usr.bin/make/unit-tests/dep-percent.exp            |   5 ++-
 usr.bin/make/unit-tests/deptgt-end-fail.exp        |  40 +++++++++++++++++----
 usr.bin/make/unit-tests/deptgt-end-fail.mk         |   7 ++-
 usr.bin/make/unit-tests/opt-debug-errors.exp       |   5 ++-
 usr.bin/make/unit-tests/opt-file.exp               |   5 ++-
 usr.bin/make/unit-tests/opt-keep-going.exp         |   5 ++-
 usr.bin/make/unit-tests/opt-keep-going.mk          |   6 ++-
 usr.bin/make/unit-tests/posix.exp                  |   5 ++-
 usr.bin/make/unit-tests/suff-add-later.exp         |   5 ++-
 usr.bin/make/unit-tests/suff-clear-regular.exp     |   5 ++-
 usr.bin/make/unit-tests/suff-clear-regular.mk      |   3 +-
 usr.bin/make/unit-tests/suff-clear-single.exp      |   5 ++-
 usr.bin/make/unit-tests/suff-main-several.exp      |   5 ++-
 usr.bin/make/unit-tests/suff-self.exp              |   5 ++-
 usr.bin/make/unit-tests/suff-transform-endless.exp |   5 ++-
 usr.bin/make/unit-tests/suff-transform-expand.exp  |   5 ++-
 usr.bin/make/unit-tests/suff-transform-select.exp  |   5 ++-
 usr.bin/make/unit-tests/use-inference.exp          |   5 ++-
 usr.bin/make/unit-tests/use-inference.mk           |   6 +-
 20 files changed, 104 insertions(+), 34 deletions(-)

diffs (truncated from 355 to 300 lines):

diff -r 91b575036946 -r b07c5bbdc9e7 usr.bin/make/compat.c
--- a/usr.bin/make/compat.c     Sun Dec 06 23:02:56 2020 +0000
+++ b/usr.bin/make/compat.c     Mon Dec 07 00:53:30 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat.c,v 1.198 2020/12/06 23:02:56 rillig Exp $      */
+/*     $NetBSD: compat.c,v 1.199 2020/12/07 00:53:30 rillig Exp $      */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -96,7 +96,7 @@
 #include "pathnames.h"
 
 /*     "@(#)compat.c   8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: compat.c,v 1.198 2020/12/06 23:02:56 rillig Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.199 2020/12/07 00:53:30 rillig Exp $");
 
 static GNode *curTarg = NULL;
 static pid_t compatChild;
@@ -736,7 +736,7 @@
        } else
                endError = FALSE;
 
-       if (!mainDepError && (mainError || endError)) {
+       if (mainDepError || mainError || endError) {
                PrintOnError(gn, "\nStop.");
                exit(1);
        }
diff -r 91b575036946 -r b07c5bbdc9e7 usr.bin/make/unit-tests/dep-percent.exp
--- a/usr.bin/make/unit-tests/dep-percent.exp   Sun Dec 06 23:02:56 2020 +0000
+++ b/usr.bin/make/unit-tests/dep-percent.exp   Mon Dec 07 00:53:30 2020 +0000
@@ -1,3 +1,6 @@
 make: don't know how to make dep-percent.o (continuing)
 `all' not remade because of errors.
-exit status 0
+
+Stop.
+make: stopped in unit-tests
+exit status 1
diff -r 91b575036946 -r b07c5bbdc9e7 usr.bin/make/unit-tests/deptgt-end-fail.exp
--- a/usr.bin/make/unit-tests/deptgt-end-fail.exp       Sun Dec 06 23:02:56 2020 +0000
+++ b/usr.bin/make/unit-tests/deptgt-end-fail.exp       Mon Dec 07 00:53:30 2020 +0000
@@ -44,28 +44,40 @@
 : Making all-dep out of nothing.
 *** Error code 1 (continuing)
 `all' not remade because of errors.
-exit status 0
+
+Stop.
+make: stopped in unit-tests
+exit status 1
 
 
 Test case all=ok all-dep=ERR end=ok end-dep=ERR.
 : Making all-dep out of nothing.
 *** Error code 1 (continuing)
 `all' not remade because of errors.
-exit status 0
+
+Stop.
+make: stopped in unit-tests
+exit status 1
 
 
 Test case all=ok all-dep=ERR end=ERR end-dep=ok.
 : Making all-dep out of nothing.
 *** Error code 1 (continuing)
 `all' not remade because of errors.
-exit status 0
+
+Stop.
+make: stopped in unit-tests
+exit status 1
 
 
 Test case all=ok all-dep=ERR end=ERR end-dep=ERR.
 : Making all-dep out of nothing.
 *** Error code 1 (continuing)
 `all' not remade because of errors.
-exit status 0
+
+Stop.
+make: stopped in unit-tests
+exit status 1
 
 
 Test case all=ERR all-dep=ok end=ok end-dep=ok.
@@ -121,28 +133,40 @@
 : Making all-dep out of nothing.
 *** Error code 1 (continuing)
 `all' not remade because of errors.
-exit status 0
+
+Stop.
+make: stopped in unit-tests
+exit status 1
 
 
 Test case all=ERR all-dep=ERR end=ok end-dep=ERR.
 : Making all-dep out of nothing.
 *** Error code 1 (continuing)
 `all' not remade because of errors.
-exit status 0
+
+Stop.
+make: stopped in unit-tests
+exit status 1
 
 
 Test case all=ERR all-dep=ERR end=ERR end-dep=ok.
 : Making all-dep out of nothing.
 *** Error code 1 (continuing)
 `all' not remade because of errors.
-exit status 0
+
+Stop.
+make: stopped in unit-tests
+exit status 1
 
 
 Test case all=ERR all-dep=ERR end=ERR end-dep=ERR.
 : Making all-dep out of nothing.
 *** Error code 1 (continuing)
 `all' not remade because of errors.
-exit status 0
+
+Stop.
+make: stopped in unit-tests
+exit status 1
 
 
 exit status 0
diff -r 91b575036946 -r b07c5bbdc9e7 usr.bin/make/unit-tests/deptgt-end-fail.mk
--- a/usr.bin/make/unit-tests/deptgt-end-fail.mk        Sun Dec 06 23:02:56 2020 +0000
+++ b/usr.bin/make/unit-tests/deptgt-end-fail.mk        Mon Dec 07 00:53:30 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: deptgt-end-fail.mk,v 1.4 2020/12/06 22:36:58 rillig Exp $
+# $NetBSD: deptgt-end-fail.mk,v 1.5 2020/12/07 00:53:30 rillig Exp $
 #
 # Tests for an errors in the main target, its dependencies,
 # the .END node and its dependencies.
@@ -59,8 +59,9 @@
 
 .endif
 
-# XXX: As of 2020-12-06, several of the test cases printed "`all' not remade
-# because of errors.", followed by "exit status 0".  This doesn't match.
+# Until 2020-12-07, several of the test cases printed "`all' not remade
+# because of errors.", followed by "exit status 0", which contradicted
+# each other.
 
 # XXX: As of 2020-12-06, '.END' is made if 'all' fails, but if a dependency
 # of 'all' fails, it is skipped.  This is inconsistent.
diff -r 91b575036946 -r b07c5bbdc9e7 usr.bin/make/unit-tests/opt-debug-errors.exp
--- a/usr.bin/make/unit-tests/opt-debug-errors.exp      Sun Dec 06 23:02:56 2020 +0000
+++ b/usr.bin/make/unit-tests/opt-debug-errors.exp      Mon Dec 07 00:53:30 2020 +0000
@@ -31,4 +31,7 @@
 *** Failed command: echo 'word1' 'word2'; false
 *** Error code 1 (continuing)
 `all' not remade because of errors.
-exit status 0
+
+Stop.
+make: stopped in unit-tests
+exit status 1
diff -r 91b575036946 -r b07c5bbdc9e7 usr.bin/make/unit-tests/opt-file.exp
--- a/usr.bin/make/unit-tests/opt-file.exp      Sun Dec 06 23:02:56 2020 +0000
+++ b/usr.bin/make/unit-tests/opt-file.exp      Mon Dec 07 00:53:30 2020 +0000
@@ -4,4 +4,7 @@
 make: stopped in unit-tests
 *** Error code 1 (continuing)
 `all' not remade because of errors.
-exit status 0
+
+Stop.
+make: stopped in unit-tests
+exit status 1
diff -r 91b575036946 -r b07c5bbdc9e7 usr.bin/make/unit-tests/opt-keep-going.exp
--- a/usr.bin/make/unit-tests/opt-keep-going.exp        Sun Dec 06 23:02:56 2020 +0000
+++ b/usr.bin/make/unit-tests/opt-keep-going.exp        Mon Dec 07 00:53:30 2020 +0000
@@ -3,4 +3,7 @@
 other 1
 *** Error code 1 (continuing)
 `all' not remade because of errors.
-exit status 0
+
+Stop.
+make: stopped in unit-tests
+exit status 1
diff -r 91b575036946 -r b07c5bbdc9e7 usr.bin/make/unit-tests/opt-keep-going.mk
--- a/usr.bin/make/unit-tests/opt-keep-going.mk Sun Dec 06 23:02:56 2020 +0000
+++ b/usr.bin/make/unit-tests/opt-keep-going.mk Mon Dec 07 00:53:30 2020 +0000
@@ -1,8 +1,12 @@
-# $NetBSD: opt-keep-going.mk,v 1.5 2020/11/09 20:50:56 rillig Exp $
+# $NetBSD: opt-keep-going.mk,v 1.6 2020/12/07 00:53:30 rillig Exp $
 #
 # Tests for the -k command line option, which stops building a target as soon
 # as an error is detected, but continues building the other, independent
 # targets, as far as possible.
+#
+# Until 2020-12-07, if a dependency of the main target failed, the exit
+# status was nevertheless 0, which was wrong since the main targets could
+# not be made.  This was only wrong in -k mode combined with compat mode.
 
 .MAKEFLAGS: -d0                        # switch stdout to being line-buffered
 .MAKEFLAGS: -k
diff -r 91b575036946 -r b07c5bbdc9e7 usr.bin/make/unit-tests/posix.exp
--- a/usr.bin/make/unit-tests/posix.exp Sun Dec 06 23:02:56 2020 +0000
+++ b/usr.bin/make/unit-tests/posix.exp Mon Dec 07 00:53:30 2020 +0000
@@ -20,4 +20,7 @@
 Now we expect an error...
 *** Error code 1 (continuing)
 `all' not remade because of errors.
-exit status 0
+
+Stop.
+make: stopped in unit-tests
+exit status 1
diff -r 91b575036946 -r b07c5bbdc9e7 usr.bin/make/unit-tests/suff-add-later.exp
--- a/usr.bin/make/unit-tests/suff-add-later.exp        Sun Dec 06 23:02:56 2020 +0000
+++ b/usr.bin/make/unit-tests/suff-add-later.exp        Mon Dec 07 00:53:30 2020 +0000
@@ -15,4 +15,7 @@
 make: don't know how to make issue5d.e (continuing)
 make: don't know how to make issue5e.d (continuing)
 `all' not remade because of errors.
-exit status 0
+
+Stop.
+make: stopped in unit-tests
+exit status 1
diff -r 91b575036946 -r b07c5bbdc9e7 usr.bin/make/unit-tests/suff-clear-regular.exp
--- a/usr.bin/make/unit-tests/suff-clear-regular.exp    Sun Dec 06 23:02:56 2020 +0000
+++ b/usr.bin/make/unit-tests/suff-clear-regular.exp    Mon Dec 07 00:53:30 2020 +0000
@@ -2,4 +2,7 @@
 make: don't know how to make .a.b (continuing)
 make: don't know how to make .b.a (continuing)
 `all' not remade because of errors.
-exit status 0
+
+Stop.
+make: stopped in unit-tests
+exit status 1
diff -r 91b575036946 -r b07c5bbdc9e7 usr.bin/make/unit-tests/suff-clear-regular.mk
--- a/usr.bin/make/unit-tests/suff-clear-regular.mk     Sun Dec 06 23:02:56 2020 +0000
+++ b/usr.bin/make/unit-tests/suff-clear-regular.mk     Mon Dec 07 00:53:30 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: suff-clear-regular.mk,v 1.1 2020/10/20 20:36:53 rillig Exp $
+# $NetBSD: suff-clear-regular.mk,v 1.2 2020/12/07 00:53:30 rillig Exp $
 #
 # https://gnats.netbsd.org/49086, issue 4:
 # Suffix rules do not become regular rules when .SUFFIXES is cleared.
@@ -27,5 +27,4 @@
 # XXX: don't know how to make .a
 # XXX: don't know how to make .a.b
 # XXX: don't know how to make .b.a
-# XXX: exit status 0
 #.MAKEFLAGS: -dg1
diff -r 91b575036946 -r b07c5bbdc9e7 usr.bin/make/unit-tests/suff-clear-single.exp
--- a/usr.bin/make/unit-tests/suff-clear-single.exp     Sun Dec 06 23:02:56 2020 +0000
+++ b/usr.bin/make/unit-tests/suff-clear-single.exp     Mon Dec 07 00:53:30 2020 +0000
@@ -1,3 +1,6 @@
 make: don't know how to make issue3 (continuing)
 `all' not remade because of errors.
-exit status 0
+
+Stop.
+make: stopped in unit-tests
+exit status 1
diff -r 91b575036946 -r b07c5bbdc9e7 usr.bin/make/unit-tests/suff-main-several.exp
--- a/usr.bin/make/unit-tests/suff-main-several.exp     Sun Dec 06 23:02:56 2020 +0000
+++ b/usr.bin/make/unit-tests/suff-main-several.exp     Mon Dec 07 00:53:30 2020 +0000
@@ -137,4 +137,7 @@
 make: don't know how to make suff-main-several.3 (continuing)
 make: don't know how to make suff-main-several.4 (continuing)
 `next-main' not remade because of errors.
-exit status 0
+
+Stop.
+make: stopped in unit-tests
+exit status 1
diff -r 91b575036946 -r b07c5bbdc9e7 usr.bin/make/unit-tests/suff-self.exp
--- a/usr.bin/make/unit-tests/suff-self.exp     Sun Dec 06 23:02:56 2020 +0000
+++ b/usr.bin/make/unit-tests/suff-self.exp     Mon Dec 07 00:53:30 2020 +0000
@@ -1,3 +1,6 @@
 make: Graph cycles through suff-self.suff
 `all' not remade because of errors.
-exit status 0
+
+Stop.
+make: stopped in unit-tests
+exit status 1
diff -r 91b575036946 -r b07c5bbdc9e7 usr.bin/make/unit-tests/suff-transform-endless.exp
--- a/usr.bin/make/unit-tests/suff-transform-endless.exp        Sun Dec 06 23:02:56 2020 +0000
+++ b/usr.bin/make/unit-tests/suff-transform-endless.exp        Mon Dec 07 00:53:30 2020 +0000
@@ -40,4 +40,7 @@
 suffix is ".e"...
 make: Graph cycles through issue6.f
 `all' not remade because of errors.
-exit status 0
+
+Stop.



Home | Main Index | Thread Index | Old Index