Add new --trace[=MODE] flags, with --trace=dir

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.
This commit is contained in:
Paul Smith 2013-05-13 01:30:24 -04:00
parent 5367d393dd
commit 381baeef7a
9 changed files with 102 additions and 36 deletions

View file

@ -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

View 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}

20
job.c
View file

@ -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;

40
main.c
View file

@ -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++ = '-';

22
make.1
View file

@ -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

View file

@ -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;

8
misc.c
View file

@ -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);
}

View 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

View 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);