Subject: bug#67971: closed (Re: [bug#67971] [PATCH] Sync shared files from Autoconf)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 23 Dec 2023 01:47:02 +0000

Your bug report

#67971: [PATCH] Sync shared files from Autoconf

which was filed against the automake-patches package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
67971: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=67971
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: [bug#67971] [PATCH] Sync shared files from Autoconf
From: Karl Berry <[email-masked]>
To: [email-masked]
Cc: [email-masked]
Date: Fri, 22 Dec 2023 18:46:26 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

    lib/Automake/ChannelDefs.pm and lib/Automake/Channels.pm were updated
    in Autoconf to address <https://savannah.gnu.org/support/?110872>.

Thanks Zack. Installed.

BTW, the automake THANKS file has your panix.com address. Is that still
ok, or should I update it to owlfolio? (Not that it really matters.) -k

Subject: [PATCH] Sync shared files from Autoconf
From: Zack Weinberg <[email-masked]>
To: [email-masked]
Date: Fri, 22 Dec 2023 13:10:12 -0500
List-Id: <debbugs-submit.debbugs.gnu.org>

lib/Automake/ChannelDefs.pm and lib/Automake/Channels.pm were updated
in Autoconf to address <https://savannah.gnu.org/support/?110872>.
Bring over the changes.

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 | 10 ++++----
 lib/Automake/Channels.pm    | 47 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 5 deletions(-)

diff --git a/lib/Automake/ChannelDefs.pm b/lib/Automake/ChannelDefs.pm
index 1c436645e..8b334ee93 100644
--- a/lib/Automake/ChannelDefs.pm
+++ b/lib/Automake/ChannelDefs.pm
@@ -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])>
diff --git a/lib/Automake/Channels.pm b/lib/Automake/Channels.pm
index b4563d36e..84e93d106 100644
--- a/lib/Automake/Channels.pm
+++ b/lib/Automake/Channels.pm
@@ -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)>
 
-- 
2.41.0