]> git.ipfire.org Git - thirdparty/make.git/commitdiff
[SV 54740] Ensure .SILENT settings do not leak into sub-makes
authorPaul Smith <psmith@gnu.org>
Sun, 12 May 2019 21:01:55 +0000 (17:01 -0400)
committerPaul Smith <psmith@gnu.org>
Sun, 19 May 2019 19:27:26 +0000 (15:27 -0400)
Create a new variable run_silent to hold the current instance's global
silence setting, allowing silent_flag to represent only whether the -s
option was provided on the command line.

* src/makeint.h: Change silent_flag variable to run_silent.
* src/job.c: Ditto.
* src/remake.c: Ditto.
* src/file.c: Ditto.
* src/main.c: Add a new global variable run_silent.
(decode_switches): After switches are decoded, initialize run_silent.
* tests/scripts/targets/SILENT: Add a test for recursive behavior.

src/file.c
src/job.c
src/main.c
src/makeint.h
src/remake.c
tests/scripts/targets/SILENT

index 73511d8a03693a612d46eb5d21a1efc06a6fdd2b..c20fcf8b0c5ac2dbdaba9591a10e01905f4a3299 100644 (file)
@@ -410,7 +410,7 @@ remove_intermediates (int sig)
                   {
                     if (! doneany)
                       DB (DB_BASIC, (_("Removing intermediate files...\n")));
-                    if (!silent_flag)
+                    if (!run_silent)
                       {
                         if (! doneany)
                           {
@@ -768,7 +768,7 @@ snap_deps (void)
   if (f != 0 && f->is_target)
     {
       if (f->deps == 0)
-        silent_flag = 1;
+        run_silent = 1;
       else
         for (d = f->deps; d != 0; d = d->next)
           for (f2 = d->file; f2 != 0; f2 = f2->prev)
index dbf85851e35197e3446657b1bc9b05d6b2bf946b..54dd284fbb18d45b000349dd930ffd8c713a1e84 100644 (file)
--- a/src/job.c
+++ b/src/job.c
@@ -541,7 +541,7 @@ child_error (struct child *child,
   const char *nm;
   size_t l;
 
-  if (ignored && silent_flag)
+  if (ignored && run_silent)
     return;
 
   if (exit_sig && coredump)
@@ -1312,7 +1312,7 @@ start_job_command (struct child *child)
 
   /* Print the command if appropriate.  */
   if (just_print_flag || trace_flag
-      || (!(flags & COMMANDS_SILENT) && !silent_flag))
+      || (!(flags & COMMANDS_SILENT) && !run_silent))
     OS (message, 0, "%s", p);
 
   /* Tell update_goal_chain that a command has been started on behalf of
index 13c1521eed813c916d088d466557275e7924a01b..e9323fae292232ef8a7e52ed53587297766f725e 100644 (file)
@@ -164,9 +164,13 @@ int verify_flag;
 
 /* Nonzero means do not print commands to be executed (-s).  */
 
-int silent_flag;
+static int silent_flag;
 static const int default_silent_flag = 0;
 
+/* Nonzero means either -s was given, or .SILENT-with-no-deps was seen.  */
+
+int run_silent = 0;
+
 /* Nonzero means just touch the files
    that would appear to need remaking (-t)  */
 
@@ -3012,6 +3016,9 @@ decode_switches (int argc, const char **argv, int env)
   /* If there are any options that need to be decoded do it now.  */
   decode_debug_flags ();
   decode_output_sync_flags ();
+
+  /* Perform any special switch handling.  */
+  run_silent = silent_flag;
 }
 
 /* Decode switches from environment variable ENVAR (which is LEN chars long).
index 2b882c9b4a94c7109f48677dec7560de63165311..dd6e894fbf2ee99d7390242fc44df1eb7044c516 100644 (file)
@@ -654,7 +654,7 @@ extern const floc **expanding_var;
 
 extern unsigned short stopchar_map[];
 
-extern int just_print_flag, silent_flag, ignore_errors_flag, keep_going_flag;
+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;
index 0f0a6d324170840be141cdd0d6721667fdda528a..a331a63aae85997e9446757e84cd2586991f7756 100644 (file)
@@ -221,7 +221,7 @@ update_goal_chain (struct goaldep *goaldeps)
                      any commands were actually started for this goal.  */
                   && file->update_status == us_success && !g->changed
                   /* Never give a message under -s or -q.  */
-                  && !silent_flag && !question_flag)
+                  && !run_silent && !question_flag)
                 OS (message, 1, ((file->phony || file->cmds == 0)
                                  ? _("Nothing to be done for '%s'.")
                                  : _("'%s' is up to date.")),
@@ -1144,7 +1144,7 @@ check_dep (struct file *file, unsigned int depth,
 static enum update_status
 touch_file (struct file *file)
 {
-  if (!silent_flag)
+  if (!run_silent)
     OS (message, 0, "touch %s", file->name);
 
   /* Print-only (-n) takes precedence over touch (-t).  */
index 521930e8ba04f3f29a94df4fa939da128dc41c68..df396a4c56ecf292d6f3cfc326da22335e73d589 100644 (file)
@@ -1,31 +1,33 @@
 #                                                                    -*-perl-*-
 
-$description = "The following tests the special target .SILENT.  By simply\n"
-              ."mentioning this as a target, it tells make not to print\n"
-              ."commands before executing them.";
-
-$details = "This test is the same as the clean test except that it should\n"
-          ."not echo its command before deleting the specified file.\n";
-
-$example = "EXAMPLE_FILE";
-
-open(MAKEFILE,"> $makefile");
-print MAKEFILE qq!
-.SILENT : clean
-clean: ; $CMD_rmfile $example
-!;
-close(MAKEFILE);
-
-touch($example);
-
-$answer = '';
-run_make_with_options($makefile,"clean",&get_logfile,0);
-if (-f $example) {
-  $test_passed = 0;
-}
-compare_output($answer,&get_logfile(1));
-
-# Just in case
-unlink($example);
+$description = "Test the special target .SILENT.";
+
+run_make_test(q!
+.PHONY: M a b
+M: a b
+.SILENT : b
+a b: ; echo $@
+!,
+              '', "echo a\na\nb");
+
+run_make_test(q!
+.PHONY: M a b
+M: a b
+.SILENT:
+a b: ; echo $@
+!,
+              '', "a\nb");
+
+# SV 54740 : don't inherit .SILENT settings in sub-makes
+run_make_test(q!
+.PHONY: M r a b
+r: a b ; @$(MAKE) -f #MAKEFILE# M V=x
+a b: ; echo $@
+
+V =
+$V.SILENT:
+M: a b
+!,
+              '--no-print-directory', "a\nb\necho a\na\necho b\nb");
 
 1;