1 # patch-systems -- lintian check script -*- perl -*-
3 # Copyright (C) 2007 Marc Brockschmidt
4 # Copyright (C) 2008 Raphael Hertzog
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, you can find it on the World Wide
18 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
19 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
22 package Lintian::patch_systems;
24 use lib "$ENV{'LINTIAN_ROOT'}/checks/";
31 my ($pkg, $type) = @_;
33 unless (-d "fields") {
34 fail("directory in lintian laboratory for $type package $pkg missing: fields");
37 #Some (cruft) checks are valid for every patch system, so we need to record that:
38 my $uses_patch_system = 0;
40 #Get build deps so we can decide which build system the maintainer
43 if (open(IN, '<', "fields/build-depends")) {
45 chomp($build_deps .= <IN>);
48 if (open(IN, '<', "fields/build-depends-indep")) {
50 $build_deps .= ", " if $build_deps;
51 chomp($build_deps .= <IN>);
54 $build_deps = Dep::parse($build_deps);
55 # Get source package format
57 if (open(IN, '<', "fields/format")) {
59 chomp($format .= <IN>);
62 my $quilt_format = ($format =~ /3\.\d+ \(quilt\)/) ? 1 : 0;
65 if (Dep::implies($build_deps, Dep::parse("dpatch"))) {
67 #check for a debian/patches file:
68 if (! -r "debfiles/patches/00list") {
69 tag "dpatch-build-dep-but-no-patch-list", $pkg;
71 my $list_uses_cpp = 0;
72 if (open(OPTS, '<', "debfiles/patches/00options")) {
74 if (/DPATCH_OPTION_CPP=1/) {
81 foreach my $listfile (glob("debfiles/patches/00list*")) {
83 if (open(IN, '<', "$listfile")) {
86 next if (/^\#/); #ignore comments or CPP directive
87 s%//.*%% if $list_uses_cpp; # remove C++ style comments
88 if ($list_uses_cpp && m%/\*%) {
89 # remove C style comments
90 $_ .= <IN> while($_ !~ m%\*/%);
93 next if (/^\s*$/); #ignore blank lines
94 push @patches, split(' ', $_);
100 foreach my $patch_file (@patches) {
101 $patch_file .= ".dpatch" if -e "debfiles/patches/$patch_file.dpatch"
102 and not -e "debfiles/patches/$patch_file";
103 if (! -r "debfiles/patches/$patch_file") {
104 tag "dpatch-index-references-non-existent-patch", $patch_file;
107 if (open(PATCH_FILE, '<', "debfiles/patches/$patch_file")) {
109 while (<PATCH_FILE>) {
110 #stop if something looking like a patch starts:
112 #note comment if we find a proper one
113 $has_comment = 1 if (/^\#+\s*DP:\s*(.*)$/ && $1 !~ /^no description\.?$/i)
116 unless ($has_comment) {
117 tag "dpatch-missing-description", $patch_file;
120 check_patch($patch_file);
127 if (Dep::implies($build_deps, Dep::parse("quilt")) or $quilt_format) {
128 $uses_patch_system++;
129 #check for a debian/patches file:
130 if (! -r "debfiles/patches/series") {
131 tag "quilt-build-dep-but-no-series-file", $pkg unless $quilt_format;
133 if (open(IN, '<', "debfiles/patches/series")) {
137 chomp; s/^\s+//; s/\s+$//; # Strip leading/trailing spaces
138 s/(^|\s+)#.*$//; # Strip comment
140 if (/^(\S+)\s+(\S.*)$/) {
149 if (scalar(@badopts)) {
150 tag "quilt-patch-with-non-standard-options", @badopts;
154 foreach my $patch_file (@patches) {
155 if (! -r "debfiles/patches/$patch_file") {
156 tag "quilt-series-references-non-existent-patch", $patch_file;
159 check_patch($patch_file);
164 if (-r "debfiles/patches/series") {
165 # 3.0 (quilt) sources don't need quilt as dpkg-source will do the work
166 tag "quilt-series-but-no-build-dep" unless $quilt_format;
171 #----- general cruft checking:
172 if ($uses_patch_system) {
173 if ($uses_patch_system > 1) {
174 tag "more-than-one-patch-system";
177 open(STAT, '<', "diffstat") or fail("cannot open diffstat file: $!");
179 my ($file) = (m,^\s+(.*?)\s+\|,)
180 or fail("syntax error in diffstat file: $_");
182 if ($file !~ /^debian/) {
183 tag "patch-system-but-direct-changes-in-diff", $file;
186 close (STAT) or fail("error reading diffstat file: $!");
190 # Checks on patches common to all build systems
192 my $patch_file = shift;
193 open(DIFFSTAT, "-|", "diffstat -p0 -l debfiles/patches/$patch_file")
194 or fail("can't fork diffstat");
197 if (m|^(\./)?debian/| or m|^(\./)?[^/]+/debian/|) {
198 tag "patch-modifying-debian-files", $patch_file, $_;
201 close(DIFFSTAT) or fail("cannot close pipe to diffstat on $patch_file: $!");
207 # indent-tabs-mode: t
208 # cperl-indent-level: 8
210 # vim: syntax=perl sw=4 ts=4 noet shiftround