summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2020-09-13 11:33:05 -0400
committerZack Weinberg <zackw@panix.com>2020-09-18 13:39:50 -0400
commit22089fa6e91f944411aea174b2d5840871142d1b (patch)
treec8db4fdddb36d0607c88c97295de67195d4971c0
parent626727a8ddcd1d0ec185a26dab573674d5536c32 (diff)
downloadautomake-22089fa6e91f944411aea174b2d5840871142d1b.tar.gz
New utility function Automake::ChannelDefs::merge_WARNINGS.
This function merges a list of warnings categories into the environment variable WARNINGS, returning a new value to set it to. The intended use is in code of the form { local $ENV{WARNINGS} = merge_WARNINGS ("this", "that"); # run a command here with WARNINGS=this,that,etc } This is not actually used in automake, but will be in autoconf. * lib/Automake/ChannelDefs.pm (merge_WARNINGS): New function.
-rw-r--r--lib/Automake/ChannelDefs.pm67
1 files changed, 65 insertions, 2 deletions
diff --git a/lib/Automake/ChannelDefs.pm b/lib/Automake/ChannelDefs.pm
index b98191b4c..e9aaf2f80 100644
--- a/lib/Automake/ChannelDefs.pm
+++ b/lib/Automake/ChannelDefs.pm
@@ -63,7 +63,8 @@ BEGIN
our @ISA = qw (Exporter);
our @EXPORT = qw (&prog_error &error &fatal &verb
- &switch_warning &parse_WARNINGS &parse_warnings);
+ &switch_warning &parse_WARNINGS &parse_warnings
+ &merge_WARNINGS);
=head2 CHANNELS
@@ -107,7 +108,7 @@ Warnings related to GNU Coding Standards.
=item C<obsolete>
-Warnings about obsolete features (silent by default).
+Warnings about obsolete features.
=item C<override>
@@ -409,6 +410,68 @@ sub parse_warnings (@)
switch_warning ($_werror ? 'error' : 'no-error');
}
+=item C<merge_WARNINGS (@CATEGORIES)>
+
+Merge the warnings categories in the environment variable C<WARNINGS>
+with the warnings categories in C<@CATEGORIES>, and return a new
+value for C<WARNINGS>. Values in C<@CATEGORIES> take precedence.
+Use like this:
+
+ local $ENV{WARNINGS} = merge_WARNINGS @additional_warnings;
+
+=cut
+
+sub merge_WARNINGS (@)
+{
+ my $werror = '';
+ my $all_or_none = '';
+ my %warnings;
+
+ my @categories = split /,/, $ENV{WARNINGS} || '';
+ push @categories, @_;
+
+ foreach (@categories)
+ {
+ if (/^(?:no-)?error$/)
+ {
+ $werror = $_;
+ }
+ elsif (/^(?:all|none)$/)
+ {
+ $all_or_none = $_;
+ }
+ else
+ {
+ # The character class in the second match group is ASCII \S minus
+ # comma. We are generous with this because category values may come
+ # from WARNINGS and we don't want to assume what other programs'
+ # syntaxes for warnings categories are.
+ /^(no-|)([\w\[\]\/\\!"#$%&'()*+-.:;<=>?@^`{|}~]+)$/
+ or die "Invalid warnings category: $_";
+ $warnings{$2} = $1;
+ }
+ }
+
+ my @final_warnings;
+ if ($all_or_none)
+ {
+ push @final_warnings, $all_or_none;
+ }
+ else
+ {
+ foreach (sort keys %warnings)
+ {
+ push @final_warnings, $warnings{$_} . $_;
+ }
+ }
+ if ($werror)
+ {
+ push @final_warnings, $werror;
+ }
+
+ return join (',', @final_warnings);
+}
+
=item C<set_strictness ($STRICTNESS_NAME)>
Configure channels for strictness C<$STRICTNESS_NAME>.