[SCM] Debian package checker branch, vendor-profile, updated. 2.5.0-rc3-6-gbb9376d
The following commit has been merged in the vendor-profile branch:
commit bb9376d05780a500e30218b18e6bad94cbbd1e54
Author: Niels Thykier <niels@thykier.net>
Date: Tue May 31 16:27:02 2011 +0200
Added support for non-overwritable tags in profiles
diff --git a/frontend/lintian b/frontend/lintian
index 46588bd..9524238 100755
--- a/frontend/lintian
+++ b/frontend/lintian
@@ -662,8 +662,10 @@ unless (defined $check_tags || %suppress_tags){
my $profile = Lintian::Profile->new($LINTIAN_PROFILE,
[PROFILE_PATH, "$LINTIAN_ROOT/profiles"]);
my @ptags = $profile->tags;
- v_msg('Using profile ' . $profile->name . ".\n");
- $TAGS->only(@ptags);
+ my @ign_overrides = $profile->ignored_overrides;
+ v_msg('Using profile ' . $profile->name . '.');
+ $TAGS->only(@ptags) if @ptags;
+ $TAGS->ignore_overrides(@ign_overrides) if @ign_overrides;
}
}
diff --git a/lib/Lintian/Profile.pm b/lib/Lintian/Profile.pm
index 91249df..4042e69 100644
--- a/lib/Lintian/Profile.pm
+++ b/lib/Lintian/Profile.pm
@@ -60,10 +60,11 @@ sub new {
if $name =~ m,^/,o or $name =~ m/\./o;
_load_checks() unless %TAG_MAP;
my $self = {
- 'parent-map' => {},
- 'parents' => [],
- 'profile-path' => $ppath,
- 'enabled-tags' => {},
+ 'parent-map' => {},
+ 'parents' => [],
+ 'profile-path' => $ppath,
+ 'enabled-tags' => {},
+ 'ignored-overrides' => {},
};
$self = bless $self, $type;
$profile = $self->_find_profile($name);
@@ -80,6 +81,11 @@ sub tags {
return keys %{ $self->{'enabled-tags'} };
}
+sub ignored_overrides {
+ my ($self) = @_;
+ return keys %{ $self->{'ignored-overrides'} };
+}
+
sub _find_profile {
my ($self, $pname) = @_;
my $pfile;
@@ -102,7 +108,7 @@ sub _read_profile {
open(my $fd, '<', $pfile) or fail "$pfile: $!";
@pdata = parse_dpkg_control($fd, 0);
close $fd;
- $pheader = $pdata[0];
+ $pheader = shift @pdata;
fail "Profile field is missing from $pfile."
unless defined $pheader && $pheader->{'profile'};
$pname = $pheader->{'profile'};
@@ -125,12 +131,34 @@ sub _read_profile {
push @$plist, $parent;
}
$self->_read_profile_tags($pname, $pheader);
+ if (@pdata){
+ my $i = 2; # section counter
+ foreach my $psection (@pdata){
+ $self->_read_profile_section($pname, $psection, $i++);
+ }
+ }
+}
+
+sub _read_profile_section {
+ my ($self, $pname, $section, $sno) = @_;
+ my @tags = $self->_split_comma_sep_field($section->{'tag'});
+ my $overwritable = $self->_parse_boolean($section->{'overwritable'}, 0, $pname, $sno);
+ my $ignore_map = $self->{'ignored-overrides'};
+ fail "Profile \"$pname\" is missing Tag field (or it is empty) in section $sno." unless @tags;
+ foreach my $tag (@tags) {
+ fail "Unknown check $tag in $pname (section $sno)\n" unless exists $TAG_MAP{$tag};
+ if ($overwritable) {
+ delete $ignore_map->{$tag};
+ } else {
+ $ignore_map->{$tag} = 1;
+ }
+ }
}
sub _read_profile_tags{
my ($self, $pname, $pheader) = @_;
- Lintian::Profile::_check_duplicates($pname, $pheader, 'enable-tags-from-check', 'disable-tags-from-check');
- Lintian::Profile::_check_duplicates($pname, $pheader, 'enable-tag', 'disable-tag');
+ $self->_check_duplicates($pname, $pheader, 'enable-tags-from-check', 'disable-tags-from-check');
+ $self->_check_duplicates($pname, $pheader, 'enable-tag', 'disable-tag');
my $tags_from_check_sub = sub {
my ($field, $check) = @_;
fail "Unknown check $check in $pname\n" unless exists $CHECK_MAP{$check};
@@ -151,7 +179,7 @@ sub _enable_tags_from_field {
my ($self, $pname, $pheader, $field, $code, $enable) = @_;
my $tags = $self->{'enabled-tags'};
return unless $pheader->{$field};
- foreach my $tag (map { $code->($field, $_) } split m/\s*+,\s*+/o, $pheader->{$field}){
+ foreach my $tag (map { $code->($field, $_) } $self->_split_comma_sep_field($pheader->{$field})){
if($enable) {
$tags->{$tag} = 1;
} else {
@@ -161,7 +189,7 @@ sub _enable_tags_from_field {
}
sub _check_duplicates{
- my ($name, $map, @fields) = @_;
+ my ($self, $name, $map, @fields) = @_;
my %dupmap;
foreach my $field (@fields) {
next unless exists $map->{$field};
@@ -177,4 +205,29 @@ sub _check_duplicates{
}
}
+# $self->($bool, $def, $pname, $sno);
+#
+# Parse $bool as a string representing a bool; if undefined return $def.
+# $pname and $sno are the Profile name and section number - used for
+# error reporting.
+sub _parse_boolean {
+ my ($self, $bool, $def, $pname, $sno) = @_;
+ return $def unless defined $bool;
+ $bool = lc $bool;
+ return 1 if $bool eq 'yes' || $bool eq 'true' ||
+ ($bool =~ m/^\d++$/o && $bool != 0);
+ return 0 if $bool eq 'no' || $bool eq 'false' ||
+ ($bool =~ m/^\d++$/o && $bool == 0);
+ fail "\"$bool\" is not a boolean value in $pname (section $sno).";
+}
+
+sub _split_comma_sep_field {
+ my ($self, $data) = @_;
+ return () unless defined $data;
+ # remove trailing and leading white-space
+ $data =~ s/^\s++//o;
+ $data =~ s/\s++$//o;
+ return split m/\s*,\s*/o, $data;
+}
+
1;
diff --git a/lib/Lintian/Tags.pm b/lib/Lintian/Tags.pm
index 153ae4b..c13acab 100644
--- a/lib/Lintian/Tags.pm
+++ b/lib/Lintian/Tags.pm
@@ -159,6 +159,7 @@ sub new {
show_pedantic => 0,
statistics => {},
suppress => {},
+ ignored_overrides => {},
};
bless($self, $class);
$GLOBAL = $self unless $GLOBAL;
@@ -522,6 +523,7 @@ file cannot be opened.
sub file_overrides {
my ($self, $overrides) = @_;
+ my $ignored = $self->{ignored_overrides};
unless (defined $self->{current}) {
die 'no current file when adding overrides';
}
@@ -540,6 +542,7 @@ sub file_overrides {
tag('malformed-override', $_);
} else {
my ($tag, $extra) = split(/ /, $override, 2);
+ next if $ignored->{$tag};
$extra = '' unless defined $extra;
$info->{overrides}{$tag}{$extra} = 0;
}
@@ -692,6 +695,21 @@ sub suppressed {
return;
}
+=item ignore_overrides(TAG[, ...])
+
+Ignores all future overrides for all tags given as arguments.
+
+=cut
+
+sub ignore_overrides {
+ my ($self, @tags) = @_;
+ my $ignored = $self->{ignored_overrides};
+ foreach my $tag (@tags){
+ $ignored->{$tag} = 1;
+ }
+ return 1;
+}
+
=back
=head1 AUTHOR
--
Debian package checker
Reply to: