make/tests/scripts/features/include
Paul Smith 87a5f98d24 [SV 102] Don't show unnecessary include file errors.
Delay the generation of error messages for included files until we
are sure that we can't rebuild that included file.
* dep.h (struct dep): Don't reuse "changed"; make a separate field
to keep "flags".  Get rid of dontcare and use the flag.
(struct goaldep): Create a new structure for goal prereqs
that tracks an errno value and the floc where the include happened.
Rework the structures to ensure they are supersets as expected.
In maintainer mode with GCC, use inline to get type checking.
* read.c (eval_makefile): Return a struct goaldep for the new
makefile.  Ensure errno is set properly to denote a failure.
(read_all_makefiles): Switch to goaldep and check errno.
(eval): Don't show included file errors; instead remember them.
* remake.c (update_goal_chain): Set global variables to the current
goaldep we're building, and the entire chain.
(show_goal_error): Check if the current failure is a consequence
of building an included makefile and if so print an error.
(complain): Call show_goal_error() on rule failure.
* job.c (child_error): Call show_goal_error() on child error.
* main.c (main): Switch from struct dep to goaldep.
* misc.c (free_dep_chain): Not used; make into a macro.
* tests/scripts/features/include: Update and include new tests.
* tests/scripts/options/dash-B, tests/scripts/options/dash-W,
tests/scripts/options/print-directory,
tests/scripts/variables/MAKE_RESTARTS: Update known-good-output.
2016-04-09 20:06:46 -04:00

244 lines
5 KiB
Perl

# -*-mode: perl; rm-trailing-spaces: nil-*-
$description = "Test various forms of the GNU make 'include' command.";
$details = "\
Test include, -include, sinclude and various regressions involving them.
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
for targets that were also -included.";
$makefile2 = &get_tmpfile;
open(MAKEFILE,"> $makefile");
# The contents of the 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
sinclude nonexistent.mk
sinclude nonexistent-2.mk
-include makeit.mk
sinclude makeit.mk
error: makeit.mk
EOF
close(MAKEFILE);
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
# how to create makeit.mk, but we should also get a message (even though
# the -include suppressed it during the makefile read phase, we should
# see one during the makefile run phase).
run_make_test
('
-include foo.mk
error: foo.mk ; @echo $@
',
'',
"#MAKE#: *** No rule to make target 'foo.mk', needed by 'error'. Stop.\n",
512
);
# Make sure that target-specific variables don't impact things. This could
# happen because a file record is created when a target-specific variable is
# set.
run_make_test
('
bar.mk: foo := baz
-include bar.mk
hello: ; @echo hello
',
'',
"hello\n"
);
# Test inheritance of dontcare flag when rebuilding makefiles.
#
run_make_test('
.PHONY: all
all: ; @:
-include foo
foo: bar; @:
', '', '');
# Make sure that we don't die when the command fails but we dontcare.
# (Savannah bug #13216).
#
run_make_test('
.PHONY: all
all:; @:
-include foo
foo: bar; @:
bar:; @exit 1
', '', '');
# Check include, sinclude, -include with no filenames.
# (Savannah bug #1761).
run_make_test('
.PHONY: all
all:; @:
include
-include
sinclude', '', '');
# Test that the diagnostics is issued even if the target has been
# tried before with the dontcare flag (direct dependency case).
#
run_make_test('
-include foo
all: bar
foo: baz
bar: baz
',
'',
"#MAKE#: *** No rule to make target 'baz', needed by 'bar'. Stop.\n",
512);
# Test that the diagnostics is issued even if the target has been
# tried before with the dontcare flag (indirect dependency case).
#
run_make_test('
-include foo
all: bar
foo: baz
bar: baz
baz: end
',
'',
"#MAKE#: *** No rule to make target 'end', needed by 'baz'. Stop.\n",
512);
# Test that the diagnostics is issued even if the target has been
# tried before with the dontcare flag (include/-include case).
#
run_make_test('
include bar
-include foo
all:
foo: baz
bar: baz
baz: end
',
'',
"#MAKEFILE#:2: bar: No such file or directory
#MAKE#: *** No rule to make target 'end', needed by 'baz'. Stop.\n",
512);
# Test include of make-able file doesn't show an error (Savannah #102)
run_make_test(q!
.PHONY: default
default:; @echo DONE
inc1:; echo > $@
include inc1
include inc2
inc2:; echo > $@
!,
'', "echo > inc2\necho > inc1\nDONE\n");
rmfiles('inc1', 'inc2');
# Test include of non-make-able file does show an error (Savannah #102)
run_make_test(q!
.PHONY: default
default:; @echo DONE
inc1:; echo > $@
include inc1
include inc2
!,
'', "#MAKEFILE#:7: inc2: No such file or directory\n#MAKE#: *** No rule to make target 'inc2'. Stop.\n", 512);
rmfiles('inc1');
# Include same file multiple times
run_make_test(q!
default:; @echo DEFAULT
include inc1
inc1:; echo > $@
include inc1
!,
'', "echo > inc1\nDEFAULT\n");
rmfiles('inc1');
# Included file has a prerequisite that fails to build
run_make_test(q!
default:; @echo DEFAULT
include inc1
inc1: foo; echo > $@
foo:; exit 1
!,
'', "exit 1\n#MAKEFILE#:3: inc1: No such file or directory\n#MAKE#: *** [#MAKEFILE#:5: foo] Error 1\n", 512);
rmfiles('inc1');
# Included file has a prerequisite we don't know how to build
run_make_test(q!
default:; @echo DEFAULT
include inc1
inc1: foo; echo > $@
!,
'', "#MAKEFILE#:3: inc1: No such file or directory\n#MAKE#: *** No rule to make target 'foo', needed by 'inc1'. Stop.\n", 512);
rmfiles('inc1');
# include a directory
if ($all_tests) {
# Test that include of a rebuild-able file doesn't show a warning
# Savannah bug #102
run_make_test(q!
include foo
foo: ; @echo foo = bar > $@
!,
'', "#MAKE#: 'foo' is up to date.\n");
rmfiles('foo');
}
1;