[SV 56301] Fail if an included makefile can't be built

Fail if a mandatory include file fails to be built even if it's
built as part of a grouped target where the other include file
is optional.

* src/main.c (main): If a makefile doesn't build set any_failed.
* tests/scripts/features/include: Add tests.
* tests/scripts/options/dash-k: Stop after include build failure.
This commit is contained in:
Dmitry Goncharov 2022-09-20 03:08:29 -04:00 committed by Paul Smith
parent d12ff78cb2
commit a9a4919909
3 changed files with 36 additions and 31 deletions

View file

@ -2499,6 +2499,7 @@ main (int argc, char **argv, char **envp)
any_remade |= (mtime != NONEXISTENT_MTIME any_remade |= (mtime != NONEXISTENT_MTIME
&& mtime != makefile_mtimes[i]); && mtime != makefile_mtimes[i]);
makefile_status = MAKE_FAILURE; makefile_status = MAKE_FAILURE;
any_failed = 1;
} }
} }

View file

@ -8,16 +8,11 @@ Test extra whitespace at the end of the include, multiple -includes and
sincludes (should not give an error) and make sure that errors are reported sincludes (should not give an error) and make sure that errors are reported
for targets that were also -included."; for targets that were also -included.";
$makefile2 = &get_tmpfile; create_file('incl.mk', "ANOTHER: ; \@echo This is another included makefile\n");
open(MAKEFILE,"> $makefile"); run_make_test(qq!#Extra space at the end of the following file name
include incl.mk ! . q!
# The contents of the Makefile ... all: ; @echo There should be no errors for this makefile.
print MAKEFILE <<EOF;
\#Extra space at the end of the following file name
include $makefile2
all: ; \@echo There should be no errors for this makefile.
-include nonexistent.mk -include nonexistent.mk
-include nonexistent.mk -include nonexistent.mk
@ -27,27 +22,12 @@ sinclude nonexistent-2.mk
sinclude makeit.mk sinclude makeit.mk
error: makeit.mk error: makeit.mk
EOF !,
"all", "There should be no errors for this makefile.\n");
close(MAKEFILE); run_make_test(undef, "ANOTHER", "This is another included makefile\n");
unlink('incl.mk');
open(MAKEFILE,"> $makefile2");
print MAKEFILE "ANOTHER: ; \@echo This is another included makefile\n";
close(MAKEFILE);
# Create the answer to what should be produced by this Makefile
&run_make_with_options($makefile, "all", &get_logfile);
$answer = "There should be no errors for this makefile.\n";
&compare_output($answer, &get_logfile(1));
&run_make_with_options($makefile, "ANOTHER", &get_logfile);
$answer = "This is another included makefile\n";
&compare_output($answer, &get_logfile(1));
$makefile = undef;
# Try to build the "error" target; this will fail since we don't know # Try to build the "error" target; this will fail since we don't know
# how to create makeit.mk, but we should also get a message (even though # how to create makeit.mk, but we should also get a message (even though
@ -443,6 +423,31 @@ hello.mk: ; echo 'FOO=bar' > $@
!, !,
'', 'FOO='); '', 'FOO=');
# SV 56301 Verify pattern rules creating optional includes.
# -k shouldn't matter when creating include files.
run_make_test(q!
all:; @echo hello
-include inc_a.mk
include inc_b.mk
%_a.mk %_b.mk:; exit 1
!,
'', "exit 1\n#MAKEFILE#:4: Failed to remake makefile 'inc_b.mk'.\n", 512);
run_make_test(undef, '-k', "exit 1\n#MAKEFILE#:4: Failed to remake makefile 'inc_b.mk'.\n", 512);
# It seems wrong to me that this gives a different error message, but at
# least it doesn't keep going.
run_make_test(q!
all:; @echo hello
include inc_a.mk
-include inc_b.mk
%_a.mk %_b.mk:; exit 1
!,
'', "exit 1\n#MAKEFILE#:3: inc_a.mk: $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#:5: inc_a.mk] Error 1\n", 512);
run_make_test(undef, '-k', "exit 1\n#MAKEFILE#:3: inc_a.mk: $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#:5: inc_a.mk] Error 1\n#MAKEFILE#:3: Failed to remake makefile 'inc_a.mk'.\n", 512);
# Check the default makefiles... this requires us to invoke make with no # Check the default makefiles... this requires us to invoke make with no
# arguments. Also check MAKEFILES # arguments. Also check MAKEFILES

View file

@ -103,13 +103,12 @@ $make_name: Target 'all' not remade because of errors.\n";
if (defined $ERR_no_such_file) { if (defined $ERR_no_such_file) {
run_make_test('all: ; @echo hi run_make_test('all: ; @echo hi
include ifile include ifile
ifile: no-such-file; @false ifile: no-such-file; exit 1
', ',
'-k', '-k',
"#MAKEFILE#:2: ifile: $ERR_no_such_file "#MAKEFILE#:2: ifile: $ERR_no_such_file
#MAKE#: *** No rule to make target 'no-such-file', needed by 'ifile'. #MAKE#: *** No rule to make target 'no-such-file', needed by 'ifile'.
#MAKEFILE#:2: Failed to remake makefile 'ifile'. #MAKEFILE#:2: Failed to remake makefile 'ifile'.\n",
hi\n",
512); 512);
} }