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