Change the arg option for -O from numeric to string.

This commit is contained in:
Paul Smith 2013-04-15 13:22:51 -04:00
parent 7f7e6f80c5
commit 2bd957a89d
8 changed files with 99 additions and 46 deletions

View File

@ -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> 2013-04-06 Paul Smith <psmith@gnu.org>
* doc/make.texi (Implicit Variables): Clarify LDFLAGS vs. LDLIBS. * doc/make.texi (Implicit Variables): Clarify LDFLAGS vs. LDLIBS.

View 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 recipe and variable definitions, so it can be a useful debugging tool
in complex environments. in complex environments.
@item -O @item -O[@var{type}]
@cindex @code{-O} @cindex @code{-O}
@itemx --output-sync @itemx --output-sync[=@var{type}]
@cindex @code{--output-sync} @cindex @code{--output-sync}
@cindex output of parallel execution @cindex output during parallel execution
@cindex parallel execution, output of @cindex parallel execution, output during
Ensure that the complete output from each recipe is printed in one Ensure that the complete output from each recipe is printed in one
uninterrupted sequence. This option is only useful when using the uninterrupted sequence. This option is only useful when using the
@code{--jobs} option to run multiple recipes simultaneously @code{--jobs} option to run multiple recipes simultaneously
(@pxref{Parallel, ,Parallel Execution}). Without this option output (@pxref{Parallel, ,Parallel Execution}) Without this option output
will be displayed as it is generated by the recipes. will be displayed as it is generated by the recipes.@refill
With no argument or the argument @samp{1}, messages from each job in With no type or the type @samp{target}, output from each individual
recursive makes are grouped together. With the argument @samp{2}, the target is grouped together. With the type @samp{make}, the output
complete output from any recursive make is grouped together. The latter from an entire recursive make is grouped together. The latter
achieves better grouping of output from related jobs, but causes longer achieves better grouping of output from related jobs, but causes
delay, since messages do not appear until the recursive make has longer delay since messages do not appear until the entire recursive
completed. Therefore @samp{-O} is more useful when watching the output make has completed (this does not increase the total build time,
while make runs, and @samp{-O2} is better suited when running a complex though). In general @samp{target} mode is useful when watching the
parallel build in the background and checking its output afterwards. 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 @item -q
@cindex @code{-q} @cindex @code{-q}

4
job.c
View File

@ -1635,8 +1635,8 @@ start_job_command (struct child *child)
/* If it still looks like we can synchronize, create a temp /* If it still looks like we can synchronize, create a temp
file to hold stdout (and one for stderr if separate). */ file to hold stdout (and one for stderr if separate). */
if (output_sync >= OUTPUT_SYNC_COARSE if (output_sync == OUTPUT_SYNC_MAKE
|| (output_sync == OUTPUT_SYNC_FINE && !(flags & COMMANDS_RECURSE))) || (output_sync == OUTPUT_SYNC_TARGET && !(flags & COMMANDS_RECURSE)))
{ {
if (!assign_child_tempfiles (child, combined_output)) if (!assign_child_tempfiles (child, combined_output))
output_sync = 0; output_sync = 0;

74
main.c
View File

@ -151,6 +151,14 @@ static int debug_flag = 0;
int db_level = 0; int db_level = 0;
#ifdef OUTPUT_SYNC
/* Synchronize output (--output-sync). */
static struct stringlist *output_sync_option;
#endif
/* Tracing (--trace). */ /* Tracing (--trace). */
int trace_flag = 0; int trace_flag = 0;
@ -228,15 +236,6 @@ static unsigned int master_job_slots = 0;
static unsigned int inf_jobs = 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. */ /* File descriptors for the jobs pipe. */
static struct stringlist *jobserver_fds = 0; 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"), Consider FILE to be very old and don't remake it.\n"),
#ifdef OUTPUT_SYNC #ifdef OUTPUT_SYNC
N_("\ 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 #endif
N_("\ N_("\
-p, --print-data-base Print make's internal database.\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" }, { 'n', flag, &just_print_flag, 1, 1, 1, 0, 0, "just-print" },
{ 'o', filename, &old_files, 0, 0, 0, 0, 0, "old-file" }, { 'o', filename, &old_files, 0, 0, 0, 0, 0, "old-file" },
#ifdef OUTPUT_SYNC #ifdef OUTPUT_SYNC
// { 'O', flag, &output_sync, 1, 1, 0, 0, 0, "output-sync" }, // two-state { 'O', string, &output_sync_option, 1, 1, 0, "target", 0, "output-sync" },
{ 'O', positive_int, &output_sync, 1, 1, 0, &default_output_sync,
&no_output_sync, "output-sync" },
#endif #endif
{ 'p', flag, &print_data_base_flag, 1, 1, 0, 0, 0, "print-data-base" }, { 'p', flag, &print_data_base_flag, 1, 1, 0, 0, 0, "print-data-base" },
{ 'q', flag, &question_flag, 1, 1, 1, 0, 0, "question" }, { 'q', flag, &question_flag, 1, 1, 1, 0, 0, "question" },
@ -521,11 +519,9 @@ int second_expansion;
int one_shell; int one_shell;
/* Either OUTPUT_SYNC_FINE or OUTPUT_SYNC_COARSE /* Either OUTPUT_SYNC_TARGET or OUTPUT_SYNC_MAKE if the "--output-sync" option
if the "--output-sync" option was given. was given. This attempts to synchronize the output of parallel jobs such
This attempts to synchronize the output of parallel that the results of each job stay together. */
jobs such that the results of each job stay together.
It works best in combination with .ONESHELL. */
int output_sync; 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 #ifdef WINDOWS32
/* /*
* HANDLE runtime exceptions by avoiding a requestor on the GUI. Capture * HANDLE runtime exceptions by avoiding a requestor on the GUI. Capture
@ -1314,8 +1331,6 @@ main (int argc, char **argv, char **envp)
} }
#endif #endif
decode_debug_flags ();
/* Set always_make_flag if -B was given and we've not restarted already. */ /* Set always_make_flag if -B was given and we've not restarted already. */
always_make_flag = always_make_set && (restarts == 0); always_make_flag = always_make_set && (restarts == 0);
@ -2465,14 +2480,17 @@ init_switches (void)
long_options[i].name = 0; long_options[i].name = 0;
} }
/* Non-option argument. It might be a variable definition. */
static void static void
handle_non_switch_argument (char *arg, int env) handle_non_switch_argument (char *arg, int env)
{ {
/* Non-option argument. It might be a variable definition. */
struct variable *v; struct variable *v;
if (arg[0] == '-' && arg[1] == '\0') if (arg[0] == '-' && arg[1] == '\0')
/* Ignore plain '-' for compatibility. */ /* Ignore plain '-' for compatibility. */
return; return;
v = try_variable_definition (0, arg, o_command, 0); v = try_variable_definition (0, arg, o_command, 0);
if (v != 0) if (v != 0)
{ {
@ -2738,12 +2756,15 @@ decode_switches (int argc, char **argv, int env)
while (optind < argc) while (optind < argc)
handle_non_switch_argument (argv[optind++], env); handle_non_switch_argument (argv[optind++], env);
if (!env && (bad || print_usage_flag)) if (!env && (bad || print_usage_flag))
{ {
print_usage (bad); print_usage (bad);
die (bad ? 2 : 0); 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). /* 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) \ if (new->arg == 0) \
++flagslen; /* Just a single flag letter. */ \ ++flagslen; /* Just a single flag letter. */ \
else \ else \
/* " -x foo", plus space to expand "foo". */ \ /* " -xfoo", plus space to expand "foo". */ \
flagslen += 1 + 1 + 1 + 1 + (3 * (LEN)); \ flagslen += 1 + 1 + 1 + (3 * (LEN)); \
if (!short_option (cs->c)) \ if (!short_option (cs->c)) \
/* This switch has no single-letter version, so we use the long. */ \ /* This switch has no single-letter version, so we use the long. */ \
flagslen += 2 + strlen (cs->long_name); \ flagslen += 2 + strlen (cs->long_name); \
@ -2997,8 +3018,9 @@ define_makeflags (int all, int makefile)
is considered the arg for the first. */ is considered the arg for the first. */
if (flags->arg[0] != '\0') if (flags->arg[0] != '\0')
{ {
/* Add its argument too. */ /* Add its argument too. Long options require '='. */
*p++ = !short_option (flags->cs->c) ? '=' : ' '; if (!short_option (flags->cs->c))
*p++ = '=';
p = quote_for_env (p, flags->arg); p = quote_for_env (p, flags->arg);
} }
++words; ++words;

13
make.1
View File

@ -220,6 +220,19 @@ on account of changes in
.IR file . .IR file .
Essentially the file is treated as very old and its rules are ignored. Essentially the file is treated as very old and its rules are ignored.
.TP 0.5i .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 \fB\-p\fR, \fB\-\-print\-data\-base\fR
Print the data base (rules and variable values) that results from Print the data base (rules and variable values) that results from
reading the makefiles; then execute as usual or as otherwise reading the makefiles; then execute as usual or as otherwise

View File

@ -525,8 +525,8 @@ int strncasecmp (const char *s1, const char *s2, int n);
# endif # endif
#endif #endif
#define OUTPUT_SYNC_FINE 1 #define OUTPUT_SYNC_TARGET 1
#define OUTPUT_SYNC_COARSE 2 #define OUTPUT_SYNC_MAKE 2
extern const gmk_floc *reading_file; extern const gmk_floc *reading_file;
extern const gmk_floc **expanding_var; extern const gmk_floc **expanding_var;

View 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> 2013-04-14 Paul Smith <psmith@gnu.org>
* scripts/features/output-sync: Rewrite to be more reliable. * scripts/features/output-sync: Rewrite to be more reliable.

View File

@ -82,7 +82,7 @@ all: make-foo make-bar
make-foo: ; \$(MAKE) -C foo make-foo: ; \$(MAKE) -C foo
make-bar: ; \$(MAKE) -C bar!, make-bar: ; \$(MAKE) -C bar!,
'-j -O2', '-j -Omake',
"#MAKEPATH# -C foo "#MAKEPATH# -C foo
#MAKEPATH# -C bar #MAKEPATH# -C bar
#MAKE#[1]: Entering directory '#PWD#/foo' #MAKE#[1]: Entering directory '#PWD#/foo'
@ -114,7 +114,7 @@ all: make-foo make-bar
make-foo: ; \$(MAKE) -C foo make-foo: ; \$(MAKE) -C foo
make-bar: ; $sleep_command 1 ; \$(MAKE) -C bar!, make-bar: ; $sleep_command 1 ; \$(MAKE) -C bar!,
'-j --output-sync', '-j --output-sync=target',
"#MAKEPATH# -C foo "#MAKEPATH# -C foo
$sleep_command 1 ; #MAKEPATH# -C bar $sleep_command 1 ; #MAKEPATH# -C bar
#MAKE#[1]: Entering directory '#PWD#/foo' #MAKE#[1]: Entering directory '#PWD#/foo'