[SCM] Debian package checker branch, master, updated. 2.5.6-79-gdfe0efa
The following commit has been merged in the master branch:
commit ff56bdc0f61d90ced58a84e3130da81d1c104a5a
Author: Niels Thykier <niels@thykier.net>
Date: Mon Apr 9 11:17:24 2012 +0200
L::Relation: Add "and" constructor
Exploit that L::Relation objects are immutable to create an "and"
constructor. This constructor creats an L::Relation object from
L::Relation objects and textual relations. The new L::Relation object
will use the internal structure of other L::Relation objects were
possible to reduce overhead.
The main advantage of this constructor is that it allows better reuse
of the L::Collect::relation method
Signed-off-by: Niels Thykier <niels@thykier.net>
diff --git a/checks/debhelper b/checks/debhelper
index 703b4a1..4e2b960 100644
--- a/checks/debhelper
+++ b/checks/debhelper
@@ -23,6 +23,7 @@ use strict;
use warnings;
use Lintian::Data;
+use Lintian::Relation;
use Lintian::Tags qw(tag);
use Lintian::Util qw(fail slurp_entire_file);
@@ -52,6 +53,8 @@ my %versions = (
dh_ucf => '8.1.5~',
);
+my $MISC_DEPENDS = Lintian::Relation->new ('${misc:Depends}');
+
sub run {
my $pkg = shift;
@@ -223,22 +226,17 @@ my $pkgs = $info->binaries;
my $single_pkg = keys(%$pkgs) == 1 ? $pkgs->{(keys(%$pkgs))[0]} : '';
for my $binpkg (keys %$pkgs) {
- my ($weak_depends, $strong_depends, $depends) = ('','','');
+ next if $pkgs->{$binpkg} ne 'deb';
+ my $strong = $info->binary_relation ($binpkg, 'strong');
+ my $all = $info->binary_relation ($binpkg, 'all');
- foreach my $field (qw(pre-depends depends)) {
- $strong_depends .= ($info->binary_field($binpkg, $field)//'');
- }
- foreach my $field (qw(recommends suggests)) {
- $weak_depends .= ($info->binary_field($binpkg, $field)//'');
+ if (!$all->implies ($MISC_DEPENDS)) {
+ tag 'debhelper-but-no-misc-depends', $binpkg;
+ } else {
+ tag 'weak-dependency-on-misc-depends', $binpkg
+ unless $strong->implies ($MISC_DEPENDS);
}
- $depends = $weak_depends . $strong_depends;
-
- tag 'debhelper-but-no-misc-depends', $binpkg
- if $depends !~ m/\$\{misc:Depends\}/ and $pkgs->{$binpkg} eq 'deb';
- tag 'weak-dependency-on-misc-depends', $binpkg
- if $weak_depends =~ m/\$\{misc:Depends\}/
- and $pkgs->{$binpkg} eq 'deb';
}
my $compatnan = 0;
diff --git a/checks/scripts b/checks/scripts
index c95e6d2..0368a5c 100644
--- a/checks/scripts
+++ b/checks/scripts
@@ -262,16 +262,10 @@ foreach (@{$info->sorted_index}) {
$executable{$_} = 1;
}
-my $all_deps = '';
-for my $field (qw/suggests recommends depends pre-depends provides/) {
- if (defined $info->field($field)) {
- $all_deps .= ', ' if $all_deps;
- $all_deps .= $info->field($field);
- }
-}
-$all_deps .= ', ' if $all_deps;
-$all_deps .= $pkg;
-my $all_parsed = Lintian::Relation->new($all_deps);
+my $all_parsed = Lintian::Relation->and ($info->relation ('all'),
+ $info->relation ('provides'),
+ $pkg);
+my $all_deps = $all_parsed->unparse ();
my $str_deps = $info->relation('strong');
diff --git a/checks/shared-libs b/checks/shared-libs
index 089d436..a479364 100644
--- a/checks/shared-libs
+++ b/checks/shared-libs
@@ -259,10 +259,7 @@ $provides .= "( = $version)" if defined $version;
# Assume the version to be a non-native version to avoid
# uninitialization warnings later.
$version = '0-1' unless defined $version;
-if (defined $info->field('provides')) {
- $provides .= ', ' . $info->field('provides');
-}
-$provides = Lintian::Relation->new($provides);
+$provides = Lintian::Relation->and ($info->relation ('provides'), $provides);
my $shlibsf = $info->control('shlibs');
my $symbolsf = $info->control('symbols');
diff --git a/lib/Lintian/Collect/Binary.pm b/lib/Lintian/Collect/Binary.pm
index 4dff890..4157b55 100644
--- a/lib/Lintian/Collect/Binary.pm
+++ b/lib/Lintian/Collect/Binary.pm
@@ -312,22 +312,18 @@ sub relation {
weak => [ qw(recommends suggests) ]);
my $result;
if ($special{$field}) {
- my $merged;
- for my $f (@{ $special{$field} }) {
- my $value = $self->field($f);
- $merged .= ', ' if (defined($merged) and defined($value));
- $merged .= $value if defined($value);
- }
- $result = $merged;
+ $result = Lintian::Relation->and (
+ map { $self->relation ($_) } @{ $special{$field} }
+ );
} else {
my %known = map { $_ => 1 }
qw(pre-depends depends recommends suggests enhances breaks
conflicts provides replaces);
croak("unknown relation field $field") unless $known{$field};
my $value = $self->field($field);
- $result = $value if defined($value);
+ $result = Lintian::Relation->new ($value);
}
- $self->{relation}->{$field} = Lintian::Relation->new($result);
+ $self->{relation}->{$field} = $result;
return $self->{relation}->{$field};
}
diff --git a/lib/Lintian/Collect/Source.pm b/lib/Lintian/Collect/Source.pm
index c183c96..6b48846 100644
--- a/lib/Lintian/Collect/Source.pm
+++ b/lib/Lintian/Collect/Source.pm
@@ -191,6 +191,7 @@ sub _load_binary_fields {
# following special field names are supported: all (pre-depends, depends,
# recommends, and suggests), strong (pre-depends and depends), and weak
# (recommends and suggests).
+# sub binary_relation Needs-Info debfiles
sub binary_relation {
my ($self, $package, $field) = @_;
$field = lc $field;
@@ -202,23 +203,17 @@ sub binary_relation {
weak => [ qw(recommends suggests) ]);
my $result;
if ($special{$field}) {
- my $merged;
- for my $f (@{ $special{$field} }) {
- # sub binary_relation Needs-Info debfiles
- my $value = $self->binary_field($package, $f);
- $merged .= ', ' if (defined($merged) and defined($value));
- $merged .= $value if defined($value);
- }
- $result = $merged;
+ $result = Lintian::Relation->and (
+ map { $self->binary_relation ($package, $_) } @{ $special{$field} }
+ );
} else {
my %known = map { $_ => 1 }
qw(pre-depends depends recommends suggests enhances breaks
conflicts provides replaces);
croak("unknown relation field $field") unless $known{$field};
my $value = $self->binary_field($package, $field);
- $result = $value if defined($value);
+ $result = Lintian::Relation->new ($value);
}
- $result = Lintian::Relation->new($result);
$self->{binary_relation}->{$package}->{$field} = $result;
return $result;
}
diff --git a/lib/Lintian/Relation.pm b/lib/Lintian/Relation.pm
index f434fb4..3de9670 100644
--- a/lib/Lintian/Relation.pm
+++ b/lib/Lintian/Relation.pm
@@ -160,6 +160,46 @@ sub new_noarch {
return $class->new($relation);
}
+
+=item and(RELATION, ...)
+
+Creates a new Lintian::Relation object produced by AND'ing all the
+relations together. Semantically it is the similar to:
+
+ Lintian::Relation->new (join (', ', @relations))
+
+Except it can avoid some overhead and it works if some of the elements
+are Lintian::Relation objects already.
+
+=cut
+
+sub and {
+ my ($class, @args) = @_;
+ my @result;
+ foreach my $arg (@args) {
+ my $rel = $arg;
+ unless ($arg && ref $arg eq 'Lintian::Relation') {
+ # Optimize out empty entries.
+ next unless $arg;
+ $rel = Lintian::Relation->new ($arg);
+ }
+ if ($rel->[0] eq 'AND') {
+ my @r = @$rel;
+ push @result, @r[1..$#r];
+ } else {
+ push @result, $rel;
+ }
+ }
+ my $self;
+ if (@result == 1) {
+ $self = $result[0];
+ } else {
+ $self = ['AND', @result];
+ }
+ bless ($self, $class);
+ return $self;
+}
+
=back
=head1 INSTANCE METHODS
diff --git a/t/tests/control-file-general/debian/debian/control.in b/t/tests/control-file-general/debian/debian/control.in
index 58b3c45..d99a5b2 100644
--- a/t/tests/control-file-general/debian/debian/control.in
+++ b/t/tests/control-file-general/debian/debian/control.in
@@ -20,7 +20,7 @@ Section: {$section}
Maintainer: {$author}
Build-Conflicts: foo
Architecture: {$architecture}
-Depends: {$srcpkg}, foo, baz, $\{shlibs:Depends\} $\{misc:Depends\}
+Depends: {$srcpkg}, foo, baz, $\{shlibs:Depends\} $\{some:Depends\}, $\{misc:Depends\}
Recommends: foo, bar, no-match$\{lintian:Foo\}, match$\{lintian:Match\}, no-match$\{lintian:Bar\}-foo
Suggests: bar | baz, no-match$\{lintian:Bar\}, match$\{lintian:Match\}
Description: {$description}
diff --git a/t/tests/control-file-general/tags b/t/tests/control-file-general/tags
index 0baad60..025eab2 100644
--- a/t/tests/control-file-general/tags
+++ b/t/tests/control-file-general/tags
@@ -1,5 +1,5 @@
E: control-file-general source: build-info-in-binary-control-file-section Package control-file-general
-E: control-file-general source: missing-separator-between-items in control-file-general depends field between '${shlibs:Depends}' and '${misc:Depends}'
+E: control-file-general source: missing-separator-between-items in control-file-general depends field between '${shlibs:Depends}' and '${some:Depends}'
I: control-file-general source: binary-control-field-duplicates-source field "maintainer" in package control-file-general
I: control-file-general source: duplicate-long-description control-file-general control-file-general-1 control-file-general-2 control-file-general-3 control-file-general-4
I: control-file-general source: duplicate-short-description control-file-general control-file-general-1
--
Debian package checker
Reply to: