]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
maint: sync autoconf Channels.pm and ChannelsDefs.pm.
authorZack Weinberg <zack@owlfolio.org>
Fri, 22 Dec 2023 23:52:26 +0000 (15:52 -0800)
committerKarl Berry <karl@freefriends.org>
Fri, 22 Dec 2023 23:52:26 +0000 (15:52 -0800)
Patch from https://bugs.gnu.org/67971.

The changes address <https://savannah.gnu.org/support/?110872>,
about m4_warn code/documentation consistency.
It should be impossible to reach report_bad_channel from code in
Automake.

* lib/Automake/Channels.pm (msg): If the channel argument is invalid,
don't crash; report the mistake and use the `syntax' channel.
(report_bad_channel): New function for reporting invalid channels.

* lib/Automake/ChannelDefs.pm (usage): Clarify that the list of
warning categories is exhaustive, and that ``all'', ``none'',
``no-CATEGORY'', and ``error'' are not warning categories.

lib/Automake/ChannelDefs.pm
lib/Automake/Channels.pm

index 1c436645ecdf39e252fe772ffad363ece4844fcf..8b334ee93bf8540b385f64bcc2b01b5fa390a096 100644 (file)
@@ -197,7 +197,7 @@ Return the warning category descriptions.
 
 sub usage ()
 {
-  return "Warning categories include:
+  return "Warning categories are:
   cross                  cross compilation issues
   gnu                    GNU coding standards (default in gnu and gnits modes)
   obsolete               obsolete features or constructions (default)
@@ -207,10 +207,12 @@ sub usage ()
   extra-portability      extra portability issues related to obscure tools
   syntax                 dubious syntactic constructs (default)
   unsupported            unsupported or incomplete features (default)
-  all                    all the warnings
-  no-CATEGORY            turn off warnings in CATEGORY
+
+-W also understands:
+  all                    turn on all the warnings
   none                   turn off all the warnings
-  error                  treat warnings as errors";
+  no-CATEGORY            turn off warnings in CATEGORY
+  error                  treat all enabled warnings as errors";
 }
 
 =item C<prog_error ($MESSAGE, [%OPTIONS])>
index b4563d36e0ff12aed02d7fd27d9f393bfe743313..84e93d10646636fa7b8a330d01f272ec3319aab2 100644 (file)
@@ -628,7 +628,13 @@ sub msg ($$;$%)
       $location = '';
     }
 
-  confess "unknown channel $channel" unless exists $channels{$channel};
+  if (!exists $channels{$channel})
+    {
+      # This can happen as a result of e.g. m4_warn([nonsense], [message])
+      # so it should not crash.
+      report_bad_channel($channel, $location);
+      $channel = 'syntax';
+    }
 
   my %opts = %{$channels{$channel}};
   _merge_options (%opts, %options);
@@ -662,6 +668,45 @@ sub msg ($$;$%)
     }
 }
 
+sub report_bad_channel ($$)
+{
+  my ($channel, $location) = @_;
+  my $message;
+  my $report_as = 'error';
+
+  # quotemeta is both too aggressive (e.g. it escapes '-') and
+  # too generous (it turns control characters into \ + themselves,
+  # not into symbolic escapes).
+  my $q_channel = $channel;
+  $q_channel =~ s/(?=[\"\$\'\@\`\\])/\\/g;
+  $q_channel =~ s/([^\x20-\x7e])/sprintf('\\x%02X', ord $1)/eg;
+  $q_channel = '"' . $q_channel . '"';
+
+  if ($channel eq '' || $channel eq 'all')
+    {
+      # Prior to version 2.70, the Autoconf manual said it was valid to use
+      # "all" and the empty string as the category argument to m4_warn, so
+      # don't treat those cases as errors.
+      $report_as = 'obsolete';
+      $message = "use of $q_channel as a diagnostic category is obsolete\n";
+      $message .= "(see automake --help for a list of valid categories)";
+    }
+  elsif ($channel eq 'none'
+         || ($channel =~ /^no-/ && exists $channels{substr($channel, 3)}))
+    {
+      # Also recognize "none" and "no-[category]", as someone might have
+      # thought anything acceptable to -W is also acceptable to m4_warn.
+      # Note: m4_warn([error], [...]) does actually issue an error.
+      $message = "-W accepts $q_channel, but it is not a diagnostic category";
+    }
+  else
+    {
+      $message = "unknown diagnostic category " . $q_channel;
+    }
+
+  msg $report_as, $location, $message;
+}
+
 
 =item C<setup_channel ($channel, %options)>