Added some code to peer into a data structure in Maemian/Schedule.pm. Also added the
[maemian] / nokia-lintian / checks / watch-file
1 # watch-file -- lintian check script -*- perl -*-
2 #
3 # Copyright (C) 2008 Patrick Schoenfeld
4 # Copyright (C) 2008 Russ Allbery
5 #
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.
10 #
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.
15 #
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,
20 # MA 02110-1301, USA.
21
22 package Lintian::watch_file;
23 use strict;
24
25 use Lintian::Collect;
26 use Tags;
27
28 sub run {
29
30 my $pkg = shift;
31 my $type = shift;
32 my $info = shift;
33
34 if (! -f "debfiles/watch") {
35     tag 'debian-watch-file-is-missing' unless ($info->native);
36     return;
37 }
38
39 # Perform the other checks even if it is a native package
40 tag 'debian-watch-file-in-native-package' if ($info->native);
41
42 # Check if the Debian version contains anything that resembles a repackaged
43 # source package sign, for fine grained version mangling check
44 my $version = $info->field('version');
45 my $repack;
46 if ($version =~ /(dfsg|debian|ds)/) {
47     $repack = $1;
48 }
49
50 # Gather information from the watch file and look for problems we can
51 # diagnose on the first time through.
52 open(WATCH, '<', 'debfiles/watch') or fail("cannot open watch file: $!");
53 local $_;
54 my ($watchver, $mangle, $dmangle);
55 while (<WATCH>) {
56     next if /^\s*\#/;
57     next if /^\s*$/;
58     s/^\s*//;
59     if (s/(?<!\\)\\$//) {
60         # This is caught by uscan.
61         last if eof(WATCH);
62         $_ .= <WATCH>;
63     }
64
65     if (/^version\s*=\s*(\d+)(\s|\Z)/) {
66         if (defined $watchver) {
67             tag 'debian-watch-file-declares-multiple-versions', "line $.";
68         }
69         $watchver = $1;
70         if ($watchver ne '2' and $watchver ne '3') {
71             tag 'debian-watch-file-unknown-version', $watchver;
72         }
73     } else {
74         unless (defined($watchver)) {
75             tag 'debian-watch-file-missing-version';
76             $watchver = 1;
77         }
78         while (s/\\\s*$//) {
79             $_ .= <WATCH>;
80         }
81         chomp;
82         my ($opts, @opts);
83         if (s/^opt(ion)?s=\"([^\"]+)\"\s+// || s/^opt(ion)?s=(\S+)\s+//) {
84             $opts = $2;
85             @opts = split(',', $opts);
86             if (defined $repack) {
87                 for (@opts) {
88                     $mangle = 1 if /^[ud]versionmangle.*=.*($repack)/;
89                     $dmangle = 1 if /^dversionmangle.*=.*($repack)/;
90                 }
91             }
92         }
93         if (m%qa\.debian\.org/watch/sf\.php\?%) {
94             tag 'debian-watch-file-uses-deprecated-sf-redirector-method';
95         }
96     }
97 }
98 close WATCH;
99
100 # If the version of the package contains dfsg, assume that it needs to be
101 # mangled to get reasonable matches with upstream.
102 if ($repack and not $mangle) {
103     tag 'debian-watch-file-should-mangle-version';
104 }
105 if ($repack and $mangle and not $dmangle) {
106     tag 'debian-watch-file-should-dversionmangle-not-uversionmangle';
107 }
108
109 }
110
111 1;
112
113 # Local Variables:
114 # indent-tabs-mode: nil
115 # cperl-indent-level: 4
116 # End:
117 # vim: syntax=perl sw=4 sts=4 ts=4 et shiftround