1 # control-file -- lintian check script -*- perl -*-
3 # Copyright (C) 2004 Marc Brockschmidt
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.
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.
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,
21 package Lintian::control_file;
23 use lib "$ENV{'LINTIAN_ROOT'}/checks/";
34 if (-l "debfiles/control") {
35 tag "debian-control-file-is-a-symlink", "";
38 # check that control is UTF-8 encoded
39 my $line = file_is_encoded_in_non_utf8("debfiles/control", $type, $pkg);
41 tag "debian-control-file-uses-obsolete-national-encoding", "at line $line"
44 # Check that each field is only used once:
46 open (CONTROL, '<', "debfiles/control")
47 or fail "Couldn't read debfiles/control: $!";
52 #Reset seen_fields if we enter a new section:
53 $seen_fields = {} if /^$/;
58 if ($seen_fields->{$field}) {
59 tag "debian-control-with-duplicate-fields", "$field: $$seen_fields{$field}, $.";
61 $seen_fields->{$field} = $.;
62 if ($field =~ /^xs-vcs-/) {
65 tag "xs-vcs-header-in-debian-control", "$field"
66 if $known_source_fields{$base};
72 my ($header, @binary_controls) = read_dpkg_control("debfiles/control");
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"});
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.
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
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));
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.
113 if ($header->{'section'}) {
114 if ($header->{'section'} =~ m%^([^/]+)/%) {
120 tag "no-section-field-for-source", "";
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;
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');
143 # indent-tabs-mode: t
144 # cperl-indent-level: 8
146 # vim: syntax=perl sw=4 ts=4 noet shiftround