Don't write "Entering" every time we re-exec for remake makefiles.
authorPaul Smith <psmith@gnu.org>
Thu, 19 Sep 2013 05:15:22 +0000 (01:15 -0400)
committerPaul Smith <psmith@gnu.org>
Sat, 21 Sep 2013 18:24:44 +0000 (14:24 -0400)
ChangeLog
main.c
output.c
output.h
tests/ChangeLog
tests/scripts/options/dash-w [new file with mode: 0644]

index 8fb2037c8e3ea7e2606d3d91d3cf2387e0d55cfd..861d841d1b688c1f1f4e8f280751b3368333292c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2013-09-19  Paul Smith  <psmith@gnu.org>
+
+       * main.c (main): Set MAKE_RESTARTS to negative before re-exec if
+       we've already generated an "Entering" message.  If we are started
+       and notice that MAKE_RESTARTS is negative, assume we already wrote
+       "Entering" and don't write it again.
+
 2013-09-18  Paul Smith  <psmith@gnu.org>
 
        * main.c (main): Set starting_directory before we write any
diff --git a/main.c b/main.c
index 059f5b588337ebb40b6fa1a2ab67a469a5f19107..1a6c193cecd99be7b7f6ee2830d3d869c2e9763a 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1332,11 +1332,17 @@ main (int argc, char **argv, char **envp)
                 shell_var.value = xstrdup (ep + 1);
               }
 
-            /* If MAKE_RESTARTS is set, remember it but don't export it.  */
-            if (streq (v->name, "MAKE_RESTARTS"))
+            /* If MAKE_RESTARTS is set, remember it but don't export it.
+               If it's negative, it means the "enter" message was printed.  */
+            else if (streq (v->name, "MAKE_RESTARTS"))
               {
                 v->export = v_noexport;
-                restarts = (unsigned int) atoi (ep + 1);
+                if (*(++ep) == '-')
+                  {
+                    OUTPUT_TRACED ();
+                    ++ep;
+                  }
+                restarts = (unsigned int) atoi (ep);
               }
           }
       }
@@ -2309,7 +2315,8 @@ main (int argc, char **argv, char **envp)
                 else if (strneq (*p, "MAKE_RESTARTS=", CSTRLEN ("MAKE_RESTARTS=")))
                   {
                     *p = alloca (40);
-                    sprintf (*p, "MAKE_RESTARTS=%u", restarts);
+                    sprintf (*p, "MAKE_RESTARTS=%s%u",
+                             OUTPUT_IS_TRACED () ? "-" : "", restarts);
                     restarts = 0;
                   }
               }
@@ -2321,7 +2328,7 @@ main (int argc, char **argv, char **envp)
             sprintf (buffer, "%u", makelevel);
             SetVar (MAKELEVEL_NAME, buffer, -1, GVF_GLOBAL_ONLY);
 
-            sprintf (buffer, "%u", restarts);
+            sprintf (buffer, "%s%u", OUTPUT_IS_TRACED () ? "-" : "", restarts);
             SetVar ("MAKE_RESTARTS", buffer, -1, GVF_GLOBAL_ONLY);
             restarts = 0;
           }
@@ -2331,7 +2338,8 @@ main (int argc, char **argv, char **envp)
           if (restarts)
             {
               char *b = alloca (40);
-              sprintf (b, "MAKE_RESTARTS=%u", restarts);
+              sprintf (b, "MAKE_RESTARTS=%s%u",
+                       OUTPUT_IS_TRACED () ? "-" : "", restarts);
               putenv (b);
             }
 
index c445e63b74e67ee433fb189cd63e443ab5803801..32334ebd722e21b6e4eb0ea690c09e1f9ed98f42 100644 (file)
--- a/output.c
+++ b/output.c
@@ -36,7 +36,7 @@ this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #endif /* WINDOWS32 */
 
 struct output *output_context = NULL;
-static unsigned int stdio_traced = 0;
+unsigned int stdio_traced = 0;
 
 #define OUTPUT_NONE (-1)
 
@@ -374,15 +374,14 @@ output_dump (struct output *out)
       int traced = 0;
 
       /* Try to acquire the semaphore.  If it fails, dump the output
-         unsynchronized; still better than silently discarding it.  */
+         unsynchronized; still better than silently discarding it.
+         We want to keep this lock for as little time as possible.  */
       void *sem = acquire_semaphore ();
 
       /* Log the working directory for this dump.  */
       if (print_directory_flag && output_sync != OUTPUT_SYNC_RECURSE)
         traced = log_working_directory (output_context, 1);
 
-      /* We've entered the "critical section" during which a lock is held.  We
-         want to keep it as short as possible.  */
       if (outfd_not_empty)
         pump_from_tmp (out->out, stdout);
       if (errfd_not_empty && out->err != out->out)
index 2bb1c39139967c18aa05d7985ad81c21eb76f43c..1f0e2d7cf8725b1bed57cd2d6b98ea2156bfa6c9 100644 (file)
--- a/output.h
+++ b/output.h
@@ -22,10 +22,14 @@ struct output
  };
 
 extern struct output *output_context;
+extern unsigned int stdio_traced;
 
 #define OUTPUT_SET(_new)    do{ if ((_new)->syncout) output_context = (_new); }while(0)
 #define OUTPUT_UNSET()      do{ output_context = NULL; }while(0)
 
+#define OUTPUT_TRACED()     do{ stdio_traced = 1; }while(0)
+#define OUTPUT_IS_TRACED()  (!!stdio_traced)
+
 FILE *output_tmpfile (char **, const char *);
 
 /* Initialize and close a child output structure: if NULL do this program's
index c6cebbf15b6260ea8dee0b321adf9bf57c86d13c..4ee7265be4ef6ed661a664be993766396e93cb0c 100644 (file)
@@ -1,3 +1,7 @@
+2013-09-21  Paul Smith  <psmith@gnu.org>
+
+       * scripts/options/dash-w: Add a test for -w flag.
+
 2013-09-15  Paul Smith  <psmith@gnu.org>
 
        * scripts/misc/fopen-fail: Check for failure on infinite recursion.
diff --git a/tests/scripts/options/dash-w b/tests/scripts/options/dash-w
new file mode 100644 (file)
index 0000000..a05bbee
--- /dev/null
@@ -0,0 +1,33 @@
+#                                                                    -*-perl-*-
+
+$description = "Test the -w option to GNU make.";
+
+# Simple test without -w
+run_make_test(q!
+all: ; @echo hi
+!,
+        "", "hi\n");
+
+# Simple test with -w
+run_make_test(undef, "-w",
+              "#MAKE#: Entering directory '#PWD#'\nhi\n#MAKE#: Leaving directory '#PWD#'\n");
+
+# Test makefile rebuild to ensure no enter/leave
+run_make_test(q!
+include foo
+all: ;@:
+foo: ; touch foo
+!,
+        "", "#MAKEFILE#:2: foo: No such file or directory\ntouch foo\n");
+unlink('foo');
+
+# Test makefile rebuild with -w
+run_make_test(q!
+include foo
+all: ;@:
+foo: ; touch foo
+!,
+        "-w", "#MAKE#: Entering directory '#PWD#'\n#MAKEFILE#:2: foo: No such file or directory\ntouch foo\n#MAKE#: Leaving directory '#PWD#'\n");
+unlink('foo');
+
+1;