]> git.donarmstrong.com Git - wannabuild.git/blob - lib/WB/QD.pm
fix binNMU detection of installed packages, and fix testsuite and logging
[wannabuild.git] / lib / WB / QD.pm
1 package WB::QD;
2
3 use strict;
4 use IO::Uncompress::AnyInflate qw(anyinflate);
5 use Dpkg::Version qw(vercmp);
6 use Data::Dumper;
7
8 sub readsourcebins {
9     my $arch = shift;
10     my $pasfile = shift;
11     my $SRC = shift;
12     my $BIN = shift;
13     my $binary = {};
14
15     my $pas = {};
16     local($/) = "\n";
17     open(PAS, '<', $pasfile);
18     while(<PAS>) {
19         chomp;
20         s,\s*#.*,,;
21         next unless $_;
22         my ($p, $c) = split(/:\s*/);
23         $pas->{$p} = { arch => [ split(/\s+/, $c) ], mode => substr($c, 0, 1) ne '!' };
24     }
25     close PAS;
26
27     my $srcs = {};
28     local($/) = ""; # read in paragraph mode
29
30     foreach my $s (@$SRC) {
31         my $S = new IO::Uncompress::AnyInflate($s) || return "WB::QD::SRC can't open $s";
32         while(<$S>) {
33             my $p={};
34             /^Package:\s*(\S+)$/mi and $p->{'name'} = $1;
35             /^Version:\s*(\S+)$/mi and $p->{'version'} = $1;
36             /^Binary:\s*(.*)$/mi and $p->{'binary'} = $1;
37             /^Architecture:\s*(.+)$/mi and $p->{'arch'} = $1;
38             /^Priority:\s*(\S+)$/mi and $p->{'priority'} = $1;
39             /^Section:\s*(\S+)$/mi and $p->{'section'} = $1;
40             /^Build-Depends:\s*(.*)$/mi and $p->{'depends'} = $1;
41             /^Build-Conflicts:\s*(.*)$/mi and $p->{'conflicts'} = $1;
42
43             next unless $p->{'name'} and $p->{'version'};
44             next if $p->{'arch'} eq 'all';
45             # TODO: respect the architecture - or not / we already respect it via P-a-s
46             delete $p->{'arch'};
47
48             # ignore if package already exists with higher version
49             if ($srcs->{$p->{'name'}}) {
50                 next if (vercmp($srcs->{$p->{'name'}}->{'version'}, $p->{'version'}) > 0);
51             }
52             my @a = split(/,? /, $p->{'binary'}) if $p->{'binary'};
53             $p->{'binary'} = \@a;
54             $srcs->{$p->{'name'}} = $p;
55         }
56         close $S;
57     }
58
59     foreach my $p (@$BIN) {
60         my $P = new IO::Uncompress::AnyInflate($p) || return "WB::QD::PKGS can't open $p";
61         while(<$P>) {
62             my $p;
63             /^Version:\s*(\S+)$/mi and $p->{'version'} = $1;
64             /^Version:\s*(\S+)\+b([0-9]+)$/mi and $p->{'version'} = $1 and $p->{'binnmu'} = $2;
65             /^Architecture:\s*(\S+)$/mi and $p->{'arch'} = $1;
66             /^Package:\s*(\S+)$/mi and $p->{'binary'} = $1;
67             /^Package:\s*(\S+)$/mi and $p->{'source'} = $1;
68             /^Source:\s*(\S+)$/mi and $p->{'source'} = $1;
69             /^Source:\s*(\S+)\s+\((\S+)\)$/mi and $p->{'source'} = $1 and $p->{'version'} = $2;
70
71             next unless $p->{'arch'} eq 'all' || $p->{'arch'} eq ${arch};
72             $binary->{$p->{'binary'}} = { 'version' => $p->{'version'}, 'arch' => $p->{'arch'}} unless $binary->{$p->{'binary'}} and vercmp($binary->{$p->{'binary'}}->{'version'}, $p->{'version'}) < 0;
73
74             #next if $pas->{$p->{'binary'}} && pasignore($pas->{$p->{'binary'}}, $arch);
75             next if $p->{'arch'} eq 'all';
76             next unless $srcs->{$p->{'source'}};
77             $srcs->{$p->{'source'}}->{'compiled'} = 1;
78             next unless $srcs->{$p->{'source'}}->{'version'} eq $p->{'version'};
79             $srcs->{$p->{'source'}}->{'installed'} = 1;
80             next unless $p->{'binnmu'};
81             next if ($srcs->{$p->{'source'}}->{'binnmu'}) && ($srcs->{$p->{'source'}}->{'binnmu'} > $p->{'binnmu'});
82             $srcs->{$p->{'source'}}->{'binnmu'} = $p->{'binnmu'};
83         }
84         close $P;
85     }
86
87     SRCS:
88     for my $k (keys %$srcs) {
89         if ($srcs->{$k}->{'installed'}) {
90             $srcs->{$k}->{'status'} = 'installed';
91             delete $srcs->{$k}->{'installed'};
92         } elsif ($srcs->{$k}->{'compiled'}) {
93             $srcs->{$k}->{'status'} = 'out-of-date';
94         } else {
95             $srcs->{$k}->{'status'} = 'uncompiled';
96         }
97         delete $srcs->{$k}->{'compiled'};
98         $srcs->{$k}->{'status'} = 'installed' if $srcs->{$k}->{'arch'} && $srcs->{$k}->{'arch'} eq 'all';
99
100         #my $p = $pas->{$k};
101         #$p ||= $pas->{'%'.$k};
102         #$srcs->{$k}->{'status'} = 'not-for-us' if pasignore($p, $arch);
103         if (pasignore($pas->{'%'.$k}, $arch)) {
104             $srcs->{$k}->{'status'} = 'not-for-us';
105             next;
106         }
107         for my $bin (@{$srcs->{$k}->{'binary'}}) {
108             next if pasignore($pas->{$bin}, $arch);
109             next if $binary->{$bin} and $binary->{$bin}->{'arch'} eq 'all';
110             next SRCS;
111         }
112         $srcs->{$k}->{'status'} = 'not-for-us';
113     }
114     $srcs->{'_binary'} = $binary;
115     local($/) = "\n";
116
117     return \$srcs;
118 }
119
120 sub pasignore {
121     my $p = shift;
122     my $arch = shift;
123     if ($p && $p->{'mode'}) {
124         return 1 unless grep { $_ eq $arch } @{$p->{'arch'}};
125     }
126     if ($p && not $p->{'mode'}) {
127         return 1 if grep /^!$arch$/, @{$p->{'arch'}};
128     }
129     return 0;
130 }
131
132 1;