From 6c3e88e60f2c7d2bff3aa1967afcc59f27626c48 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Sat, 21 Sep 2013 17:24:59 -0400 Subject: Ensure that output generated while reading makefiles is synced. --- main.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'main.c') diff --git a/main.c b/main.c index bd8b478..f0a7174 100644 --- a/main.c +++ b/main.c @@ -550,6 +550,11 @@ int clock_skew_detected; #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; + /* Mask of signals that are being caught with fatal_error_signal. */ @@ -1041,6 +1046,7 @@ main (int argc, char **argv, char **envp) 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; @@ -1052,6 +1058,8 @@ main (int argc, char **argv, char **envp) no_default_sh_exe = 1; #endif + output_init (&make_sync); + initialize_stopchar_map(); #ifdef SET_STACK_SIZE @@ -1390,6 +1398,13 @@ main (int argc, char **argv, char **envp) 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" @@ -1399,6 +1414,16 @@ main (int argc, char **argv, char **envp) 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)); @@ -1907,6 +1932,16 @@ main (int argc, char **argv, char **envp) 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) { @@ -2077,6 +2112,11 @@ main (int argc, char **argv, char **envp) /* 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. */ @@ -3358,6 +3398,13 @@ die (int status) 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 -- cgit v1.2.3