]> git.donarmstrong.com Git - wannabuild.git/blob - lib/WB/QD.pm
01eea54354c1cb19862ff1543716447981462e3a
[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 (); # import nothing
6 if ( defined $Dpkg::Version::VERSION ) {
7     *vercmp = \&Dpkg::Version::version_compare;
8 } else {
9     *vercmp = \&Dpkg::Version::vercmp;
10 }
11 use Dpkg::Arch qw(debarch_is);
12 use Data::Dumper;
13
14 sub readsourcebins {
15     my $arch = shift;
16     my $pasfile = shift;
17     my $SRC = shift;
18     my $BIN = shift;
19     my $binary = {};
20
21     my $pas = {};
22     local($/) = "\n";
23     open(my $pasf, '<', $pasfile);
24     while(<$pasf>) {
25         chomp;
26         s,\s*#.*,,;
27         next unless $_;
28         my ($p, $c) = split(/:\s*/);
29         $pas->{$p} = { arch => [ split(/\s+/, $c) ], mode => substr($c, 0, 1) ne '!' };
30     }
31     close $pasf;
32
33     my $srcs = {};
34     local($/) = ""; # read in paragraph mode
35
36     foreach my $s (@$SRC) {
37         my $S = new IO::Uncompress::AnyInflate($s) || return "WB::QD::SRC can't open $s";
38         while(<$S>) {
39             my $p={};
40             /^Package:\s*(\S+)$/mi and $p->{'name'} = $1;
41             /^Version:\s*(\S+)$/mi and $p->{'version'} = $1;
42             /^Binary:\s*(.*)$/mi and $p->{'binary'} = $1;
43             /^Architecture:\s*(.+)$/mi and $p->{'arch'} = $1;
44             /^Priority:\s*(\S+)$/mi and $p->{'priority'} = $1;
45             /^Section:\s*(\S+)$/mi and $p->{'section'} = $1;
46             /^Build-Depends:\s*(.*)$/mi and $p->{'depends'} = $1;
47             /^Build-Conflicts:\s*(.*)$/mi and $p->{'conflicts'} = $1;
48
49             next unless $p->{'name'} and $p->{'version'};
50             next if $p->{'arch'} eq 'all';
51             foreach my $tarch (split(/\s+/, $p->{'arch'})) {
52                 $p->{'for-us'} = 1 if debarch_is($arch, $tarch);
53             }
54             delete $p->{'arch'};
55
56             # ignore if package already exists with higher version
57             if ($srcs->{$p->{'name'}}) {
58                 next if (vercmp($srcs->{$p->{'name'}}->{'version'}, $p->{'version'}) > 0);
59             }
60             if ($p->{'binary'}) {
61                 $p->{'binary'} = [ split(/,? /, $p->{'binary'}) ];
62             }
63             $srcs->{$p->{'name'}} = $p;
64         }
65         close $S;
66     }
67
68     foreach my $p (@$BIN) {
69         my $P = new IO::Uncompress::AnyInflate($p) || return "WB::QD::PKGS can't open $p";
70         while(<$P>) {
71             my $p;
72             /^Version:\s*(\S+)$/mi and $p->{'version'} = $1;
73             /^Version:\s*(\S+)\+b([0-9]+)$/mi and $p->{'version'} = $1 and $p->{'binnmu'} = $2;
74             /^Architecture:\s*(\S+)$/mi and $p->{'arch'} = $1;
75             /^Package:\s*(\S+)$/mi and $p->{'binary'} = $1;
76             /^Package:\s*(\S+)$/mi and $p->{'source'} = $1;
77             /^Source:\s*(\S+)$/mi and $p->{'source'} = $1;
78             /^Source:\s*(\S+)\s+\((\S+)\)$/mi and $p->{'source'} = $1 and $p->{'version'} = $2;
79
80             # consider packages as non-existant if it's all but outdated
81             next if $p->{'arch'} eq 'all' && $srcs->{$p->{'source'}} && $srcs->{$p->{'source'}}->{'version'} && vercmp($srcs->{$p->{'source'}}->{'version'}, $p->{'version'}) > 0;
82             next unless $p->{'arch'} eq 'all' || $p->{'arch'} eq ${arch};
83             $binary->{$p->{'binary'}} = { 'version' => $p->{'version'}, 'arch' => $p->{'arch'}} unless $binary->{$p->{'binary'}} and vercmp($binary->{$p->{'binary'}}->{'version'}, $p->{'version'}) < 0;
84
85             #next if $pas->{$p->{'binary'}} && pasignore($pas->{$p->{'binary'}}, $arch);
86             next if $p->{'arch'} eq 'all';
87             next unless $srcs->{$p->{'source'}};
88             $srcs->{$p->{'source'}}->{'compiled'} = 1;
89             next unless $srcs->{$p->{'source'}}->{'version'} eq $p->{'version'};
90             $srcs->{$p->{'source'}}->{'installed'} = 1;
91             next unless $p->{'binnmu'};
92             next if ($srcs->{$p->{'source'}}->{'binnmu'}) && ($srcs->{$p->{'source'}}->{'binnmu'} > $p->{'binnmu'});
93             $srcs->{$p->{'source'}}->{'binnmu'} = $p->{'binnmu'};
94         }
95         close $P;
96     }
97
98     SRCS:
99     for my $k (keys %$srcs) {
100         if ($srcs->{$k}->{'installed'}) {
101             $srcs->{$k}->{'status'} = 'installed';
102             delete $srcs->{$k}->{'installed'};
103         } elsif ($srcs->{$k}->{'compiled'}) {
104             $srcs->{$k}->{'status'} = 'out-of-date';
105         } else {
106             $srcs->{$k}->{'status'} = 'uncompiled';
107         }
108         delete $srcs->{$k}->{'compiled'};
109         $srcs->{$k}->{'status'} = 'installed' if $srcs->{$k}->{'arch'} && $srcs->{$k}->{'arch'} eq 'all';
110         
111         if (!$srcs->{$k}->{'for-us'} && $srcs->{$k}->{'status'} ne 'installed') {
112             $srcs->{$k}->{'status'} = 'auto-not-for-us';
113         }
114         delete $srcs->{$k}->{'for-us'};
115
116         #my $p = $pas->{$k};
117         #$p ||= $pas->{'%'.$k};
118         #$srcs->{$k}->{'status'} = 'not-for-us' if pasignore($p, $arch);
119         if (pasignore($pas->{'%'.$k}, $arch)) {
120             $srcs->{$k}->{'status'} = 'not-for-us';
121             next;
122         }
123         for my $bin (@{$srcs->{$k}->{'binary'}}) {
124             $srcs->{$k}->{'pas'} = 1 if pasignore($pas->{$bin}, $arch);
125             next if pasignore($pas->{$bin}, $arch);
126             next if $binary->{$bin} and $binary->{$bin}->{'arch'} eq 'all';
127             next SRCS;
128         }
129         if ($srcs->{$k}->{'pas'}) {
130             $srcs->{$k}->{'status'} = 'not-for-us';
131             $srcs->{$k}->{'notes'} = 'packages-arch-specific';
132         } else {
133             $srcs->{$k}->{'status'} = 'auto-not-for-us';
134             $srcs->{$k}->{'notes'} = 'overwritten-by-arch-all';
135         }
136         delete $srcs->{$k}->{'pas'};
137     }
138     $srcs->{'_binary'} = $binary;
139     local($/) = "\n";
140
141     return \$srcs;
142 }
143
144 sub pasignore {
145     my $p = shift;
146     my $arch = shift;
147     if ($p && $p->{'mode'}) {
148         return 1 unless grep { $_ eq $arch } @{$p->{'arch'}};
149     }
150     if ($p && not $p->{'mode'}) {
151         return 1 if grep /^!$arch$/, @{$p->{'arch'}};
152     }
153     return 0;
154 }
155
156 1;