File: check-deps

package info (click to toggle)
request-tracker3.6 3.6.1-4+etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 9,028 kB
  • ctags: 1,371
  • sloc: perl: 27,270; sh: 671; makefile: 327
file content (119 lines) | stat: -rw-r--r-- 2,673 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#! /usr/bin/perl
#
# check-deps -- verify that debian/deps matches the output from
#   rt-test-dependencies

# Return codes:
#   0 = okay
#   1 = module in debian/deps not required by RT
#   2 = version specified in debian/deps too low or unspecified
#   4 = module required by RT absent from debian/deps
#
# These are ORed together. Suggest aborting package build if check-deps
# returns 2 or more.

use strict;
use warnings;

my %test;

sub packageName {
    $_ = shift;
    s/^/lib/;
    s/$/-perl/;
    s/::/-/g;
    lc;
}

sub verHigher {
    return $_[0] > $_[1];
}

sub check {
    my ($pkg, $ver) = @_;
    print "Checking $pkg".($ver?" ($ver)":''). " ... ";
    if (defined $test{$pkg}) {
	$_ = $test{$pkg};
	delete $test{$pkg};
	if (defined $_->{'version'}) {
	    my $needs = "needs >= $_->{'version'} ";
	    if (!defined $ver) {
		print $needs. "but we don't version !\n"; return 2;
	    } elsif (verHigher($_->{'version'}, $ver)) {
		print $needs. "but we say $ver !\n"; return 2
	    } else {
		print "okay\n"; return 0;
	    }
	} else {
	    print "okay\n"; return 0;
	}
    } else {
	print "not required (?)\n"; return 1;
    }
}

sub depline {
    my $ret = 0;
    $_ = shift;
    return 0 if /^\w+:\w+$/; # perllib:Depends etc.
    my ($pkg, $ver);
    if (/^([^\s#]+)(\s+\((.*)\))?/) {
	($pkg, $ver) = ($1, $3);
	$ver =~ s/>=\s+// if defined $ver;
    }
    if (/#\s+(=)\s+(\S*)(\s+\((.*)\))?\s*/) {
	my ($op, $mod, $xver) = ($1, $2, $4);
	# print "Override ($op) ($mod) ". ($xver?$xver:'') . "\n";
	$ver = $xver if (defined $xver);
	# Overrides (=) and extras (+)
	my @mods = split /,/, $mod;
	for (@mods) {
	    $ret |= check(packageName($_), $ver);
	}
	return 0;
    }
    return 0 unless $pkg;
    $ret |= check($pkg, $ver);
    return $ret;
}

my @components = qw(mysql postgresql modperl1);

my $cmdline = 'perl sbin/rt-test-dependencies ' .
    (join ' ', map({"--with-".$_} @components))
  || die "Can't run rt-test-dependencies";

open(TEST, $cmdline."|");

while (<TEST>) {
    if (/\s+(\S+)\s+([\d.]+)?\.\.\.(\S+)/) {
	local %_;
	($_{'module'}, $_{'version'}, $_{'result'}) = ($1, $2, $3);
	my $pkg = packageName($_{'module'});
#	print "($pkg) ($module) (" . ($version?$version:'') . ") ($result)\n";
	$test{$pkg} = \%_;
    }
}

close TEST;

my $ret;

my @depfiles = qw!debian/deps debian/rt3.6-clients.deps!;
my $depfile;
 
foreach $depfile (@depfiles) {
    open(DEPS, $depfile) || die "Can't open $depfile";
    while(<DEPS>) {
	$ret |= depline($_);
	
    }
}

while ((my ($k, $ref)) = each %test) {
    $ret |= 1;
    print "Need $ref->{'module'} -- ".
      $k.($ref->{'version'} ? " (>= $ref->{'version'})" : '')." !\n";
}

exit $ret;