make/tests/scripts/options/dash-k
Paul Smith 7c4e6b0299 [SV 60595] Restart whenever any makefile is rebuilt
Previously if an included makefile was rebuilt as a prerequisite of
another included makefile which didn't need to be rebuilt, make would
not realize that it needed to re-exec itself.

Ensure that if any included makefile target is rebuilt we re-exec.
Also ensure that if an included makefile is not readable, and our rule
for rebuilding it doesn't actually change it, we will still fail.

* src/remake.c (update_goal_chain): If a goal's update was successful
then check its status, even if no actual commands were run because it
was already up to date.
(show_goal_error): Remove superfluous cast.
* src/main.c (main): If the makefile remake did nothing, check that we
were able to successfully include all the makefiles we care about; if
not fail.  When generating error messages about included makefiles be
sure to show the filename/linenumber information.
* test/scripts/features/reinvoke: Add tests for this behavior.
* test/scripts/options/dash-k: Update error messages.
2021-09-03 12:08:11 -04:00

117 lines
2.9 KiB
Perl

# -*-perl-*-
$description = "Test the make -k (don't stop on error) option.\n";
$details = "\
The makefile created in this test is a simulation of building
a small product. However, the trick to this one is that one
of the dependencies of the main target does not exist.
Without the -k option, make would fail immediately and not
build any part of the target. What we are looking for here,
is that make builds the rest of the dependencies even though
it knows that at the end it will fail to rebuild the main target.";
open(MAKEFILE,"> $makefile");
# The Contents of the MAKEFILE ...
print MAKEFILE <<EOF;
VPATH = $workdir
edit: main.o kbd.o commands.o display.o
\t\@echo cc -o edit main.o kbd.o commands.o display.o
main.o : main.c defs.h
\t\@echo cc -c main.c
kbd.o : kbd.c defs.h command.h
\t\@echo cc -c kbd.c
commands.o : command.c defs.h command.h
\t\@echo cc -c commands.c
display.o : display.c defs.h buffer.h
\t\@echo cc -c display.c
EOF
# END of Contents of MAKEFILE
close(MAKEFILE);
@files_to_touch = ("$workdir${pathsep}main.c","$workdir${pathsep}defs.h",
"$workdir${pathsep}command.h",
"$workdir${pathsep}commands.c","$workdir${pathsep}display.c",
"$workdir${pathsep}buffer.h",
"$workdir${pathsep}command.c");
&touch(@files_to_touch);
if ($vos) {
$error_code = 3307;
}
else {
$error_code = 512;
}
&run_make_with_options($makefile, "-k", &get_logfile, $error_code);
# Create the answer to what should be produced by this Makefile
$answer = "cc -c main.c
$make_name: *** No rule to make target 'kbd.c', needed by 'kbd.o'.
cc -c commands.c
cc -c display.c
$make_name: Target 'edit' not remade because of errors.\n";
# COMPARE RESULTS
&compare_output($answer, &get_logfile(1));
unlink(@files_to_touch) unless $keep;
# TEST 1: Make sure that top-level targets that depend on targets that
# previously failed to build, aren't attempted. Regression for PR/1634.
$makefile2 = &get_tmpfile;
open(MAKEFILE, "> $makefile2");
print MAKEFILE <<'EOF';
.SUFFIXES:
all: exe1 exe2; @echo making $@
exe1 exe2: lib; @echo cp $^ $@
lib: foo.o; @echo cp $^ $@
foo.o: ; exit 1
EOF
close(MAKEFILE);
&run_make_with_options($makefile2, "-k", &get_logfile, $error_code);
$answer = "exit 1
$make_name: *** [$makefile2:9: foo.o] Error 1
$make_name: Target 'all' not remade because of errors.\n";
&compare_output($answer, &get_logfile(1));
# TEST -- make sure we keep the error code if we can't create an included
# makefile.
if (defined $ERR_no_such_file) {
run_make_test('all: ; @echo hi
include ifile
ifile: no-such-file; @false
',
'-k',
"#MAKEFILE#:2: ifile: $ERR_no_such_file
#MAKE#: *** No rule to make target 'no-such-file', needed by 'ifile'.
#MAKEFILE#:2: Failed to remake makefile 'ifile'.
hi\n",
512);
}
1;