/usr/lib/obs/server/BSSched/BuildJob/Channel.pm is in obs-server 2.7.1-10.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see the file COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
package BSSched::BuildJob::Channel;
use strict;
use warnings;
use Digest::MD5 ();
use BSUtil;
use BSSched::BuildJob;
use BSSched::BuildResult;
=head1 NAME
BSSched::BuildJob::Channel - A Class to handle Channel builds
=head1 SYNOPSIS
my $h = BSSched::BuildJob::Channel->new()
$h->check();
$h->expand();
$h->rebuild();
=cut
=head2 new - TODO: add summary
TODO: add description
=cut
sub new {
return bless({}, $_[0]);
}
=head2 expand - TODO: add summary
TODO: add description
=cut
sub expand {
return 1, splice(@_, 3);
}
=head2 check - check if a patchinfo needs to be rebuilt
TODO: add description
=cut
sub check {
my ($self, $ctx, $packid, $pdata, $info) = @_;
my $gctx = $ctx->{'gctx'};
my $myarch = $gctx->{'arch'};
my $projid = $ctx->{'project'};
my $repoid = $ctx->{'repository'};
my $repo = $ctx->{'repo'};
my %repoarchs = map {$_ => 1} @{$repo->{'arch'} || []};
my $channel = $pdata->{'channel'};
my $projpacks = $gctx->{'projpacks'};
my $proj = $projpacks->{$projid} || {};
my $reporoot = $gctx->{'reporoot'};
# do the channel filtering, same project but different repositories
# first build a releasetarget -> repo map
my %proj2repo;
for my $arepo (@{$projpacks->{$projid}->{'repository'} || []}) {
next unless grep {$_ eq $myarch} @{$arepo->{'arch'} || []};
$proj2repo{"$projid/$arepo->{'name'}"}->{$arepo->{'name'}} = 1;
for my $rt (@{$arepo->{'releasetarget'} || []}) {
my $rtprojid = $rt->{'project'};
my $rtrepoid = $rt->{'repository'};
$proj2repo{"$rtprojid/$rtrepoid"}->{$arepo->{'name'}} = 1;
$proj2repo{$rtprojid}->{$arepo->{'name'}} = 1;
}
}
my $forme = {};
if ($channel->{'target'}) {
$forme = undef;
for (@{$channel->{'target'}}) {
if (!$_->{'project'}) {
$forme = $_ if $_->{'repository'} && $repoid eq $_->{'repository'};
} else {
if ($_->{'repository'}) {
$forme = $_ if $proj2repo{"$_->{'project'}/$_->{'repository'}"};
} else {
$forme = $_ if $proj2repo{$_->{'project'}};
}
}
}
}
return ('excluded', 'not target of channel') if !$forme;
# now create filter
my %arepos;
my %filter;
my %packagefilter;
for my $binaries (@{$channel->{'binaries'} || []}) {
my $defprojid = $binaries->{'project'};
my $defrepoid = $binaries->{'repository'};
my $defarch = $binaries->{'arch'};
for my $binary (@{$binaries->{'binary'} || []}) {
next unless $binary->{'name'};
my $bi = $binary;
my $arch = $bi->{'arch'} || $defarch || '';
if ($arch && !$repoarchs{$arch}) {
# not in repo, go for the import!
$bi = { %$binary, 'importedfrom' => $arch };
$arch = $myarch;
}
next unless !$arch || $arch eq $myarch;
my $aprojid = $bi->{'project'} || $defprojid || $projid;
next unless $aprojid;
my $arepoid = $bi->{'repository'} || $defrepoid || '';
my $rtkey = $arepoid ? "$aprojid/$arepoid" : $aprojid;
next unless $proj2repo{$rtkey};
for my $arepoid (keys %{$proj2repo{$rtkey}}) {
$arepos{$arepoid} = 1;
push @{$filter{"$arepoid/$bi->{'name'}"}}, $bi;
}
if ($bi->{'package'}) {
push @{$packagefilter{"$arepoid/$bi->{'package'}"}}, $bi;
}
}
}
#print Dumper(\%filter);
# find packages (same code as in checkpatchinfo)
my $pdatas = $proj->{'package'} || {};
my @apackids = grep {!$pdatas->{$_}->{'aggregatelist'} && !$pdatas->{$_}->{'patchinfo'}} sort keys %$pdatas;
# go through the repos and check the binaries
my @new_meta = ($pdata->{'verifymd5'} || $pdata->{'srcmd5'})." $packid";
my @blocked;
my @broken;
my %collected;
my @channelbins;
for my $arepoid (sort keys %arepos) {
my $aprp = "$projid/$arepoid";
my $ps = BSUtil::retrieve("$reporoot/$aprp/$myarch/:packstatus", 1);
$ps = ($ps || {})->{'packstatus'} || {};
# find which projects go into this repo
my %aprojids;
for my $aprojid (keys %proj2repo) {
$aprojids{$aprojid} = 1 if $proj2repo{$aprojid}->{$arepoid};
}
my $gbininfo = BSSched::BuildResult::read_gbininfo("$reporoot/$aprp/$myarch");
for my $apackid (@apackids) {
next if $arepoid eq $repoid && $apackid eq $packid;
my $code = $ps->{$apackid} || 'unknown';
if ($code eq 'scheduled' || $code eq 'blocked' || $code eq 'finished' || $code eq 'unknown') {
push @blocked, "$arepoid/$apackid";
next;
}
my $bininfo = $gbininfo->{$apackid} || {};
my @sbins;
my %usedsrc;
# this messy code tries to guess the "final" package name for
# maintenance incidents.
my $lapackid; #linked package id
my $linked = ($pdatas->{$apackid} || {})->{'linked'};
if (!@{$linked || []}) {
$lapackid = $apackid;
if (($proj->{'kind'} || '') eq 'maintenance_incident' && (($pdatas->{$apackid} || {})->{'error'} || '') eq 'disabled') {
# workaround for src server not sending linked data for disabled packages
$lapackid =~ s/\.[^\.]+$//;
}
} elsif ($linked->[0]->{'project'} ne $projid) {
$lapackid = $linked->[0]->{'package'};
} else {
# what a mess! but bug compatible to api...
my ($pin, $pout);
for (@$linked) {
$pout = $_->{'package'};
last if $_->{'project'} ne $projid;
$pin = $pout;
}
$lapackid = $apackid;
if ($pin =~ s/^\Q$pout\E//) {
$lapackid =~ s/\Q$pin\E$//;
}
}
my @pf = @{$packagefilter{"$arepoid/$apackid"} || $packagefilter{"$arepoid/$lapackid"} || []};
my @bins = sort keys %$bininfo;
# put imports last
my @ibins = grep {/^::import::/} @bins;
if (@ibins) {
@bins = grep {!/^::import::/} @bins;
push @bins, @ibins;
}
for my $filename (@bins) {
my $bi = $bininfo->{$filename};
my $n = $bi->{'name'};
next unless $n;
if ($bi->{'arch'} eq 'src' || $bi->{'arch'} eq 'nosrc') {
push @sbins, $bi unless $bininfo->{'.nosourceaccess'};
next;
}
if (@pf) {
for my $f (splice @pf) {
push @pf, $f if $f->{'name'} ne $n || ($f->{'binaryarch'} && $bi->{'arch'} ne $f->{'binaryarch'});
}
}
my $tfilename = $filename;
$tfilename =~ s/^::import::.*?:://;
next if $collected{$tfilename};
next unless $filter{"$arepoid/$n"};
my $found;
my $supportstatus;
my $importedfrom;
for my $f (@{$filter{"$arepoid/$n"}}) {
next if $f->{'importedfrom'} && $filename !~ /^::import::\Q$f->{'importedfrom'}\E::/;
next if $f->{'package'} && $apackid ne $f->{'package'} && $lapackid ne $f->{'package'};
next if $f->{'binaryarch'} && $bi->{'arch'} ne $f->{'binaryarch'};
$supportstatus = $f->{'supportstatus'};
$found = 1;
last;
}
next unless $found;
# oooh, this binary goes into the channel!
$collected{$tfilename} = 1;
$usedsrc{$bi->{'source'}} = 1;
my $m = Digest::MD5::md5_hex($bi->{'id'})." $arepoid/$apackid/$n.$bi->{'arch'}";
push @new_meta, $m;
$bi->{'filename'} = $filename; # work around bug in bininfo generation
push @channelbins, [ $arepoid, $apackid, $bi, $supportstatus ];
}
if (%usedsrc) {
for my $bi (@sbins) {
next unless $usedsrc{$bi->{'name'}};
next if $collected{$bi->{'filename'}};
$collected{$bi->{'filename'}} = 1;
my $m = Digest::MD5::md5_hex($bi->{'id'})." $arepoid/$apackid/$bi->{'name'}.$bi->{'arch'}";
push @new_meta, $m;
push @channelbins, [ $arepoid, $apackid, $bi ];
}
}
for my $f (@pf) {
if ($f->{'binaryarch'}) {
push @broken, "$arepoid/$apackid/$f->{'name'}.$f->{'binaryarch'}";
} else {
push @broken, "$arepoid/$apackid/$f->{'name'}";
}
}
}
}
if (@broken) {
print " - $packid (channel)\n";
print " broken (@broken)\n";
return ('broken', 'missing: '.join(', ', @broken));
}
if (@blocked) {
print " - $packid (channel)\n";
if (@blocked < 11) {
print " blocked (@blocked)\n";
} else {
print " blocked (@blocked[0..9] ...)\n";
}
return ('blocked', join(', ', @blocked));
}
my @meta;
if (open(F, '<', "$reporoot/$projid/$repoid/$myarch/:meta/$packid")) {
@meta = <F>;
close F;
chomp @meta;
}
if (join('\n', @meta) eq join('\n', @new_meta)) {
print " - $packid (channel)\n";
print " nothing changed\n";
return ('done');
}
my @diff = BSSched::BuildJob::diffsortedmd5(\@meta, \@new_meta);
print " - $packid (channel)\n";
print " $_\n" for @diff;
my $new_meta = join('', map {"$_\n"} @new_meta);
return ('scheduled', [ $new_meta, \@channelbins, $forme ]);
}
=head2 build - rebuild a channel
TODO: add description
=cut
sub build {
my ($self, $ctx, $packid, $pdata, $info, $data) = @_;
my $new_meta = $data->[0];
my $channelbins = $data->[1];
my $forme = $data->[2];
my $gctx = $ctx->{'gctx'};
my $myarch = $gctx->{'arch'};
my $projid = $ctx->{'project'};
my $repoid = $ctx->{'repository'};
my $prp = "$projid/$repoid";
my $job = BSSched::BuildJob::jobname($prp, $packid);
my $myjobsdir = $gctx->{'myjobsdir'};
return ('scheduled', $job) if -s "$myjobsdir/$job";
my $reporoot = $gctx->{'reporoot'};
my $jobdatadir = "$myjobsdir/$job:dir";
unlink "$jobdatadir/$_" for ls($jobdatadir);
mkdir_p($jobdatadir);
my %channelinfo = ('/target' => $forme);
my $bininfo = {};
my $checksums = '';
my %checksums_seen;
for my $cb (@$channelbins) {
my ($arepoid, $apackid, $bi, $supportstatus) = @$cb;
my $dir = "$reporoot/$projid/$arepoid/$myarch/$apackid";
my $file = "$dir/$bi->{'filename'}";
my @s = stat($file);
if (!@s || "$s[9]/$s[7]/$s[1]" ne $bi->{'id'}) {
BSUtil::cleandir($jobdatadir);
rmdir($jobdatadir);
return ('broken', "id mismatch in $arepoid/$apackid $s[9]/$s[7]/$s[1] $bi->{'id'}");
}
my $tfilename = $bi->{'filename'};
$tfilename =~ s/^::import::.*?:://;
link($file, "$jobdatadir/$tfilename") || die("link $file $jobdatadir/$tfilename: $!\n");
if ($bi->{'arch'} ne 'src' && $bi->{'arch'} ne 'nosrc' && -e "$dir/$bi->{'name'}-appdata.xml") {
unlink("$jobdatadir/$bi->{'name'}-appdata.xml");
link("$dir/$bi->{'name'}-appdata.xml", "$jobdatadir/$bi->{'name'}-appdata.xml") || die("link $bi->{'name'}-appdata.xml $jobdatadir/$bi->{'name'}-appdata.xml: $!\n");
}
if (!$checksums_seen{"$arepoid/$apackid"}) {
$checksums_seen{"$arepoid/$apackid"} = 1;
# just append the checksums, it does not matter if we pick up too many
if (-s "$reporoot/$projid/$arepoid/$myarch/$apackid/.checksums") {
$checksums .= readstr("$reporoot/$projid/$arepoid/$myarch/$apackid/.checksums", 1) || '';
}
}
$bininfo->{$tfilename} = $bi;
my $ci = { 'repository' => $arepoid, 'package' => $apackid };
$ci->{'supportstatus'} = $supportstatus if defined $supportstatus;
$channelinfo{$tfilename} = $ci;
}
BSUtil::store("$jobdatadir/.channelinfo", undef, \%channelinfo);
writestr("$jobdatadir/.checksums", undef, $checksums) if $checksums;
writestr("$jobdatadir/meta", undef, $new_meta);
BSSched::BuildJob::fakejobfinished_nouseforbuild($ctx, $packid, $job, 'succeeded', $bininfo, $pdata);
return ('done');
}
1;
|