1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
# -*- perl -*-
# Lintian::Processable::Source::Relation -- interface to source package data collection
# Copyright (C) 2008 Russ Allbery
# Copyright (C) 2009 Raphael Geissert
# Copyright (C) 2020 Felix Lechner
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
package Lintian::Processable::Source::Relation;
use v5.20;
use warnings;
use utf8;
use Carp qw(croak);
use Unicode::UTF8 qw(encode_utf8);
use Lintian::Relation;
use Moo::Role;
use namespace::clean;
=head1 NAME
Lintian::Processable::Source::Relation - Lintian interface to source package data collection
=head1 SYNOPSIS
my ($name, $type, $dir) = ('foobar', 'source', '/path/to/lab-entry');
my $collect = Lintian::Processable::Source::Relation->new($name);
if ($collect->native) {
print encode_utf8("Package is native\n");
}
=head1 DESCRIPTION
Lintian::Processable::Source::Relation provides an interface to package data for source
packages. It implements data collection methods specific to source
packages.
This module is in its infancy. Most of Lintian still reads all data from
files in the laboratory whenever that data is needed and generates that
data via collect scripts. The goal is to eventually access all data about
source packages via this module so that the module can cache data where
appropriate and possibly retire collect scripts in favor of caching that
data in memory.
=head1 INSTANCE METHODS
=over 4
=item binary_relation (PACKAGE, FIELD)
Returns a L<Lintian::Relation> object for the specified FIELD in the
binary package PACKAGE in the F<debian/control> file. FIELD should be
one of the possible relationship fields of a Debian package or one of
the following special values:
=over 4
=item All
The concatenation of Pre-Depends, Depends, Recommends, and Suggests.
=item Strong
The concatenation of Pre-Depends and Depends.
=item Weak
The concatenation of Recommends and Suggests.
=back
If FIELD isn't present in the package, the returned Lintian::Relation
object will be empty (present but satisfies nothing).
Any substvars in F<debian/control> will be represented in the returned
relation as packages named after the substvar.
=item saved_binary_relations
=cut
has saved_binary_relations => (
is => 'rw',
coerce => sub { my ($hashref) = @_; return ($hashref // {}); },
default => sub { {} }
);
my %alias = (
all => [qw(Pre-Depends Depends Recommends Suggests)],
strong => [qw(Pre-Depends Depends)],
weak => [qw(Recommends Suggests)]
);
my %known = map { $_ => 1 }
qw(pre-depends depends recommends suggests enhances breaks
conflicts provides replaces);
sub binary_relation {
my ($self, $package, $name) = @_;
return undef
unless length $name;
my $lowercase = lc $name;
return undef
unless length $package;
my $relation = $self->saved_binary_relations->{$package}{$lowercase};
unless (defined $relation) {
if (length $alias{$lowercase}) {
$relation
= Lintian::Relation->new->logical_and(
map { $self->binary_relation($package, $_) }
@{ $alias{$lowercase} });
} else {
croak encode_utf8("unknown relation field $name")
unless $known{$lowercase};
my $value
= $self->debian_control->installable_fields($package)
->value($name);
$relation = Lintian::Relation->new->load($value);
}
$self->saved_binary_relations->{$package}{$lowercase} = $relation;
}
return $relation;
}
=item relation (FIELD)
Returns a L<Lintian::Relation> object for the given build relationship
field FIELD. In addition to the normal build relationship fields, the
following special field names are supported:
=over 4
=item Build-Depends-All
The concatenation of Build-Depends, Build-Depends-Arch and
Build-Depends-Indep.
=item Build-Conflicts-All
The concatenation of Build-Conflicts, Build-Conflicts-Arch and
Build-Conflicts-Indep.
=back
If FIELD isn't present in the package, the returned Lintian::Relation
object will be empty (present but satisfies nothing).
=item saved_relation
=cut
has saved_relations => (
is => 'rw',
coerce => sub { my ($hashref) = @_; return ($hashref // {}); },
default => sub { {} }
);
sub relation {
my ($self, $name) = @_;
return undef
unless length $name;
my $lowercase = lc $name;
my $relation = $self->saved_relations->{$lowercase};
unless (defined $relation) {
if ($name =~ /^Build-(Depends|Conflicts)-All$/i) {
my $type = $1;
my @fields
= ("Build-$type", "Build-$type-Indep", "Build-$type-Arch");
$relation
= Lintian::Relation->new->logical_and(map { $self->relation($_) }
@fields);
} elsif ($name =~ /^Build-(Depends|Conflicts)(?:-(?:Arch|Indep))?$/i){
my $value = $self->fields->value($name);
$relation = Lintian::Relation->new->load($value);
} else {
croak encode_utf8("unknown relation field $name");
}
$self->saved_relations->{$lowercase} = $relation;
}
return $relation;
}
=item relation_norestriction (FIELD)
The same as L</relation (FIELD)>, but ignores architecture
restrictions and build profile restrictions in the FIELD field.
=item saved_relations_norestriction
=cut
has saved_relations_norestriction => (
is => 'rw',
coerce => sub { my ($hashref) = @_; return ($hashref // {}); },
default => sub { {} }
);
sub relation_norestriction {
my ($self, $name) = @_;
return undef
unless length $name;
my $lowercase = lc $name;
my $relation = $self->saved_relations_norestriction->{$lowercase};
unless (defined $relation) {
$relation = $self->relation($name)->restriction_less;
$self->saved_relations_norestriction->{$lowercase} = $relation;
}
return $relation;
}
=back
=head1 AUTHOR
Originally written by Russ Allbery <rra@debian.org> for Lintian.
Amended by Felix Lechner <felix.lechner@lease-up.com> for Lintian.
=head1 SEE ALSO
lintian(1)
=cut
1;
# Local Variables:
# indent-tabs-mode: nil
# cperl-indent-level: 4
# End:
# vim: syntax=perl sw=4 sts=4 sr et
|