]> git.ipfire.org Git - thirdparty/make.git/commitdiff
[SV 56301] Fail if an included makefile can't be built
authorDmitry Goncharov <dgoncharov@users.sf.net>
Tue, 20 Sep 2022 07:08:29 +0000 (03:08 -0400)
committerPaul Smith <psmith@gnu.org>
Tue, 20 Sep 2022 07:55:39 +0000 (03:55 -0400)
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.

src/main.c
tests/scripts/features/include
tests/scripts/options/dash-k

index 91eae5805b727f01196712a5ec454628d24c9b7a..7392a432a86f01ffe6169512935b6cbabd04ccc8 100644 (file)
@@ -2499,6 +2499,7 @@ main (int argc, char **argv, char **envp)
                         any_remade |= (mtime != NONEXISTENT_MTIME
                                        && mtime != makefile_mtimes[i]);
                         makefile_status = MAKE_FAILURE;
+                        any_failed = 1;
                       }
                   }
 
index 14741609edb0245a857ed4d7b1ba073aea647655..69d67181ccbca23480b27283e7e1ef68631414d6 100644 (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
 for targets that were also -included.";
 
-$makefile2 = &get_tmpfile;
+create_file('incl.mk', "ANOTHER: ; \@echo This is another included makefile\n");
 
-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.
+run_make_test(qq!#Extra space at the end of the following file name
+include incl.mk    ! . q!
+all: ; @echo There should be no errors for this makefile.
 
 -include nonexistent.mk
 -include nonexistent.mk
@@ -27,27 +22,12 @@ sinclude nonexistent-2.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));
+!,
+              "all", "There should be no errors for this makefile.\n");
 
-&run_make_with_options($makefile, "ANOTHER", &get_logfile);
-$answer = "This is another included makefile\n";
-&compare_output($answer, &get_logfile(1));
+run_make_test(undef, "ANOTHER", "This is another included makefile\n");
 
-$makefile = undef;
+unlink('incl.mk');
 
 # 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
@@ -443,6 +423,31 @@ hello.mk: ; echo 'FOO=bar' > $@
 !,
               '', '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
 # arguments.  Also check MAKEFILES
 
index 323dff60c021d4211ab96b9966d6d2ed5de723b6..4bd68f032dd9ac7a9644b4b67b22bc35f01b23c7 100644 (file)
@@ -103,13 +103,12 @@ $make_name: Target 'all' not remade because of errors.\n";
 if (defined $ERR_no_such_file) {
     run_make_test('all: ; @echo hi
 include ifile
-ifile: no-such-file; @false
+ifile: no-such-file; exit 1
 ',
                   '-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",
+#MAKEFILE#:2: Failed to remake makefile 'ifile'.\n",
                   512);
 }