Added some code to peer into a data structure in Maemian/Schedule.pm. Also added the
[maemian] / nokia-lintian / checks / control-file
1 # control-file -- lintian check script -*- perl -*-
2 #
3 # Copyright (C) 2004 Marc Brockschmidt
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 package Lintian::control_file;
22 use strict;
23 use lib "$ENV{'LINTIAN_ROOT'}/checks/";
24 use common_data;
25 use Dep;
26 use Util;
27 use Tags;
28
29 sub run {
30
31 my $pkg = shift;
32 my $type = shift;
33
34 if (-l "debfiles/control") {
35     tag "debian-control-file-is-a-symlink", "";
36 }
37
38 # check that control is UTF-8 encoded
39 my $line = file_is_encoded_in_non_utf8("debfiles/control", $type, $pkg);
40 if ($line) {
41     tag "debian-control-file-uses-obsolete-national-encoding", "at line $line"
42 }
43
44 # Check that each field is only used once:
45 my $seen_fields = {};
46 open (CONTROL, '<', "debfiles/control")
47     or fail "Couldn't read debfiles/control: $!";
48 while (<CONTROL>) {
49         s/\s*\n$//;
50         next if /^\#/;
51
52         #Reset seen_fields if we enter a new section:
53         $seen_fields = {} if /^$/;
54
55         #line with field:
56         if (/^(\S+):/) {
57                 my $field = lc ($1);
58                 if ($seen_fields->{$field}) {
59                         tag "debian-control-with-duplicate-fields", "$field: $$seen_fields{$field}, $.";
60                 }
61                 $seen_fields->{$field} = $.;
62                 if ($field =~ /^xs-vcs-/) {
63                         my $base = $field;
64                         $base =~ s/^xs-//;
65                         tag "xs-vcs-header-in-debian-control", "$field"
66                             if $known_source_fields{$base};
67                 }
68         }
69 }
70 close CONTROL;
71
72 my ($header, @binary_controls) = read_dpkg_control("debfiles/control");
73
74 for my $binary_control (@binary_controls) {
75         tag "build-info-in-binary-control-file-section", "Package ".$binary_control->{"package"}
76             if ($binary_control->{"build-depends"} || $binary_control->{"build-depends-indep"} ||
77                 $binary_control->{"build-conflicts"} || $binary_control->{"build-conflicts-indep"});
78 }
79
80 # Make sure that a stronger dependency field doesn't imply any of the elements
81 # of a weaker dependency field.  dpkg-gencontrol will fix this up for us, but
82 # we want to check the source package since dpkg-gencontrol may silently "fix"
83 # something that's a more subtle bug.
84 #
85 # Also check if a package declares a simple dependency on itself, since
86 # similarly dpkg-gencontrol will clean this up for us but it may be a sign of
87 # another problem.
88 my @dep_fields = qw(pre-depends depends recommends suggests);
89 for my $control (@binary_controls) {
90         for my $strong (0 .. ($#dep_fields - 1)) {
91                 next unless $control->{$dep_fields[$strong]};
92                 my $parsed = Dep::parse ($control->{$dep_fields[$strong]});
93                 tag "package-depends-on-itself", $control->{package}, $dep_fields[$strong]
94                     if Dep::implies($parsed, Dep::parse($control->{package}));
95                 for my $weak (($strong + 1) .. $#dep_fields) {
96                         next unless $control->{$dep_fields[$weak]};
97                         for my $dependency (split /\s*,\s*/, $control->{$dep_fields[$weak]}) {
98                                 next unless $dependency;
99                                 tag "stronger-dependency-implies-weaker", $control->{package}, "$dep_fields[$strong] -> $dep_fields[$weak]", $dependency
100                                     if Dep::implies($parsed, Dep::parse($dependency));
101                         }
102                 }
103         }
104 }
105
106 # Check that every package is in the same archive category, except that
107 # sources in main can deliver both main and contrib packages.  The source
108 # package may or may not have a section specified; if it doesn't, derive the
109 # expected archive category from the first binary package by leaving $category
110 # undefined until parsing the first binary section.  Missing sections will be
111 # caught by other checks.
112 my $category;
113 if ($header->{'section'}) {
114         if ($header->{'section'} =~ m%^([^/]+)/%) {
115                 $category = $1;
116         } else {
117                 $category = '';
118         }
119 } else {
120         tag "no-section-field-for-source", "";
121 }
122 for my $binary_control (@binary_controls) {
123         next unless $binary_control->{'section'};
124         if (!defined ($category)) {
125                 if ($binary_control->{'section'} =~ m%^([^/]+)/%) {
126                         $category = ($1 eq 'contrib') ? '' : $1;
127                 } else {
128                         $category = '';
129                 }
130                 next;
131         }
132         tag "section-category-mismatch", "Package " . $binary_control->{'package'}
133                 if ($category && $binary_control->{'section'} !~ m%^$category/%);
134         tag "section-category-mismatch", "Package " . $binary_control->{'package'}
135                 if (!$category && $binary_control->{'section'} =~ m%^([^/]+)/% && $1 ne 'contrib');
136 }
137
138 }
139
140 1;
141
142 # Local Variables:
143 # indent-tabs-mode: t
144 # cperl-indent-level: 8
145 # End:
146 # vim: syntax=perl sw=4 ts=4 noet shiftround