1# $NetBSD: opt-keep-going-indirect.mk,v 1.2 2022/02/12 20:05:36 rillig Exp $
2#
3# Tests for the -k command line option, which stops building a target as soon
4# as an error is detected, but continues building the other, independent
5# targets, as far as possible.
6#
7# History:
8#	In 1993, the exit status for the option '-k' was always 0, even if a
9#	direct or an indirect target failed.
10#
11#	Since 2000.12.30.02.05.21, the word '(continuing)' is missing in jobs
12#	mode, both for direct as well as indirect targets.
13#
14#	Since 2001.10.16.18.50.12, the exit status for a direct failure in
15#	compat mode is the correct 1, while jobs mode and indirect failures
16#	still return the wrong exit status 0.  The number of empty lines
17#	between the various error messages differs between the modes, for no
18#	reason.
19#
20#	At 2006.11.17.22.07.39, the exit status for direct failures in both
21#	modes and for indirect failures in jobs mode was fixed to the correct
22#	1.  The exit status for indirect failures in compat mode is still the
23#	wrong 0.  On the downside, a failed indirect target in jobs mode is no
24#	longer listed as "not remade because of errors".
25#
26#	At 2016.08.26.23.28.39, the additional empty line for a direct failure
27#	in compat mode was removed, making it consistent with a direct failure
28#	in jobs mode.  This left only one inconsistency, in that indirect
29#	failures in jobs mode (by far the most common when building large
30#	projects) did not produce any empty line.
31#
32#	Since 2020.12.07.00.53.30, the exit status is consistently 1 for
33#	failures in all 4 modes.
34#
35# Bugs:
36#	The output in case of a failure needlessly differs between compat and
37#	jobs mode.  As of 2022-02-12, compat mode outputs '(continuing)' while
38#	jobs mode doesn't.  In compat mode, the output does not mention which
39#	target failed.
40#
41# See also:
42#	https://gnats.netbsd.org/49720
43
44.PHONY: all direct indirect
45
46# The 'set +e' was necessary in 2003, when the shell was run with '-e' by
47# default.
48# The 'env -i' prevents that the environment variable MAKEFLAGS is passed down
49# to the child processes.
50all:
51	@echo 'direct compat'
52	@set +e; env -i ${MAKE} -r -f ${MAKEFILE} -k direct; echo "exited $$?"
53	@echo
54
55	@echo 'direct jobs'
56	@set +e; env -i ${MAKE} -r -f ${MAKEFILE} -k direct -j1; echo "exited $$?"
57	@echo
58
59	@echo 'indirect compat'
60	@set +e; env -i ${MAKE} -r -f ${MAKEFILE} -k indirect; echo "exited $$?"
61	@echo
62
63	@echo 'indirect jobs'
64	@set +e; env -i ${MAKE} -r -f ${MAKEFILE} -k indirect -j1; echo "exited $$?"
65	@echo
66
67indirect: direct
68direct:
69	false
70
71# TODO: Mention the target that failed, maybe even the chain of targets.
72# expect: direct compat
73# expect: *** Error code 1 (continuing)
74# expect: exited 1
75
76# TODO: Add '(continuing)'.
77# expect: direct jobs
78# expect: *** [direct] Error code 1
79# expect: exited 1
80
81# TODO: Mention the target that failed, maybe even the chain of targets.
82# expect: indirect compat
83# expect: *** Error code 1 (continuing)
84# expect: exited 1
85
86# TODO: Add '(continuing)'.
87# TODO: Add 'not remade because of errors'.
88# expect: indirect jobs
89# expect: *** [direct] Error code 1
90# expect: exited 1
91