From: Zack Weinberg Date: Fri, 22 Dec 2023 23:52:26 +0000 (-0800) Subject: maint: sync autoconf Channels.pm and ChannelsDefs.pm. X-Git-Tag: v1.16.90~47 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=352d5f6f86d01da65f8828aab7f0682cfb643fbb;p=thirdparty%2Fautomake.git maint: sync autoconf Channels.pm and ChannelsDefs.pm. Patch from https://bugs.gnu.org/67971. The changes address , 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. --- 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 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