diff --git a/ChangeLog b/ChangeLog index 8fb2037c..861d841d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2013-09-19 Paul Smith + + * 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 * main.c (main): Set starting_directory before we write any diff --git a/main.c b/main.c index 059f5b58..1a6c193c 100644 --- 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); } diff --git a/output.c b/output.c index c445e63b..32334ebd 100644 --- a/output.c +++ b/output.c @@ -36,7 +36,7 @@ this program. If not, see . */ #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) diff --git a/output.h b/output.h index 2bb1c391..1f0e2d7c 100644 --- 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 diff --git a/tests/ChangeLog b/tests/ChangeLog index c6cebbf1..4ee7265b 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,7 @@ +2013-09-21 Paul Smith + + * scripts/options/dash-w: Add a test for -w flag. + 2013-09-15 Paul Smith * 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 index 00000000..a05bbee7 --- /dev/null +++ b/tests/scripts/options/dash-w @@ -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;