xref: /freebsd/contrib/bmake/unit-tests/depsrc-ignore.mk (revision e2eeea75eb8b6dd50c1298067a0655880d186734)
1*e2eeea75SSimon J. Gerraty# $NetBSD: depsrc-ignore.mk,v 1.5 2020/11/15 20:20:58 rillig Exp $
22c3632d1SSimon J. Gerraty#
32c3632d1SSimon J. Gerraty# Tests for the special source .IGNORE in dependency declarations,
42c3632d1SSimon J. Gerraty# which ignores any command failures for that target.
52c3632d1SSimon J. Gerraty#
6*e2eeea75SSimon J. Gerraty# Even though 'ignore-errors' fails, 'all' is still made.  Since 'all' is
7*e2eeea75SSimon J. Gerraty# not marked with .IGNORE, it stops at the first failing command.
82c3632d1SSimon J. Gerraty#
92c3632d1SSimon J. Gerraty# XXX: The ordering of the messages in the output is confusing.
102c3632d1SSimon J. Gerraty# The "ignored" comes much too late to be related to the "false
112c3632d1SSimon J. Gerraty# ignore-errors".  This is due to stdout being buffered.
122c3632d1SSimon J. Gerraty#
132c3632d1SSimon J. Gerraty# The "continuing" message comes from the -k option.  If there had been
142c3632d1SSimon J. Gerraty# other targets independent of "all", these would be built as well.
152c3632d1SSimon J. Gerraty#
162c3632d1SSimon J. Gerraty# Enabling the debugging option -de changes the order in which the messages
172c3632d1SSimon J. Gerraty# appear.  Now the "ignored" message is issued in the correct position.
182c3632d1SSimon J. Gerraty# The explanation for the output reordering is that the output is buffered.
192c3632d1SSimon J. Gerraty# As the manual page says, in debugging mode stdout is line buffered.
202c3632d1SSimon J. Gerraty# In these tests the output is redirected to a file, therefore stdout is
212c3632d1SSimon J. Gerraty# fully buffered.
222c3632d1SSimon J. Gerraty#
232c3632d1SSimon J. Gerraty# This is what actually happens, as of 2020-08-29.  To verify it, set the
242c3632d1SSimon J. Gerraty# following breakpoints in CompatRunCommand:
252c3632d1SSimon J. Gerraty#
26*e2eeea75SSimon J. Gerraty# * the "!silent" line, to see all commands
27*e2eeea75SSimon J. Gerraty# * the "fflush" line, to see stdout being flushed
282c3632d1SSimon J. Gerraty# * the "status = WEXITSTATUS" line
292c3632d1SSimon J. Gerraty# * the "(continuing)" line
302c3632d1SSimon J. Gerraty# * the "(ignored)" line
312c3632d1SSimon J. Gerraty#
322c3632d1SSimon J. Gerraty# The breakpoints are visited in the following order:
332c3632d1SSimon J. Gerraty#
342c3632d1SSimon J. Gerraty# "ignore-errors begin"
352c3632d1SSimon J. Gerraty#	Goes directly to STDOUT_FILENO since it is run in a child process.
362c3632d1SSimon J. Gerraty# "false ignore-errors"
372c3632d1SSimon J. Gerraty#	Goes to the stdout buffer (CompatRunCommand, keyword "!silent") and
382c3632d1SSimon J. Gerraty#	the immediate call to fflush(stdout) copies it to STDOUT_FILENO.
392c3632d1SSimon J. Gerraty# "*** Error code 1 (ignored)"
402c3632d1SSimon J. Gerraty#	Goes to the stdout buffer but is not flushed (CompatRunCommand, near
412c3632d1SSimon J. Gerraty#	the end).
422c3632d1SSimon J. Gerraty# "ignore-errors end"
432c3632d1SSimon J. Gerraty#	Goes directly to STDOUT_FILENO.
442c3632d1SSimon J. Gerraty# "all begin"
452c3632d1SSimon J. Gerraty#	Goes directly to STDOUT_FILENO.
462c3632d1SSimon J. Gerraty# "false all"
472c3632d1SSimon J. Gerraty#	Goes to the stdout buffer, where the "*** Error code 1 (ignored)" is
482c3632d1SSimon J. Gerraty#	still waiting to be flushed.  These two lines are flushed now.
492c3632d1SSimon J. Gerraty# "*** Error code 1 (continuing)"
502c3632d1SSimon J. Gerraty#	Goes to the stdout buffer.
512c3632d1SSimon J. Gerraty# "Stop."
522c3632d1SSimon J. Gerraty#	Goes to the stdout buffer.
532c3632d1SSimon J. Gerraty# exit(1)
542c3632d1SSimon J. Gerraty#	Flushes the stdout buffer to STDOUT_FILENO.
552c3632d1SSimon J. Gerraty
562c3632d1SSimon J. Gerratyall: ignore-errors
572c3632d1SSimon J. Gerraty
582c3632d1SSimon J. Gerratyignore-errors: .IGNORE
592c3632d1SSimon J. Gerraty	@echo $@ begin
602c3632d1SSimon J. Gerraty	false $@
612c3632d1SSimon J. Gerraty	@echo $@ end
622c3632d1SSimon J. Gerraty
632c3632d1SSimon J. Gerratyall:
642c3632d1SSimon J. Gerraty	@echo $@ begin
652c3632d1SSimon J. Gerraty	false $@
662c3632d1SSimon J. Gerraty	@echo $@ end
67