Added lots more modules from lintian. Maemian appears to work.
[maemian] / 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 Maemian::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 my $info = shift;
46
47 my $binpkgs = $info->binaries;
48
49 my @dep_fields = qw(depends pre-depends recommends suggests conflicts replaces);
50
51 foreach (keys %$binpkgs) {
52         my ($pkg1, $pkg1_is_any, $pkg2, $pkg2_is_any, $substvar_strips_binNMU);
53
54         $pkg1 = $_;
55         $pkg1_is_any = ($info->binary_field($pkg1, 'architecture') ne 'all');
56
57         foreach my $field (@dep_fields) {
58                 next unless $info->binary_field($pkg1, $field);
59                 if ($info->binary_field($pkg1, $field) =~ m/\${Source-Version}/) {
60                         tag "substvar-source-version-is-deprecated", $pkg1;
61                 }
62         }
63
64         foreach (split(m/,/, $info->binary_field($pkg1, 'pre-depends').", ".
65                        $info->binary_field($pkg1, '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                 # We can't test dependencies on packages whose names are
72                 # formed via substvars expanded during the build.  Assume
73                 # those maintainers know what they're doing.
74                 if (not $info->binary_field($pkg2, 'architecture')) {
75                         tag "version-substvar-for-external-package", "$pkg1 -> $pkg2"
76                                 unless ($pkg2 =~ /\$\{\S+\}/);
77                         next;
78                 }
79                 $pkg2_is_any = ($info->binary_field($pkg2, 'architecture') !~ m/^all$/);
80
81                 if ($pkg1_is_any) {
82                         if ($pkg2_is_any and $substvar_strips_binNMU) {
83                                 # (b1) any -> any (= ${source:Version})
84                                 tag "not-binnmuable-any-depends-any", "$pkg1 -> $pkg2";
85                         } elsif (not $pkg2_is_any and not $substvar_strips_binNMU) {
86                                 # (b2) any -> all (= ${Source-Version}) [or b:V]
87                                 tag "not-binnmuable-any-depends-all", "$pkg1 -> $pkg2";
88                         }
89                 } elsif ($pkg2_is_any) {
90                         # (b3) all -> any (= ${either-of-them})
91                         tag "not-binnmuable-all-depends-any", "$pkg1 -> $pkg2";
92                 }
93         }
94 }
95
96 }
97
98 1;
99
100 # Local Variables:
101 # indent-tabs-mode: t
102 # cperl-indent-level: 8
103 # End:
104 # vim: syntax=perl sw=4 ts=4 noet shiftround