]> git.ipfire.org Git - thirdparty/make.git/commitdiff
Obey order of multiple print/no-print directory options
authorPaul Smith <psmith@gnu.org>
Mon, 30 Mar 2020 18:07:10 +0000 (14:07 -0400)
committerPaul Smith <psmith@gnu.org>
Tue, 31 Mar 2020 04:17:49 +0000 (00:17 -0400)
Previously if --no-print-directory was seen anywhere even once
(environment, command line, etc.) it would always take precedence
over any --print-directory option.  Change this so that the last
seen option (which will be the command line, if present there) takes
precedence.

* NEWS: Mark this change in behavior.
* src/makeint.h (print_directory): A new variable to control printing.
* src/output.c (output_dump): Use the new variable.
(output_start): Ditto.
* src/main.c: Add a new variable print_directory.  Use -1 for
print_directory_flag so we know of the option was seen or not.  Add a
new default_print_directory_flag set to -1 to keep options from being
added.
(switches): Use flag_off for --no-print-directory, rather than a
separate inhibit_print_directory_flag.
(main): If print_directory_flag was set by the user, use that for
print_directory.  If not, compute the print_directory value based on
-s, -C, and sub-makes as before.
* tests/scripts/variables/GNUMAKEFLAGS: -w is not added automatically
* tests/scripts/options/print-directory: Add tests for overriding
print-directory options.

NEWS
src/main.c
src/makeint.h
src/output.c
tests/scripts/options/print-directory
tests/scripts/variables/GNUMAKEFLAGS

diff --git a/NEWS b/NEWS
index c3c1025483676739ebec604310c7c1d39ea325c1..9b70cc59f94449d2dcadac8e13780cfb58830856 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,12 @@ A complete list of bugs fixed in this version is available here:
 
 https://sv.gnu.org/bugs/index.php?group=make&report_id=111&fix_release_id=109&set=custom
 
+* WARNING: Backward-incompatibility!
+  Previously if --no-print-directory was seen anywhere in the environment or
+  command line it would take precedence over --print-directory.  Now, the
+  last setting of directory printing options seen will be used, so a command
+  line such as "--no-print-directory -w" _will_ show directory entry/exits.
+
 * GNU Make can now be built for MS-Windows using the Tiny C tcc compiler.
 
 \f
index 78a27d7130e1609d57418f84d6a068c5ab02b0f0..2696f4fb32c5f05b4e11abee21d146eaa138471d 100644 (file)
@@ -227,12 +227,9 @@ int check_symlink_flag = 0;
 
 /* Nonzero means print directory before starting and when done (-w).  */
 
-int print_directory_flag = 0;
-
-/* Nonzero means ignore print_directory_flag and never print the directory.
-   This is necessary because print_directory_flag is set implicitly.  */
-
-int inhibit_print_directory_flag = 0;
+int print_directory;
+static int print_directory_flag = -1;
+static const int default_print_directory_flag = -1;
 
 /* Nonzero means print version information.  */
 
@@ -438,7 +435,8 @@ static const struct command_switch switches[] =
       "no-keep-going" },
     { 't', flag, &touch_flag, 1, 1, 1, 0, 0, "touch" },
     { 'v', flag, &print_version_flag, 1, 1, 0, 0, 0, "version" },
-    { 'w', flag, &print_directory_flag, 1, 1, 0, 0, 0, "print-directory" },
+    { 'w', flag, &print_directory_flag, 1, 1, 0, 0,
+      &default_print_directory_flag, "print-directory" },
 
     /* These options take arguments.  */
     { 'C', filename, &directories, 0, 0, 0, 0, 0, "directory" },
@@ -457,12 +455,13 @@ static const struct command_switch switches[] =
     { CHAR_MAX+1, strlist, &db_flags, 1, 1, 0, "basic", 0, "debug" },
     { CHAR_MAX+2, string, &jobserver_auth, 1, 1, 0, 0, 0, "jobserver-auth" },
     { CHAR_MAX+3, flag, &trace_flag, 1, 1, 0, 0, 0, "trace" },
-    { CHAR_MAX+4, flag, &inhibit_print_directory_flag, 1, 1, 0, 0, 0,
-      "no-print-directory" },
+    { CHAR_MAX+4, flag_off, &print_directory_flag, 1, 1, 0, 0,
+      &default_print_directory_flag, "no-print-directory" },
     { CHAR_MAX+5, flag, &warn_undefined_variables_flag, 1, 1, 0, 0, 0,
       "warn-undefined-variables" },
     { CHAR_MAX+7, string, &sync_mutex, 1, 1, 0, 0, 0, "sync-mutex" },
-    { CHAR_MAX+8, flag_off, &silent_flag, 1, 1, 0, 0, &default_silent_flag, "no-silent" },
+    { CHAR_MAX+8, flag_off, &silent_flag, 1, 1, 0, 0, &default_silent_flag,
+      "no-silent" },
     { CHAR_MAX+9, string, &jobserver_auth, 1, 0, 0, 0, 0, "jobserver-fds" },
     { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
   };
@@ -1722,13 +1721,13 @@ main (int argc, char **argv, char **envp)
    no_default_sh_exe = !find_and_set_default_shell (NULL);
 #endif /* WINDOWS32 */
 
-  /* Except under -s, always do -w in sub-makes and under -C.  */
-  if (!silent_flag && (directories != 0 || makelevel > 0))
-    print_directory_flag = 1;
+  /* If the user didn't specify any print-directory options, compute the
+     default setting: disable under -s / print in sub-makes and under -C.  */
 
-  /* Let the user disable that with --no-print-directory.  */
-  if (inhibit_print_directory_flag)
-    print_directory_flag = 0;
+  if (print_directory_flag == -1)
+    print_directory = !silent_flag && (directories != 0 || makelevel > 0);
+  else
+    print_directory = print_directory_flag;
 
   /* If -R was given, set -r too (doesn't make sense otherwise!)  */
   if (no_builtin_variables_flag)
index c428a362a4cc59c7960bc10f19e217bc05bdce4e..de9b3dda1639974e9dbcdc3b0381ebc4a33b2913 100644 (file)
@@ -670,7 +670,7 @@ extern unsigned short stopchar_map[];
 extern int just_print_flag, run_silent, ignore_errors_flag, keep_going_flag;
 extern int print_data_base_flag, question_flag, touch_flag, always_make_flag;
 extern int env_overrides, no_builtin_rules_flag, no_builtin_variables_flag;
-extern int print_version_flag, print_directory_flag, check_symlink_flag;
+extern int print_version_flag, print_directory, check_symlink_flag;
 extern int warn_undefined_variables_flag, trace_flag, posix_pedantic;
 extern int not_parallel, second_expansion, clock_skew_detected;
 extern int rebuilding_makefiles, one_shell, output_sync, verify_flag;
index 221174963d72a0c0473d54ade29c020d0e27b936..4845f2027673e98dca22d7c0878ebc1544019476 100644 (file)
@@ -367,7 +367,7 @@ output_dump (struct output *out)
       void *sem = acquire_semaphore ();
 
       /* Log the working directory for this dump.  */
-      if (print_directory_flag && output_sync != OUTPUT_SYNC_RECURSE)
+      if (print_directory && output_sync != OUTPUT_SYNC_RECURSE)
         traced = log_working_directory (1);
 
       if (outfd_not_empty)
@@ -517,7 +517,7 @@ output_start (void)
   /* If we're not syncing this output per-line or per-target, make sure we emit
      the "Entering..." message where appropriate.  */
   if (output_sync == OUTPUT_SYNC_NONE || output_sync == OUTPUT_SYNC_RECURSE)
-    if (! stdio_traced && print_directory_flag)
+    if (! stdio_traced && print_directory)
       stdio_traced = log_working_directory (1);
 }
 
index db762b2c76a8ae25b23411bf3273655ddf03a881..7ba9a2e7493e9d95c94d36f0d5b2573bbe6425d5 100644 (file)
@@ -2,15 +2,25 @@
 
 $description = "Test the -w option to GNU make.";
 
+my $enter = "#MAKE#: Entering directory '#PWD#'";
+my $leave = "#MAKE#: Leaving directory '#PWD#'";
+
 # Simple test without -w
 run_make_test(q!
 all: ; @echo hi
 !,
         "", "hi\n");
 
+my $ans = "$enter\nhi\n$leave\n";
+
 # Simple test with -w
-run_make_test(undef, "-w",
-              "#MAKE#: Entering directory '#PWD#'\nhi\n#MAKE#: Leaving directory '#PWD#'\n");
+run_make_test(undef, "-w", $ans);
+
+# Simple test with overriding -w
+run_make_test(undef, "-w --no-print-directory", "hi\n");
+
+# Simple test with overriding --no-print-directory
+run_make_test(undef, "--no-print-directory --print-directory", $ans);
 
 # Test makefile rebuild to ensure no enter/leave
 run_make_test(q!
@@ -21,13 +31,40 @@ foo: ; touch foo
         "", "touch foo\n");
 unlink('foo');
 
+$ans = "$enter\ntouch foo\n$leave\n";
+
 # Test makefile rebuild with -w
+run_make_test(undef, "-w", $ans);
+unlink('foo');
+
+# Test makefile rebuild with -w overridden
+run_make_test(undef, "-w --no-print-directory", "touch foo\n");
+unlink('foo');
+
+# Test makefile rebuild with --no-print-directory overridden
+run_make_test(undef, "--no-print-directory --print-directory", $ans);
+unlink('foo');
+
+my $enter1 = "#MAKE#[1]: Entering directory '#PWD#'";
+my $leave1 = "#MAKE#[1]: Leaving directory '#PWD#'";
+
+$ans = "$enter1\nhi\n$leave1\n";
+
+# Test makefile recursion with default enter/leave
 run_make_test(q!
-include foo
-all: ;@:
-foo: ; touch foo
+all: ;@$(MAKE) -f #MAKEFILE# recurse
+recurse: ; @echo hi
 !,
-        "-w", "#MAKE#: Entering directory '#PWD#'\ntouch foo\n#MAKE#: Leaving directory '#PWD#'\n");
-unlink('foo');
+        "", $ans);
+
+# Disable enter/leave
+run_make_test(undef, "--no-print-directory", "hi\n");
+
+# Re-enable enter/leave
+$ans = "$enter\n$ans$leave\n";
+run_make_test(undef, "--no-print-directory -w", $ans);
+
+# Override enter/leave
+run_make_test(undef, "-w --no-print-directory", "hi\n");
 
 1;
index 6e507949be8275d2be84a8684ff94bde76177688..62a68bd9cfdfefd28ab19ea75ad39a82bf50900d 100644 (file)
@@ -35,7 +35,7 @@ all: ; @echo $@; echo MAKEFLAGS = $$MAKEFLAGS; echo GNUMAKEFLAGS = $$GNUMAKEFLAG
 -include x.mk
 x.mk: ; @echo $@; echo MAKEFLAGS = $$MAKEFLAGS; echo GNUMAKEFLAGS = $$GNUMAKEFLAGS; echo > $@
 !,
-              "", "x.mk\nMAKEFLAGS = -Itst/bad\nGNUMAKEFLAGS =\nrecurse\nMAKEFLAGS = -Itst/bad\nGNUMAKEFLAGS =\n#MAKE#[1]: Entering directory '#PWD#'\nall\nMAKEFLAGS = -Itst/bad\nGNUMAKEFLAGS =\n#MAKE#[1]: Leaving directory '#PWD#'\n");
+              "", "x.mk\nMAKEFLAGS = -Itst/bad\nGNUMAKEFLAGS =\nrecurse\nMAKEFLAGS = -Itst/bad\nGNUMAKEFLAGS =\n#MAKE#[1]: Entering directory '#PWD#'\nall\nMAKEFLAGS = -Itst/bad\nGNUMAKEFLAGS =\n#MAKE#[1]: Leaving directory '#PWD#'\n");
 
 unlink('x.mk');