xref: /freebsd/contrib/bmake/unit-tests/depsrc-ignore.mk (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1# $NetBSD: depsrc-ignore.mk,v 1.5 2020/11/15 20:20:58 rillig Exp $
2#
3# Tests for the special source .IGNORE in dependency declarations,
4# which ignores any command failures for that target.
5#
6# Even though 'ignore-errors' fails, 'all' is still made.  Since 'all' is
7# not marked with .IGNORE, it stops at the first failing command.
8#
9# XXX: The ordering of the messages in the output is confusing.
10# The "ignored" comes much too late to be related to the "false
11# ignore-errors".  This is due to stdout being buffered.
12#
13# The "continuing" message comes from the -k option.  If there had been
14# other targets independent of "all", these would be built as well.
15#
16# Enabling the debugging option -de changes the order in which the messages
17# appear.  Now the "ignored" message is issued in the correct position.
18# The explanation for the output reordering is that the output is buffered.
19# As the manual page says, in debugging mode stdout is line buffered.
20# In these tests the output is redirected to a file, therefore stdout is
21# fully buffered.
22#
23# This is what actually happens, as of 2020-08-29.  To verify it, set the
24# following breakpoints in CompatRunCommand:
25#
26# * the "!silent" line, to see all commands
27# * the "fflush" line, to see stdout being flushed
28# * the "status = WEXITSTATUS" line
29# * the "(continuing)" line
30# * the "(ignored)" line
31#
32# The breakpoints are visited in the following order:
33#
34# "ignore-errors begin"
35#	Goes directly to STDOUT_FILENO since it is run in a child process.
36# "false ignore-errors"
37#	Goes to the stdout buffer (CompatRunCommand, keyword "!silent") and
38#	the immediate call to fflush(stdout) copies it to STDOUT_FILENO.
39# "*** Error code 1 (ignored)"
40#	Goes to the stdout buffer but is not flushed (CompatRunCommand, near
41#	the end).
42# "ignore-errors end"
43#	Goes directly to STDOUT_FILENO.
44# "all begin"
45#	Goes directly to STDOUT_FILENO.
46# "false all"
47#	Goes to the stdout buffer, where the "*** Error code 1 (ignored)" is
48#	still waiting to be flushed.  These two lines are flushed now.
49# "*** Error code 1 (continuing)"
50#	Goes to the stdout buffer.
51# "Stop."
52#	Goes to the stdout buffer.
53# exit(1)
54#	Flushes the stdout buffer to STDOUT_FILENO.
55
56all: ignore-errors
57
58ignore-errors: .IGNORE
59	@echo $@ begin
60	false $@
61	@echo $@ end
62
63all:
64	@echo $@ begin
65	false $@
66	@echo $@ end
67