Added some code to peer into a data structure in Maemian/Schedule.pm. Also added the
[maemian] / nokia-lintian / checks / version-substvars
1 # version-substvars -- lintian check script -*- perl -*-
2 #
3 # Copyright (C) 2006 Adeodato Simó
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, you can find it on the World Wide
17 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
18 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20
21 # SUMMARY
22 # =======
23 #
24 # What breaks
25 # -----------
26 #
27 # (b1) any -> any (= ${source:Version})          -> use b:V
28 # (b2) any -> all (= ${Source-Version}) [or b:V] -> use s:V
29 # (b3) all -> any (= ${either-of-them})          -> use (>= ${s:V}),
30 #                                                   optionally (<< ${s:V}.1~)
31 #
32 # Always warn on ${Source-Version} even if it doesn't break since the substvar
33 # is now considered deprecated.
34
35 package Lintian::version_substvars;
36 use strict;
37
38 use Util;
39 use Tags;
40
41 sub run {
42
43 my $pkg = shift;
44 my $type = shift;
45
46 my @control_data = read_dpkg_control("debfiles/control");
47 my @dep_fields = qw(depends pre-depends recommends suggests conflicts replaces);
48
49 shift @control_data; # skip source info entry
50
51 foreach (@control_data) {
52         my ($pkg1, $pkg1_is_any, $pkg2, $pkg2_is_any, $substvar_strips_binNMU);
53
54         $pkg1 = $_->{'package'};
55         $pkg1_is_any = ($_->{'architecture'} ne 'all');
56
57         foreach my $field (@dep_fields) {
58                 next unless $_->{$field};
59                 if ($_->{$field} =~ m/\${Source-Version}/) {
60                         tag "substvar-source-version-is-deprecated", $pkg1;
61                 }
62         }
63
64         foreach (split(m/,/, ($_->{'pre-depends'} || "").", ".
65                        ($_->{'depends'} || ""))) {
66                 next unless m/(\S+)\s*\(\s*=\s*\${((?:Source-|source:|binary:)Version)}/x;
67
68                 $pkg2 = $1;
69                 $substvar_strips_binNMU = ($2 eq 'source:Version');
70
71                 if (not -f "control/$pkg2/architecture") {
72                         tag "version-substvar-for-external-package", "$pkg1 -> $pkg2";
73                         next;
74                 }
75                 $pkg2_is_any = (slurp_entire_file("control/$pkg2/architecture") !~ m/^all$/);
76
77                 if ($pkg1_is_any) {
78                         if ($pkg2_is_any and $substvar_strips_binNMU) {
79                                 # (b1) any -> any (= ${source:Version})
80                                 tag "not-binnmuable-any-depends-any", "$pkg1 -> $pkg2";
81                         } elsif (not $pkg2_is_any and not $substvar_strips_binNMU) {
82                                 # (b2) any -> all (= ${Source-Version}) [or b:V]
83                                 tag "not-binnmuable-any-depends-all", "$pkg1 -> $pkg2";
84                         }
85                 } elsif ($pkg2_is_any) {
86                         # (b3) all -> any (= ${either-of-them})
87                         tag "not-binnmuable-all-depends-any", "$pkg1 -> $pkg2";
88                 }
89         }
90 }
91
92 }
93
94 1;
95
96 # vim: syntax=perl sw=4 ts=4 noet shiftround