Change the arg option for -O from numeric to string.
authorPaul Smith <psmith@gnu.org>
Mon, 15 Apr 2013 17:22:51 +0000 (13:22 -0400)
committerPaul Smith <psmith@gnu.org>
Mon, 15 Apr 2013 17:22:51 +0000 (13:22 -0400)
ChangeLog
doc/make.texi
job.c
main.c
make.1
makeint.h
tests/ChangeLog
tests/scripts/features/output-sync

index 744eb0765894009e84afdef8fd4f97e436e65247..deca62a3b6b02b9c4fc63f80f7ea4bd004efb3f7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2013-04-15  Paul Smith  <psmith@gnu.org>
+
+       * makeint.h (OUTPUT_SYNC_TARGET, OUTPUT_SYNC_MAKE): Rename.
+       * job.c (start_job_command): Use new constants.
+       * main.c: New -O argument format.
+
+       * doc/make.texi (Options Summary): Document the argument to -O.
+       * make.1: Ditto.
+
+       * main.c (define_makeflags): Don't add space between a single-char
+       option and its argument.
+
 2013-04-06  Paul Smith  <psmith@gnu.org>
 
        * doc/make.texi (Implicit Variables): Clarify LDFLAGS vs. LDLIBS.
index e0049840061734df7d0017403ecb1aa02827133b..ce8e07b15a1fe408b45d94940aa2c2aab1da8fe1 100644 (file)
@@ -8616,26 +8616,28 @@ The data base output contains file name and line number information for
 recipe and variable definitions, so it can be a useful debugging tool
 in complex environments.
 
-@item -O
+@item -O[@var{type}]
 @cindex @code{-O}
-@itemx --output-sync
+@itemx --output-sync[=@var{type}]
 @cindex @code{--output-sync}
-@cindex output of parallel execution
-@cindex parallel execution, output of
+@cindex output during parallel execution
+@cindex parallel execution, output during
 Ensure that the complete output from each recipe is printed in one
 uninterrupted sequence.  This option is only useful when using the
 @code{--jobs} option to run multiple recipes simultaneously
-(@pxref{Parallel, ,Parallel Execution}).  Without this option output
-will be displayed as it is generated by the recipes.
-
-With no argument or the argument @samp{1}, messages from each job in
-recursive makes are grouped together. With the argument @samp{2}, the
-complete output from any recursive make is grouped together. The latter
-achieves better grouping of output from related jobs, but causes longer
-delay, since messages do not appear until the recursive make has
-completed. Therefore @samp{-O} is more useful when watching the output
-while make runs, and @samp{-O2} is better suited when running a complex
-parallel build in the background and checking its output afterwards.
+(@pxref{Parallel, ,Parallel Execution})  Without this option output
+will be displayed as it is generated by the recipes.@refill
+
+With no type or the type @samp{target}, output from each individual
+target is grouped together.  With the type @samp{make}, the output
+from an entire recursive make is grouped together.  The latter
+achieves better grouping of output from related jobs, but causes
+longer delay since messages do not appear until the entire recursive
+make has completed (this does not increase the total build time,
+though).  In general @samp{target} mode is useful when watching the
+output while make runs, and @samp{make} mode is useful when running a
+complex parallel build in the background and checking its output
+afterwards.
 
 @item -q
 @cindex @code{-q}
diff --git a/job.c b/job.c
index 360729b72985acafee43c0eb65d9570493916f79..84bc39b8c5109e327c23f6a86e87d24c7149b330 100644 (file)
--- a/job.c
+++ b/job.c
@@ -1635,8 +1635,8 @@ start_job_command (struct child *child)
 
           /* If it still looks like we can synchronize, create a temp
               file to hold stdout (and one for stderr if separate). */
-          if (output_sync >= OUTPUT_SYNC_COARSE
-              || (output_sync == OUTPUT_SYNC_FINE && !(flags & COMMANDS_RECURSE)))
+          if (output_sync == OUTPUT_SYNC_MAKE
+              || (output_sync == OUTPUT_SYNC_TARGET && !(flags & COMMANDS_RECURSE)))
             {
               if (!assign_child_tempfiles (child, combined_output))
                 output_sync = 0;
diff --git a/main.c b/main.c
index d9c2dcdb19de64f66fde5e41ad846a84f3d39852..985c765f400d9d12fb032ce8512cb18d59920b60 100644 (file)
--- a/main.c
+++ b/main.c
@@ -151,6 +151,14 @@ static int debug_flag = 0;
 
 int db_level = 0;
 
+#ifdef OUTPUT_SYNC
+
+/* Synchronize output (--output-sync).  */
+
+static struct stringlist *output_sync_option;
+
+#endif
+
 /* Tracing (--trace).  */
 
 int trace_flag = 0;
@@ -228,15 +236,6 @@ static unsigned int master_job_slots = 0;
 
 static unsigned int inf_jobs = 0;
 
-#ifdef OUTPUT_SYNC
-
-/* Default value for output-sync without an argument.  */
-
-static unsigned int no_output_sync = 0;
-static unsigned int default_output_sync = OUTPUT_SYNC_FINE;
-
-#endif
-
 /* File descriptors for the jobs pipe.  */
 
 static struct stringlist *jobserver_fds = 0;
@@ -353,7 +352,8 @@ static const char *const usage[] =
                               Consider FILE to be very old and don't remake it.\n"),
 #ifdef OUTPUT_SYNC
     N_("\
-  -O [2], --output-sync[=2]   Synchronize output of parallel jobs [coarse].\n"),
+  -O[TYPE], --output-sync[=TYPE]\n\
+                              Synchronize output of parallel jobs by TYPE.\n"),
 #endif
     N_("\
   -p, --print-data-base       Print make's internal database.\n"),
@@ -421,9 +421,7 @@ static const struct command_switch switches[] =
     { 'n', flag, &just_print_flag, 1, 1, 1, 0, 0, "just-print" },
     { 'o', filename, &old_files, 0, 0, 0, 0, 0, "old-file" },
 #ifdef OUTPUT_SYNC
-    // { 'O', flag, &output_sync, 1, 1, 0, 0, 0, "output-sync" },  // two-state
-    { 'O', positive_int, &output_sync, 1, 1, 0, &default_output_sync,
-      &no_output_sync, "output-sync" },
+    { 'O', string, &output_sync_option, 1, 1, 0, "target", 0, "output-sync" },
 #endif
     { 'p', flag, &print_data_base_flag, 1, 1, 0, 0, 0, "print-data-base" },
     { 'q', flag, &question_flag, 1, 1, 1, 0, 0, "question" },
@@ -521,11 +519,9 @@ int second_expansion;
 
 int one_shell;
 
-/* Either OUTPUT_SYNC_FINE or OUTPUT_SYNC_COARSE
-   if the "--output-sync" option was given.
-   This attempts to synchronize the output of parallel
-   jobs such that the results of each job stay together.
-   It works best in combination with .ONESHELL.  */
+/* Either OUTPUT_SYNC_TARGET or OUTPUT_SYNC_MAKE if the "--output-sync" option
+   was given.  This attempts to synchronize the output of parallel jobs such
+   that the results of each job stay together.  */
 
 int output_sync;
 
@@ -689,6 +685,27 @@ decode_debug_flags (void)
     }
 }
 
+static void
+decode_output_sync_flags (void)
+{
+  const char **pp;
+
+  if (!output_sync_option)
+    return;
+
+  for (pp=output_sync_option->list; *pp; ++pp)
+    {
+      const char *p = *pp;
+
+      if (streq (p, "target"))
+        output_sync = OUTPUT_SYNC_TARGET;
+      else if (streq (p, "make"))
+        output_sync = OUTPUT_SYNC_MAKE;
+      else
+        fatal (NILF, _("unknown output-sync type '%s'"), p);
+    }
+}
+
 #ifdef WINDOWS32
 /*
  * HANDLE runtime exceptions by avoiding a requestor on the GUI. Capture
@@ -1314,8 +1331,6 @@ main (int argc, char **argv, char **envp)
   }
 #endif
 
-  decode_debug_flags ();
-
   /* Set always_make_flag if -B was given and we've not restarted already.  */
   always_make_flag = always_make_set && (restarts == 0);
 
@@ -2465,14 +2480,17 @@ init_switches (void)
   long_options[i].name = 0;
 }
 
+
+/* Non-option argument.  It might be a variable definition.  */
 static void
 handle_non_switch_argument (char *arg, int env)
 {
-  /* Non-option argument.  It might be a variable definition.  */
   struct variable *v;
+
   if (arg[0] == '-' && arg[1] == '\0')
     /* Ignore plain '-' for compatibility.  */
     return;
+
   v = try_variable_definition (0, arg, o_command, 0);
   if (v != 0)
     {
@@ -2738,12 +2756,15 @@ decode_switches (int argc, char **argv, int env)
   while (optind < argc)
     handle_non_switch_argument (argv[optind++], env);
 
-
   if (!env && (bad || print_usage_flag))
     {
       print_usage (bad);
       die (bad ? 2 : 0);
     }
+
+  /* If there are any options that need to be decoded do it now.  */
+  decode_debug_flags ();
+  decode_output_sync_flags ();
 }
 
 /* Decode switches from environment variable ENVAR (which is LEN chars long).
@@ -2876,8 +2897,8 @@ define_makeflags (int all, int makefile)
     if (new->arg == 0)                                                        \
       ++flagslen;               /* Just a single flag letter.  */             \
     else                                                                      \
-      /* " -x foo", plus space to expand "foo".  */                           \
-      flagslen += 1 + 1 + 1 + 1 + (3 * (LEN));                                \
+      /* " -xfoo", plus space to expand "foo".  */                            \
+      flagslen += 1 + 1 + 1 + (3 * (LEN));                                    \
     if (!short_option (cs->c))                                                \
       /* This switch has no single-letter version, so we use the long.  */    \
       flagslen += 2 + strlen (cs->long_name);                                 \
@@ -2997,8 +3018,9 @@ define_makeflags (int all, int makefile)
              is considered the arg for the first.  */
           if (flags->arg[0] != '\0')
             {
-              /* Add its argument too.  */
-              *p++ = !short_option (flags->cs->c) ? '=' : ' ';
+              /* Add its argument too.  Long options require '='.  */
+              if (!short_option (flags->cs->c))
+                *p++ = '=';
               p = quote_for_env (p, flags->arg);
             }
           ++words;
diff --git a/make.1 b/make.1
index e25ee8cd2296efd4a9c6e2a81f5f4608a1a98752..6eeaaf841038bd9944d3fc8d482b9d468bbce70a 100644 (file)
--- a/make.1
+++ b/make.1
@@ -220,6 +220,19 @@ on account of changes in
 .IR file .
 Essentially the file is treated as very old and its rules are ignored.
 .TP 0.5i
+\fB\-O\fR[\fItype\fR], \fB\-\-output\-sync\fR[=\fItype\fR]
+When running multiple jobs in parallel with \fB-j\fR, ensure the output of
+each job is collected together rather than interspersed with output from
+other jobs.  If
+.I type
+is not specified or is
+.B target
+output is grouped together on a per-target basis.  If
+.I type
+is
+.B make
+output from an entire recursive make is grouped together.
+.TP 0.5i
 \fB\-p\fR, \fB\-\-print\-data\-base\fR
 Print the data base (rules and variable values) that results from
 reading the makefiles; then execute as usual or as otherwise
index 1310d8fd0736a94bc7293aaf5ad8b722c87aac0e..fe4326035ca61d058cc98bc9d04e45c34ce9a59a 100644 (file)
--- a/makeint.h
+++ b/makeint.h
@@ -525,8 +525,8 @@ int strncasecmp (const char *s1, const char *s2, int n);
 # endif
 #endif
 
-#define OUTPUT_SYNC_FINE 1
-#define OUTPUT_SYNC_COARSE 2
+#define OUTPUT_SYNC_TARGET 1
+#define OUTPUT_SYNC_MAKE 2
 
 extern const gmk_floc *reading_file;
 extern const gmk_floc **expanding_var;
index 31f1dee4a9b001e58d9613115c8bd7f5b5c33f30..0502abab81a65243677cc3ea6affa1b03f4de29c 100644 (file)
@@ -1,3 +1,7 @@
+2013-04-15  Paul Smith  <psmith@gnu.org>
+
+       * scripts/features/output-sync (output_sync_set): New arg syntax.
+
 2013-04-14  Paul Smith  <psmith@gnu.org>
 
        * scripts/features/output-sync: Rewrite to be more reliable.
index 100646cb441667f9994da2ecad075c12dd96593b..dce2ac4393a552ffadb9cc9eb59ae2f985806168 100644 (file)
@@ -82,7 +82,7 @@ all: make-foo make-bar
 make-foo: ; \$(MAKE) -C foo
 
 make-bar: ; \$(MAKE) -C bar!,
-              '-j -O2',
+              '-j -Omake',
 "#MAKEPATH# -C foo
 #MAKEPATH# -C bar
 #MAKE#[1]: Entering directory '#PWD#/foo'
@@ -114,7 +114,7 @@ all: make-foo make-bar
 make-foo: ; \$(MAKE) -C foo
 
 make-bar: ; $sleep_command 1 ; \$(MAKE) -C bar!,
-              '-j --output-sync',
+              '-j --output-sync=target',
 "#MAKEPATH# -C foo
 $sleep_command 1 ; #MAKEPATH# -C bar
 #MAKE#[1]: Entering directory '#PWD#/foo'