2013-09-21 Paul Smith <psmith@gnu.org>
+ Output generated while reading makefiles should be synced.
+
+ * main.c (make_sync): Define a context for syncing while reading
+ makefiles and other top-level operations.
+ (main): If we request syncing, enable it while we are parsing
+ options, reading makefiles, etc. to capture that output. Just
+ before we start to run rules, dump the output if any.
+ (die): Dump any output we've been syncing before we die
+ * output.h (OUTPUT_SET): Disable output_context if not syncout.
+
Stderr generated from shell functions in recipes should be synced.
* job.h (FD_STDIN, FD_STDOUT, FD_STDERR): Create new macros to
#endif
unsigned short stopchar_map[UCHAR_MAX + 1] = {0};
+/* If output-sync is enabled we'll collect all the output generated due to
+ options, while reading makefiles, etc. */
+
+struct output make_sync;
+
\f
/* Mask of signals that are being caught with fatal_error_signal. */
struct dep *read_files;
PATH_VAR (current_directory);
unsigned int restarts = 0;
+ unsigned int syncing = 0;
#ifdef WINDOWS32
char *unix_path = NULL;
char *windows32_path = NULL;
no_default_sh_exe = 1;
#endif
+ output_init (&make_sync);
+
initialize_stopchar_map();
#ifdef SET_STACK_SIZE
decode_env_switches (STRING_SIZE_TUPLE ("GNUMAKEFLAGS"));
decode_env_switches (STRING_SIZE_TUPLE ("MAKEFLAGS"));
+ /* In output sync mode we need to sync any output generated by reading the
+ makefiles, such as in $(info ...) or stderr from $(shell ...) etc. */
+
+ syncing = make_sync.syncout = (output_sync == OUTPUT_SYNC_LINE
+ || output_sync == OUTPUT_SYNC_TARGET);
+ OUTPUT_SET (&make_sync);
+
#if 0
/* People write things like:
MFLAGS="CC=gcc -pipe" "CFLAGS=-g"
decode_switches (argc, argv, 0);
+ /* Reset in case the switches changed our minds. */
+ syncing = (output_sync == OUTPUT_SYNC_LINE
+ || output_sync == OUTPUT_SYNC_TARGET);
+
+ if (make_sync.syncout && ! syncing)
+ output_close (&make_sync);
+
+ make_sync.syncout = syncing;
+ OUTPUT_SET (&make_sync);
+
/* Figure out the level of recursion. */
{
struct variable *v = lookup_variable (STRING_SIZE_TUPLE (MAKELEVEL_NAME));
decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS"));
#endif
+ /* Reset in case the switches changed our minds. */
+ syncing = (output_sync == OUTPUT_SYNC_LINE
+ || output_sync == OUTPUT_SYNC_TARGET);
+
+ if (make_sync.syncout && ! syncing)
+ output_close (&make_sync);
+
+ make_sync.syncout = syncing;
+ OUTPUT_SET (&make_sync);
+
/* If we've disabled builtin rules, get rid of them. */
if (no_builtin_rules_flag && ! old_builtin_rules_flag)
{
/* Initialize the remote job module. */
remote_setup ();
+ /* Dump any output we've collected. */
+
+ OUTPUT_UNSET ();
+ output_close (&make_sync);
+
if (read_files != 0)
{
/* Update any makefiles if necessary. */
clean_jobserver (status);
+ if (output_context)
+ {
+ assert (output_context == &make_sync);
+ OUTPUT_UNSET ();
+ output_close (&make_sync);
+ }
+
output_close (NULL);
/* Try to move back to the original directory. This is essential on
!,
'-w -Oline', "#MAKE#: Entering directory '#PWD#'\nfoo\n#MAKE#: Leaving directory '#PWD#'\n");
+# Ensure that output generated while parsing makefiles is synced
+# when appropriate.
+run_make_test(q!
+$(shell echo foo 1>&2)
+all: ; echo bar
+!,
+ '-s -w -Otarget', "#MAKE#: Entering directory '#PWD#'\nfoo\n#MAKE#: Leaving directory '#PWD#'\n#MAKE#: Entering directory '#PWD#'\nbar\n#MAKE#: Leaving directory '#PWD#'\n");
+
+# Test recursion
+$m1 = get_tmpfile();
+$m2 = get_tmpfile();
+
+open(M1, "> $m1");
+print M1 <<'EOF';
+$(shell echo d1 stderr 1>&2)
+$(info d1 stdout)
+all:; @:
+EOF
+close(M1);
+
+open(M2, "> $m2");
+print M2 <<'EOF';
+$(shell echo d2 stderr 1>&2)
+$(info d2 stdout)
+all:; @:
+# Force an ordering on the output
+$(shell sleep 1)
+EOF
+close(M2);
+
+run_make_test(qq!
+all: t1 t2
+t1: ; \@\$(MAKE) -f $m1
+t2: ; \@\$(MAKE) -f $m2
+!,
+ "-j -Oline", "#MAKE#[1]: Entering directory '#PWD#'\nd1 stderr\nd1 stdout\n#MAKE#[1]: Leaving directory '#PWD#'\n#MAKE#[1]: Entering directory '#PWD#'\nd2 stderr\nd2 stdout\n#MAKE#[1]: Leaving directory '#PWD#'\n");
+
+rmfiles($m1, $m2);
+
+# Ensure that output generated while parsing makefiles is synced
+# when appropriate.
+$m1 = get_tmpfile();
+
+open(M1, "> $m1");
+print M1 <<'EOF';
+$(shell echo d1 stderr 1>&2)
+$(info d1 stdout)
+$(error d1 failed)
+all:; @:
+EOF
+close(M1);
+
+run_make_test(qq!
+all: t1
+t1: ; -\@\$(MAKE) -f $m1
+!,
+ "-j -Oline", "#MAKE#[1]: Entering directory '#PWD#'\nd1 stderr\nd1 stdout\n$m1:3: *** d1 failed. Stop.\n#MAKE#[1]: Leaving directory '#PWD#'\n#MAKEFILE#:3: recipe for target 't1' failed\n#MAKE#: [t1] Error 2 (ignored)\n");
+
+rmfiles($m1);
+
# This tells the test driver that the perl test script executed properly.
1;