ChannelDefs.pm (automake-1.16.2.tar.xz) | : | ChannelDefs.pm (automake-1.16.3.tar.xz) | ||
---|---|---|---|---|
skipping to change at line 18 | skipping to change at line 18 | |||
# This program is distributed in the hope that it will be useful, | # This program is distributed in the hope that it will be useful, | |||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
# GNU General Public License for more details. | # GNU General Public License for more details. | |||
# You should have received a copy of the GNU General Public License | # You should have received a copy of the GNU General Public License | |||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | # along with this program. If not, see <https://www.gnu.org/licenses/>. | |||
package Automake::ChannelDefs; | package Automake::ChannelDefs; | |||
use Automake::Config; | ||||
BEGIN | ||||
{ | ||||
if ($perl_threads) | ||||
{ | ||||
require threads; | ||||
import threads; | ||||
} | ||||
} | ||||
use Automake::Channels; | ||||
=head1 NAME | =head1 NAME | |||
Automake::ChannelDefs - channel definitions for Automake and helper functions | Automake::ChannelDefs - channel definitions for Automake and helper functions | |||
=head1 SYNOPSIS | =head1 SYNOPSIS | |||
use Automake::ChannelDefs; | use Automake::ChannelDefs; | |||
Automake::ChannelDefs::usage (); | print Automake::ChannelDefs::usage (), "\n"; | |||
prog_error ($MESSAGE, [%OPTIONS]); | prog_error ($MESSAGE, [%OPTIONS]); | |||
error ($WHERE, $MESSAGE, [%OPTIONS]); | error ($WHERE, $MESSAGE, [%OPTIONS]); | |||
error ($MESSAGE); | error ($MESSAGE); | |||
fatal ($WHERE, $MESSAGE, [%OPTIONS]); | fatal ($WHERE, $MESSAGE, [%OPTIONS]); | |||
fatal ($MESSAGE); | fatal ($MESSAGE); | |||
verb ($MESSAGE, [%OPTIONS]); | verb ($MESSAGE, [%OPTIONS]); | |||
switch_warning ($CATEGORY); | switch_warning ($CATEGORY); | |||
parse_WARNINGS (); | parse_WARNINGS (); | |||
parse_warnings ($OPTION, $ARGUMENT); | parse_warnings ($OPTION, @ARGUMENT); | |||
Automake::ChannelDefs::set_strictness ($STRICTNESS_NAME); | Automake::ChannelDefs::set_strictness ($STRICTNESS_NAME); | |||
=head1 DESCRIPTION | =head1 DESCRIPTION | |||
This packages defines channels that can be used in Automake to | This package defines channels that can be used in Automake to | |||
output diagnostics and other messages (via C<msg()>). It also defines | output diagnostics and other messages (via C<msg()>). It also defines | |||
some helper function to enable or disable these channels, and some | some helper function to enable or disable these channels, and some | |||
shorthand function to output on specific channels. | shorthand function to output on specific channels. | |||
=cut | =cut | |||
use 5.006; | use 5.006; | |||
use strict; | use strict; | |||
use warnings FATAL => 'all'; | ||||
use Exporter; | use Exporter; | |||
use vars qw (@ISA @EXPORT); | use Automake::Channels; | |||
use Automake::Config; | ||||
BEGIN | ||||
{ | ||||
if ($perl_threads) | ||||
{ | ||||
require threads; | ||||
import threads; | ||||
} | ||||
} | ||||
@ISA = qw (Exporter); | our @ISA = qw (Exporter); | |||
@EXPORT = qw (&prog_error &error &fatal &verb | our @EXPORT = qw (&prog_error &error &fatal &verb | |||
&switch_warning &parse_WARNINGS &parse_warnings); | &switch_warning &parse_WARNINGS &parse_warnings | |||
&merge_WARNINGS); | ||||
=head2 CHANNELS | =head2 CHANNELS | |||
The following channels can be used as the first argument of | The following channels can be used as the first argument of | |||
C<Automake::Channel::msg>. For some of them we list a shorthand | C<Automake::Channel::msg>. For some of them we list a shorthand | |||
function that makes the code more readable. | function that makes the code more readable. | |||
=over 4 | =over 4 | |||
=item C<fatal> | =item C<fatal> | |||
skipping to change at line 100 | skipping to change at line 101 | |||
Errors related to GNU Standards that should be warnings in 'foreign' mode. | Errors related to GNU Standards that should be warnings in 'foreign' mode. | |||
=item C<error-gnits> | =item C<error-gnits> | |||
Errors related to GNITS Standards (silent by default). | Errors related to GNITS Standards (silent by default). | |||
=item C<automake> | =item C<automake> | |||
Internal errors. Use C<&prog_error> to send messages over this channel. | Internal errors. Use C<&prog_error> to send messages over this channel. | |||
=item C<cross> | ||||
Constructs compromising the cross-compilation of the package. | ||||
=item C<gnu> | =item C<gnu> | |||
Warnings related to GNU Coding Standards. | Warnings related to GNU Coding Standards. | |||
=item C<obsolete> | =item C<obsolete> | |||
Warnings about obsolete features (silent by default). | Warnings about obsolete features. | |||
=item C<override> | =item C<override> | |||
Warnings about user redefinitions of Automake rules or | Warnings about user redefinitions of Automake rules or | |||
variables (silent by default). | variables (silent by default). | |||
=item C<portability> | =item C<portability> | |||
Warnings about non-portable constructs. | Warnings about non-portable constructs. | |||
=item C<portability-recursive> | ||||
Warnings about recursive variable expansions (C<$(foo$(x))>). | ||||
These are not universally supported, but are more portable than | ||||
the other non-portable constructs diagnosed by C<-Wportability>. | ||||
These warnings are turned on by C<-Wportability> but can then be | ||||
turned off separately by C<-Wno-portability-recursive>. | ||||
=item C<extra-portability> | =item C<extra-portability> | |||
Extra warnings about non-portable constructs covering obscure tools. | Extra warnings about non-portable constructs covering obscure tools. | |||
=item C<syntax> | =item C<syntax> | |||
Warnings about weird syntax, unused variables, typos... | Warnings about weird syntax, unused variables, typos... | |||
=item C<unsupported> | =item C<unsupported> | |||
skipping to change at line 157 | skipping to change at line 170 | |||
register_channel 'error-gnu', type => 'error'; | register_channel 'error-gnu', type => 'error'; | |||
register_channel 'error-gnu/warn', type => 'error'; | register_channel 'error-gnu/warn', type => 'error'; | |||
register_channel 'error-gnits', type => 'error', silent => 1; | register_channel 'error-gnits', type => 'error', silent => 1; | |||
register_channel 'automake', type => 'fatal', backtrace => 1, | register_channel 'automake', type => 'fatal', backtrace => 1, | |||
header => ("####################\n" . | header => ("####################\n" . | |||
"## Internal Error ##\n" . | "## Internal Error ##\n" . | |||
"####################\n"), | "####################\n"), | |||
footer => "\nPlease contact <$PACKAGE_BUGREPORT>.", | footer => "\nPlease contact <$PACKAGE_BUGREPORT>.", | |||
uniq_part => UP_NONE, ordered => 0; | uniq_part => UP_NONE, ordered => 0; | |||
register_channel 'extra-portability', type => 'warning', silent => 1; | register_channel 'cross', type => 'warning', silent => 1; | |||
register_channel 'gnu', type => 'warning'; | register_channel 'gnu', type => 'warning'; | |||
register_channel 'obsolete', type => 'warning'; | register_channel 'obsolete', type => 'warning'; | |||
register_channel 'override', type => 'warning', silent => 1; | register_channel 'override', type => 'warning', silent => 1; | |||
register_channel 'portability', type => 'warning', silent => 1; | register_channel 'portability', type => 'warning', silent => 1; | |||
register_channel 'extra-portability', type => 'warning', silent => 1; | ||||
register_channel 'portability-recursive', type => 'warning', silent => 1; | register_channel 'portability-recursive', type => 'warning', silent => 1; | |||
register_channel 'syntax', type => 'warning'; | register_channel 'syntax', type => 'warning'; | |||
register_channel 'unsupported', type => 'warning'; | register_channel 'unsupported', type => 'warning'; | |||
register_channel 'verb', type => 'debug', silent => 1, uniq_part => UP_NONE, | register_channel 'verb', type => 'debug', silent => 1, uniq_part => UP_NONE, | |||
ordered => 0; | ordered => 0; | |||
register_channel 'note', type => 'debug', silent => 0; | register_channel 'note', type => 'debug', silent => 0; | |||
setup_channel_type 'warning', header => 'warning: '; | setup_channel_type 'warning', header => 'warning: '; | |||
setup_channel_type 'error', header => 'error: '; | setup_channel_type 'error', header => 'error: '; | |||
setup_channel_type 'fatal', header => 'error: '; | setup_channel_type 'fatal', header => 'error: '; | |||
=head2 FUNCTIONS | =head2 FUNCTIONS | |||
=over 4 | =over 4 | |||
=item C<usage ()> | =item C<usage ()> | |||
Display warning categories. | Return the warning category descriptions. | |||
=cut | =cut | |||
sub usage () | sub usage () | |||
{ | { | |||
print <<EOF; | return "Warning categories include: | |||
Warning categories include: | cross cross compilation issues | |||
gnu GNU coding standards (default in gnu and gnits modes) | gnu GNU coding standards (default in gnu and gnits modes) | |||
obsolete obsolete features or constructions | obsolete obsolete features or constructions (default) | |||
override user redefinitions of Automake rules or variables | override user redefinitions of Automake rules or variables | |||
portability portability issues (default in gnu and gnits modes) | portability portability issues (default in gnu and gnits modes) | |||
extra-portability extra portability issues related to obscure tools | portability-recursive nested Make variables (default with -Wportability) | |||
syntax dubious syntactic constructs (default) | extra-portability extra portability issues related to obscure tools | |||
unsupported unsupported or incomplete features (default) | syntax dubious syntactic constructs (default) | |||
all all the warnings | unsupported unsupported or incomplete features (default) | |||
no-CATEGORY turn off warnings in CATEGORY | all all the warnings | |||
none turn off all the warnings | no-CATEGORY turn off warnings in CATEGORY | |||
error treat warnings as errors | none turn off all the warnings | |||
EOF | error treat warnings as errors"; | |||
} | } | |||
=item C<prog_error ($MESSAGE, [%OPTIONS])> | =item C<prog_error ($MESSAGE, [%OPTIONS])> | |||
Signal a programming error (on channel C<automake>), | Signal a programming error (on channel C<automake>), | |||
display C<$MESSAGE>, and exit 1. | display C<$MESSAGE>, and exit 1. | |||
=cut | =cut | |||
sub prog_error ($;%) | sub prog_error ($;%) | |||
skipping to change at line 260 | skipping to change at line 274 | |||
{ | { | |||
my ($msg, %opts) = @_; | my ($msg, %opts) = @_; | |||
$msg = "thread " . threads->tid . ": " . $msg | $msg = "thread " . threads->tid . ": " . $msg | |||
if $perl_threads; | if $perl_threads; | |||
msg 'verb', '', $msg, %opts; | msg 'verb', '', $msg, %opts; | |||
} | } | |||
=item C<switch_warning ($CATEGORY)> | =item C<switch_warning ($CATEGORY)> | |||
If C<$CATEGORY> is C<mumble>, turn on channel C<mumble>. | If C<$CATEGORY> is C<mumble>, turn on channel C<mumble>. | |||
If it's C<no-mumble>, turn C<mumble> off. | If it is C<no-mumble>, turn C<mumble> off. | |||
Else handle C<all> and C<none> for completeness. | Else handle C<all> and C<none> for completeness. | |||
=cut | =cut | |||
sub switch_warning ($) | sub switch_warning ($) | |||
{ | { | |||
my ($cat) = @_; | my ($cat) = @_; | |||
my $has_no = 0; | my $has_no = 0; | |||
if ($cat =~ /^no-(.*)$/) | if ($cat =~ /^no-(.*)$/) | |||
skipping to change at line 341 | skipping to change at line 355 | |||
} | } | |||
return 0; | return 0; | |||
} | } | |||
=item C<parse_WARNINGS ()> | =item C<parse_WARNINGS ()> | |||
Parse the WARNINGS environment variable. | Parse the WARNINGS environment variable. | |||
=cut | =cut | |||
# Used to communicate from parse_WARNINGS to parse_warnings. | ||||
our $_werror = 0; | ||||
sub parse_WARNINGS () | sub parse_WARNINGS () | |||
{ | { | |||
if (exists $ENV{'WARNINGS'}) | if (exists $ENV{'WARNINGS'}) | |||
{ | { | |||
# Ignore unknown categories. This is required because WARNINGS | # Ignore unknown categories. This is required because WARNINGS | |||
# should be honored by many tools. | # should be honored by many tools. | |||
switch_warning $_ foreach (split (',', $ENV{'WARNINGS'})); | # For the same reason, do not turn on -Werror at this point, just | |||
# record that we saw it; parse_warnings will turn on -Werror after | ||||
# the command line has been processed. | ||||
foreach (split (',', $ENV{'WARNINGS'})) | ||||
{ | ||||
if (/^(no-)?error$/) | ||||
{ | ||||
$_werror = !defined $1; | ||||
} | ||||
else | ||||
{ | ||||
switch_warning $_; | ||||
} | ||||
} | ||||
} | } | |||
} | } | |||
=item C<parse_warnings ($OPTION, $ARGUMENT)> | =item C<parse_warnings (@CATEGORIES)> | |||
Parse the argument of C<--warning=CATEGORY> or C<-WCATEGORY>. | Parse the argument of C<--warning=CATEGORY> or C<-WCATEGORY>. | |||
C<@CATEGORIES> is the accumulated set of warnings categories. | ||||
Use like this: | ||||
C<$OPTIONS> is C<"--warning"> or C<"-W">, C<$ARGUMENT> is C<CATEGORY>. | Automake::GetOpt::parse_options ( | |||
# ... | ||||
'W|warnings=s' => \@warnings, | ||||
) | ||||
# possibly call set_strictness here | ||||
parse_warnings @warnings; | ||||
This is meant to be used as an argument to C<Getopt>. | =cut | |||
sub parse_warnings (@) | ||||
{ | ||||
foreach my $cat (map { split ',' } @_) | ||||
{ | ||||
if ($cat =~ /^(no-)?error$/) | ||||
{ | ||||
$_werror = !defined $1; | ||||
} | ||||
elsif (switch_warning $cat) | ||||
{ | ||||
msg 'unsupported', "unknown warning category '$cat'"; | ||||
} | ||||
} | ||||
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 | =cut | |||
sub parse_warnings ($$) | sub merge_WARNINGS (@) | |||
{ | { | |||
my ($opt, $categories) = @_; | 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; | ||||
} | ||||
} | ||||
foreach my $cat (split (',', $categories)) | my @final_warnings; | |||
if ($all_or_none) | ||||
{ | { | |||
msg 'unsupported', "unknown warning category '$cat'" | push @final_warnings, $all_or_none; | |||
if switch_warning $cat; | ||||
} | } | |||
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)> | =item C<set_strictness ($STRICTNESS_NAME)> | |||
Configure channels for strictness C<$STRICTNESS_NAME>. | Configure channels for strictness C<$STRICTNESS_NAME>. | |||
=cut | =cut | |||
sub set_strictness ($) | sub set_strictness ($) | |||
{ | { | |||
skipping to change at line 428 | skipping to change at line 531 | |||
L<Automake::Channels> | L<Automake::Channels> | |||
=head1 HISTORY | =head1 HISTORY | |||
Written by Alexandre Duret-Lutz E<lt>F<adl@gnu.org>E<gt>. | Written by Alexandre Duret-Lutz E<lt>F<adl@gnu.org>E<gt>. | |||
=cut | =cut | |||
1; | 1; | |||
### Setup "GNU" style for perl-mode and cperl-mode. | ||||
## Local Variables: | ||||
## perl-indent-level: 2 | ||||
## perl-continued-statement-offset: 2 | ||||
## perl-continued-brace-offset: 0 | ||||
## perl-brace-offset: 0 | ||||
## perl-brace-imaginary-offset: 0 | ||||
## perl-label-offset: -2 | ||||
## cperl-indent-level: 2 | ||||
## cperl-brace-offset: 0 | ||||
## cperl-continued-brace-offset: 0 | ||||
## cperl-label-offset: -2 | ||||
## cperl-extra-newline-before-brace: t | ||||
## cperl-merge-trailing-else: nil | ||||
## cperl-continued-statement-offset: 2 | ||||
## End: | ||||
End of changes. 27 change blocks. | ||||
45 lines changed or deleted | 148 lines changed or added |