Add new --trace[=MODE] flags, with --trace=dir
authorPaul Smith <psmith@gnu.org>
Mon, 13 May 2013 05:30:24 +0000 (01:30 -0400)
committerPaul Smith <psmith@gnu.org>
Mon, 13 May 2013 05:30:24 +0000 (01:30 -0400)
This mode replaces the previous heuristic setting enabled with -O, where we
would log directory enter/leave for each synchronized output.  Now we only
do that if --trace=dir is given.

ChangeLog
doc/make.texi
job.c
main.c
make.1
makeint.h
misc.c
tests/ChangeLog
tests/scripts/features/output-sync

index 4d085763967747804587fbbda6cf494908fc6295..57803f0ec692c39088c1a5f34b9545706f3717a9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2013-05-13  Paul Smith  <psmith@gnu.org>
+
+       * makeint.h (TRACE_NONE, TRACE_RULE, TRACE_DIRECTORY): Define
+       constants for the trace mode.
+       * main.c: Add new --trace mode parsing.
+       (decode_trace_flags): New function.
+       (decode_switches): Call it.
+       (define_makeflags): Fix a bug with long-name options.
+       * misc.c (fatal): Remove special output-sync handling.
+       * make.1: Document new --trace mode flags.
+       * doc/make.texi (Options Summary): Ditto.
+
 2013-05-11  Eli Zaretskii  <eliz@gnu.org>
 
        * job.c (child_out): Output the newline following the message
index 69de5b7df9a399b4d44445539ff1a4e99572a662..8a357800afc32155e0401ace1b6e689031c07151 100644 (file)
@@ -8730,7 +8730,8 @@ With no type or the type @samp{target}, output from the entire recipe
 of each target is grouped together.  With the type @samp{line}, output
 from each line in the recipe is grouped together.  With the type
 @samp{recurse}, the output from an entire recursive make is grouped
-together.  @xref{Parallel Output, ,Output During Parallel Execution}.
+together.  With the type @samp{none}, no output synchronization is
+performed.  @xref{Parallel Output, ,Output During Parallel Execution}.
 
 @item -q
 @cindex @code{-q}
@@ -8803,13 +8804,17 @@ instead of running their recipes.  This is used to pretend that the
 recipes were done, in order to fool future invocations of
 @code{make}.  @xref{Instead of Execution, ,Instead of Executing Recipes}.
 
-@item --trace
+@item --trace[=@var{mode}]
 @cindex @code{--trace}
-@c Extra blank line here makes the table look better.
-
-Print the entire recipe to be executed, even for recipes that are
-normally silent (due to @code{.SILENT} or @samp{@@}).  Also print the
-makefile name and line number where the recipe was defined.
+Show tracing information for @code{make} execution.  With no mode or
+the type @samp{rule}, print the entire recipe to be executed, even for
+recipes that are normally silent (due to @code{.SILENT} or @samp{@@}).
+Also print the makefile name and line number where the recipe was
+defined, and information on why the target is being rebuilt.  With the
+type @samp{dir}, directory enter/leave lines are shown around each
+synchronized output segment.  These modes are cumulative and can be
+set with multiple instances of the @code{--trace} flag.  With the type
+@samp{none}, all tracing is disabled.
 
 @item -v
 @cindex @code{-v}
diff --git a/job.c b/job.c
index 106c518fb1ef66c82cc831b7ec3a3a20d2d3ad64..56055e433bbbd6c63be9cde9207f1a67b4e41f61 100644 (file)
--- a/job.c
+++ b/job.c
@@ -768,14 +768,20 @@ sync_output (struct child *c)
          unsynchronized; still better than silently discarding it.  */
       void *sem = acquire_semaphore ();
 
-      /* We've entered the "critical section" during which a lock is held.
-         We want to keep it as short as possible.  */
-      log_working_directory (1, 1);
+      /* We've entered the "critical section" during which a lock is held.  We
+         want to keep it as short as possible.  */
+
+      /* Log the working directory.  Force it if we're doing dir tracing.  */
+      log_working_directory (1, (trace_flag & TRACE_DIRECTORY));
+
       if (outfd_not_empty)
-          pump_from_tmp (c->outfd, stdout);
+        pump_from_tmp (c->outfd, stdout);
       if (errfd_not_empty && c->errfd != c->outfd)
         pump_from_tmp (c->errfd, stderr);
-      log_working_directory (0, 1);
+
+      /* If we're doing dir tracing, force the leave message.  */
+      if (trace_flag & TRACE_DIRECTORY)
+        log_working_directory (0, 1);
 
       /* Exit the critical section.  */
       if (sem)
@@ -1506,7 +1512,7 @@ start_job_command (struct child *child)
       return;
     }
 
-  print_cmd = (just_print_flag || trace_flag
+  print_cmd = (just_print_flag || (trace_flag & TRACE_RULE)
                || (!(flags & COMMANDS_SILENT) && !silent_flag));
 
 #ifdef OUTPUT_SYNC
@@ -2237,7 +2243,7 @@ new_job (struct file *file)
 
   /* Trace the build.
      Use message here so that changes to working directories are logged.  */
-  if (trace_flag)
+  if (trace_flag & TRACE_RULE)
     {
       char *newer = allocated_variable_expand_for_file ("$?", c->file);
       const char *nm;
diff --git a/main.c b/main.c
index 49f466ce5f6d70dc20e592bff839f065a16d1cb2..fe0f54ee454fb58dcd150c7b4e9d18fe0b20417f 100644 (file)
--- a/main.c
+++ b/main.c
@@ -157,7 +157,7 @@ static struct stringlist *output_sync_option = 0;
 
 /* Tracing (--trace).  */
 
-int trace_flag = 0;
+static struct stringlist *trace_option = 0;
 
 #ifdef WINDOWS32
 /* Suspend make in main for a short time to allow debugger to attach */
@@ -370,7 +370,7 @@ static const char *const usage[] =
     N_("\
   -t, --touch                 Touch targets instead of remaking them.\n"),
     N_("\
-  --trace                     Print tracing information.\n"),
+  --trace[=MODE]              Print tracing information.\n"),
     N_("\
   -v, --version               Print the version number of make and exit.\n"),
     N_("\
@@ -430,7 +430,7 @@ static const struct command_switch switches[] =
     { 'S', flag_off, &keep_going_flag, 1, 1, 0, 0, &default_keep_going_flag,
       "no-keep-going" },
     { 't', flag, &touch_flag, 1, 1, 1, 0, 0, "touch" },
-    { CHAR_MAX+3, flag, &trace_flag, 1, 1, 0, 0, 0, "trace" },
+    { CHAR_MAX+3, string, &trace_option, 1, 1, 0, "rule", 0, "trace" },
     { 'v', flag, &print_version_flag, 1, 1, 0, 0, 0, "version" },
     { 'w', flag, &print_directory_flag, 1, 1, 0, 0, 0, "print-directory" },
     { CHAR_MAX+4, flag, &inhibit_print_directory_flag, 1, 1, 0, 0, 0,
@@ -521,7 +521,12 @@ int one_shell;
    attempts to synchronize the output of parallel jobs such that the results
    of each job stay together.  */
 
-int output_sync;
+int output_sync = OUTPUT_SYNC_NONE;
+
+/* One of TRACE_* if the "--trace" option was given.  Enables various types of
+   tracing.  */
+
+int trace_flag = TRACE_NONE;
 
 /* Nonzero if we have seen the '.NOTPARALLEL' target.
    This turns off parallel builds for this invocation of make.  */
@@ -683,6 +688,29 @@ decode_debug_flags (void)
     }
 }
 
+static void
+decode_trace_flags (void)
+{
+  const char **pp;
+
+  if (!trace_option)
+    return;
+
+  for (pp=trace_option->list; *pp; ++pp)
+    {
+      const char *p = *pp;
+
+      if (streq (p, "none"))
+        trace_flag = TRACE_NONE;
+      else if (streq (p, "rule"))
+        trace_flag |= TRACE_RULE;
+      else if (streq (p, "dir"))
+        trace_flag |= TRACE_DIRECTORY;
+      else
+        fatal (NILF, _("unknown trace mode '%s'"), p);
+    }
+}
+
 static void
 decode_output_sync_flags (void)
 {
@@ -2764,6 +2792,7 @@ decode_switches (int argc, char **argv, int env)
   /* If there are any options that need to be decoded do it now.  */
   decode_debug_flags ();
   decode_output_sync_flags ();
+  decode_trace_flags ();
 }
 
 /* Decode switches from environment variable ENVAR (which is LEN chars long).
@@ -3000,7 +3029,8 @@ define_makeflags (int all, int makefile)
         *p++ = flags->cs->c;
       else
         {
-          if (*p != '-')
+          /* If we don't have a dash, start a double-dash.  */
+          if (p[-1] != '-')
             {
               *p++ = ' ';
               *p++ = '-';
diff --git a/make.1 b/make.1
index ad86db365e6db3f68b4ba7d83cc3a76e28b72110..94200326387f2063c11ac25bce08c2df8decb890 100644 (file)
--- a/make.1
+++ b/make.1
@@ -231,7 +231,7 @@ the output from the entire recipe for each target is grouped together.  If
 .I type
 is
 .B line
-the output from each line within a recipe is grouped together.
+the output from each command line within a recipe is grouped together.
 If
 .I type
 is
@@ -289,9 +289,25 @@ This is used to pretend that the commands were done, in order to fool
 future invocations of
 .BR make .
 .TP 0.5i
-.B \-\-trace
+.B \-\-trace\fR[=\fImode\fR]
 Print information about the commands invoked by
-.BR make.
+.BR make .
+If
+.I mode
+is not specified or is
+.B rule
+information about the disposition of each target is printed.  If
+.I mode
+is
+.B dir
+then directory enter/leave trace statements are shown for each synchronized
+output segment (see
+.BR \-O ).
+If
+.I mode
+is
+.B none
+then no tracing is performed.
 .TP 0.5i
 \fB\-v\fR, \fB\-\-version\fR
 Print the version of the
index 6bff07af24802db5336fe443ced70d7246e95507..ae7e81333da0f63af5d57600b3f8d7725b3adcd9 100644 (file)
--- a/makeint.h
+++ b/makeint.h
@@ -544,6 +544,10 @@ int strncasecmp (const char *s1, const char *s2, int n);
 #define OUTPUT_SYNC_TARGET  2
 #define OUTPUT_SYNC_RECURSE 3
 
+#define TRACE_NONE      0x0
+#define TRACE_RULE      0x1
+#define TRACE_DIRECTORY 0x2
+
 extern const gmk_floc *reading_file;
 extern const gmk_floc **expanding_var;
 
diff --git a/misc.c b/misc.c
index 2a6c6ea3c95c0dd684a450d419e14c0d07a0469f..301a3c22e2d138b1fa82b760fd4ccf910e78123a 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -313,10 +313,7 @@ fatal (const gmk_floc *flocp, const char *fmt, ...)
 {
   va_list args;
 
-  if (output_sync)
-    log_working_directory (1, 1);
-  else
-    log_working_directory (1, 0);
+  log_working_directory (1, 0);
 
   if (flocp && flocp->filenm)
     fprintf (stderr, "%s:%lu: *** ", flocp->filenm, flocp->lineno);
@@ -331,8 +328,7 @@ fatal (const gmk_floc *flocp, const char *fmt, ...)
 
   fputs (_(".  Stop.\n"), stderr);
 
-  if (output_sync)
-    log_working_directory (0, 1);
+  log_working_directory (0, 1);
 
   die (2);
 }
index 260093af169ee7793afbfc1ff18f9e636094df4c..34e8cc295616af00fe8456632ae1ee6fd5fafefb 100644 (file)
@@ -1,3 +1,8 @@
+2013-05-13  Paul Smith  <psmith@gnu.org>
+
+       * scripts/features/output-sync (output_sync_set): Update for new
+       --trace behavior.
+
 2013-05-05  Paul Smith  <psmith@gnu.org>
 
        * scripts/features/output-sync (output_sync_set): Remove
index d76088594b3beb07bb194ec423ed0f0d8201bc25..b4541fb1eb4558d20f946fec003f5ada191ea20c 100644 (file)
@@ -135,8 +135,6 @@ foo: end
 #MAKE#[1]: Entering directory '#PWD#/bar'
 bar: start
 bar: end
-#MAKE#[1]: Leaving directory '#PWD#/bar'
-#MAKE#[1]: Entering directory '#PWD#/bar'
 baz: start
 baz: end
 #MAKE#[1]: Leaving directory '#PWD#/bar'\n", 0, 6);
@@ -159,12 +157,10 @@ $sleep_command 1 ; #MAKEPATH# -C bar
 #MAKE#[1]: Entering directory '#PWD#/bar'
 bar: start
 bar: end
-#MAKE#[1]: Leaving directory '#PWD#/bar'
 #MAKE#[1]: Entering directory '#PWD#/foo'
 foo: start
 foo: end
 #MAKE#[1]: Leaving directory '#PWD#/foo'
-#MAKE#[1]: Entering directory '#PWD#/bar'
 baz: start
 baz: end
 #MAKE#[1]: Leaving directory '#PWD#/bar'\n", 0, 6);
@@ -213,14 +209,10 @@ make-bar: ; $sleep_command 1 ; \$(MAKE) -C bar bar-job!,
 $sleep_command 1 ; #MAKEPATH# -C bar bar-job
 #MAKE#[1]: Entering directory '#PWD#/foo'
 foo: start
-#MAKE#[1]: Leaving directory '#PWD#/foo'
 #MAKE#[1]: Entering directory '#PWD#/bar'
 bar: start
-#MAKE#[1]: Leaving directory '#PWD#/bar'
-#MAKE#[1]: Entering directory '#PWD#/bar'
 bar: end
 #MAKE#[1]: Leaving directory '#PWD#/bar'
-#MAKE#[1]: Entering directory '#PWD#/foo'
 foo: end
 #MAKE#[1]: Leaving directory '#PWD#/foo'\n", 0, 6);