Fix -W foo yielding infinite recursion in some cases of re-exec.
authorPaul Smith <psmith@gnu.org>
Sat, 25 Jun 2005 20:00:24 +0000 (20:00 +0000)
committerPaul Smith <psmith@gnu.org>
Sat, 25 Jun 2005 20:00:24 +0000 (20:00 +0000)
Added a -W test suite.

ChangeLog
main.c
tests/ChangeLog
tests/scripts/options/dash-W [new file with mode: 0644]

index 648e502de002d986b597a9ddacf0ec1408684304..8e53a647119a43a96bd340c251517e6e7fa2599e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
        (main): When checking makefiles, only set always_make_flag if
        always_make_set is set AND the restarts flag is 0.  When building
        normal targets, set it IFF always_make_set is set.
+       (main): Avoid infinite recursion with -W, too: only set what-if
+       files to NEW before we check makefiles if we've never restarted
+       before.  If we have restarted, set what-if files to NEW _after_ we
+       check makefiles.
 
 2005-06-17  Paul D. Smith  <psmith@gnu.org>
 
diff --git a/main.c b/main.c
index 0be958d564cebb84ff234b3f6c3bc01de7dd9a77..cd58a49353805dbcd0c73c80739b5eb386061720 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1772,9 +1772,9 @@ main (int argc, char **argv, char **envp)
 
   build_vpath_lists ();
 
-  /* Mark files given with -o flags as very old
-     and as having been updated already, and files given with -W flags as
-     brand new (time-stamp as far as possible into the future).  */
+  /* Mark files given with -o flags as very old and as having been updated
+     already, and files given with -W flags as brand new (time-stamp as far
+     as possible into the future).  If restarts is set we'll do -W later.  */
 
   if (old_files != 0)
     for (p = old_files->list; *p != 0; ++p)
@@ -1786,7 +1786,7 @@ main (int argc, char **argv, char **envp)
        f->command_state = cs_finished;
       }
 
-  if (new_files != 0)
+  if (!restarts && new_files != 0)
     {
       for (p = new_files->list; *p != 0; ++p)
        {
@@ -2117,6 +2117,16 @@ main (int argc, char **argv, char **envp)
   /* Set always_make_flag if -B was given.  */
   always_make_flag = always_make_set;
 
+  /* If restarts is set we haven't set up -W files yet, so do that now.  */
+  if (restarts && new_files != 0)
+    {
+      for (p = new_files->list; *p != 0; ++p)
+       {
+         f = enter_command_line_file (*p);
+         f->last_mtime = f->mtime_before_update = NEW_MTIME;
+       }
+    }
+
   /* If there is a temp file from reading a makefile from stdin, get rid of
      it now.  */
   if (stdin_nm && unlink (stdin_nm) < 0 && errno != ENOENT)
index 90fbf7d9c58e7df82369c7a473710fc37f9976da..be5169b433667ec4dc273816db4a278c84142e7d 100644 (file)
@@ -4,6 +4,8 @@
        MAKE_RESTARTS variable.
        * scripts/options/dash-B: Test re-exec doesn't loop infinitely.
        Tests fix for Savannah bug #7566.
+       * scripts/options/dash-W: New file: test the -W flag, including
+       re-exec infinite looping.
 
 2005-06-12  Paul D. Smith  <psmith@gnu.org>
 
diff --git a/tests/scripts/options/dash-W b/tests/scripts/options/dash-W
new file mode 100644 (file)
index 0000000..9a12d9a
--- /dev/null
@@ -0,0 +1,57 @@
+#                                                                    -*-perl-*-
+
+$description = "Test make -W (what if) option.\n";
+
+# Basic build
+
+run_make_test('
+a.x: b.x
+a.x b.x: ; touch $@
+',
+              '', "touch b.x\ntouch a.x");
+
+# Run it again: nothing should happen
+
+run_make_test(undef, '', "#MAKE#: `a.x' is up to date.");
+
+# Now run it with -W b.x: should rebuild a.x
+
+run_make_test(undef, '-W b.x', 'touch a.x');
+
+# Put the timestamp for a.x into the future; it should still be remade.
+
+utouch(1000, 'a.x');
+run_make_test(undef, '', "#MAKE#: `a.x' is up to date.");
+run_make_test(undef, '-W b.x', 'touch a.x');
+
+# Clean up
+
+rmfiles('a.x', 'b.x');
+
+# Test -W with the re-exec feature: we don't want to re-exec forever
+# Savannah bug # 7566
+
+# First set it up with a normal build
+
+run_make_test('
+all: baz.x ; @:
+include foo.x
+foo.x: bar.x
+       @echo "\$$(info restarts=\$$(MAKE_RESTARTS))" > $@
+       @echo "touch $@"
+bar.x: ; touch $@
+baz.x: bar.x ; @echo "touch $@"
+',
+              '', '#MAKEFILE#:3: foo.x: No such file or directory
+touch bar.x
+touch foo.x
+restarts=1
+touch baz.x');
+
+# Now run with -W bar.x
+
+run_make_test(undef, '-W bar.x', "restarts=\ntouch foo.x\nrestarts=1\ntouch baz.x");
+
+rmfiles('foo.x', 'bar.x');
+
+1;