forked from openSUSE/openSUSE-release-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrebuildpacs.pl
executable file
·353 lines (286 loc) · 8.78 KB
/
rebuildpacs.pl
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
#! /usr/bin/perl
use Data::Dumper;
use XML::Simple;
use URI::Escape;
use File::Basename;
use File::Temp qw/tempdir/;
use Digest::MD5 qw(md5_hex);
my $script_dir;
BEGIN {
($script_dir) = $0 =~ m-(.*)/-;
$script_dir ||= '.';
unshift @INC, $script_dir;
}
require CreatePackageDescr;
my @repodirs;
sub find_source_container($) {
my $pkg = shift;
for my $repodir (@repodirs) {
my @rpms = glob("$repodir/*-$pkg.rpm");
for my $rpm (@rpms) {
# 1123 == Disturl
my %qq = Build::Rpm::rpmq( $rpm, qw{NAME 1123} );
next if ( $qq{NAME}[0] ne $pkg );
my $distfile = basename( $qq{1123}[0] );
$distfile =~ s,^[^-]*-,,;
return $distfile;
}
}
}
my $followup = 0;
my $cproblem = '';
my %problems;
my $project = $ARGV[0] || "openSUSE:Factory";
my $repo = $ARGV[1] || "standard";
my $arch = $ARGV[2] || "x86_64";
my %leafed;
sub read_plain_index($) {
my $file = shift;
my %ret;
open(FILE, $file) || return \%ret;
while ( <FILE> ) {
if (m/^(.*):(.*)/) {
$ret{$1} = $2;
}
}
close(FILE);
return \%ret;
}
sub write_plain_index($$) {
my $file = shift;
my $hash = shift;
open(FILE, ">$file") || die "can't write to $file";
for my $key (sort keys %{$hash}) {
print FILE "$key:" . $hash->{$key} . "\n";
}
close(FILE);
}
# defines packages that need to be triggered too
my %parents = (
"rpmlint" => [qw(rpmlint-mini)],
"branding-openSUSE" => [
qw(glib2-branding-openSUSE
kiwi-config-openSUSE
xfce4-branding-openSUSE
kdebase4-openSUSE kde-branding-openSUSE
bundle-lang-kde bundle-lang-common
openSUSE-images installation-images-openSUSE)
],
"kdebase4-openSUSE" => [qw(bundle-lang-kde)],
);
# for subsets (staging projects) we need to remember which are ignored
my %ignored;
sub check_leaf_package($$) {
my $package = shift;
my $rebuildhash = shift;
if (system("osc api /source/$project/$package/_meta > /dev/null 2>&1 ")) {
$ignored{$package} = 1;
return;
}
my @lines = ();
open( OSC, "osc api /build/$project/$repo/$arch/$package/_buildinfo?internal=1|" );
while (<OSC>) {
chomp;
if (m/<subpack>(.*)</) {
$leafed{$1} = $package;
}
if (m/bdep name="([^"]*)"/) {
my $parent = $leafed{$1};
if ( $parent && $parent ne "rpmlint-mini" ) {
# I dislike grep
unless (grep { $_ eq $package } @{$parents{$parent}}) {
print "ADD $package to PARENT $parent!!\n";
}
next;
}
}
else {
next;
}
next if (m/notmeta="1"/);
push( @lines, $_ );
}
close(OSC);
my $ctx = Digest::MD5->new;
for my $line ( sort @lines ) {
$ctx->add($line);
}
my $rebuilds = read_plain_index("buildinfos");
my $newmd5 = $ctx->hexdigest;
if ($rebuilds->{"$project/$repo/$arch/$package"} ne $newmd5) {
$rebuildhash->{$package} = 1;
for my $child (@{$parents{$package}}) {
$rebuildhash->{$child} = 1;
}
$rebuilds->{"$project/$repo/$arch/$package"} = $newmd5;
write_plain_index("buildinfos", $rebuilds);
}
}
my %torebuild;
check_leaf_package("rpmlint", \%torebuild);
check_leaf_package("rpmlint-mini", \%torebuild);
check_leaf_package("branding-openSUSE", \%torebuild);
check_leaf_package("glib2-branding-openSUSE", \%torebuild);
check_leaf_package("PackageKit-branding-openSUSE", \%torebuild);
check_leaf_package("kiwi-config-openSUSE", \%torebuild);
check_leaf_package("xfce4-branding-openSUSE", \%torebuild);
check_leaf_package("kdebase4-openSUSE", \%torebuild);
check_leaf_package("kde-branding-openSUSE", \%torebuild);
check_leaf_package("bundle-lang-common", \%torebuild);
check_leaf_package("bundle-lang-kde", \%torebuild);
check_leaf_package("bundle-lang-gnome", \%torebuild);
check_leaf_package("installation-images-openSUSE", \%torebuild);
check_leaf_package("openSUSE-images", \%torebuild);
if (%torebuild) {
my $api = "/build/$project?cmd=rebuild&repository=$repo&arch=$arch";
for my $package (sort keys %torebuild) {
next if (defined $ignored{$package});
$api .= "&package=" . uri_escape( $package );
}
system("osc api -X POST '$api'");
}
my $pfile = tempdir() . "/packages"; # the filename is important ;(
sub mirror_repo($$$) {
my $project = shift;
my $repo = shift;
my $arch = shift;
my $repodir = ($ENV{XDG_CACHE_HOME}||$ENV{HOME}."/.cache")."/opensuse-repo-checker/repo-$project-$repo-$arch";
mkdir($repodir);
system(
"$script_dir/bs_mirrorfull --nodebug https://api.opensuse.org/public/build/$project/$repo/$arch/ $repodir"
);
return $repodir;
}
sub find_package_in_project($) {
my $project = shift;
open(OSC, "osc api /source/$project?expand=1 |");
my $xml = XMLin(join('', <OSC>), ForceArray => 1);
close(OSC);
my @packs = keys %{$xml->{entry}};
return shift @packs;
}
# find a random package
sub get_paths($$$) {
my $project = shift;
my $repo = shift;
my $arch = shift;
my $package = find_package_in_project($project);
open(OSC, "osc api /build/$project/$repo/$arch/$package/_buildinfo|");
my $xml = join('', <OSC>);
if ($xml !~ m/^</) {
die "failed to open /build/$project/$repo/$arch/$package/_buildinfo";
}
$xml = XMLin($xml, ForceArray => 1);
close(OSC);
return $xml->{path};
}
my $paths = get_paths($project, $repo, $arch);
my @rpms;
for my $path (@$paths) {
# openSUSE:Factory/ports is in the paths, but not a repo
if (system("osc api /build/$path->{'project'}/$path->{'repository'}/$arch > /dev/null 2>&1 ")) {
next;
}
my $repodir = mirror_repo($path->{'project'}, $path->{'repository'}, $arch);
push(@repodirs, $repodir);
push(@rpms, glob("$repodir/*.rpm"));
}
open( PACKAGES, ">", $pfile ) || die "can not open $pfile";
print PACKAGES "=Ver: 2.0\n";
my %knipser;
foreach my $package (@rpms) {
die $package unless $package =~ m,/.{32}-([^/]+)\.rpm$,;
next if $knipser{$1}++;
my $out = CreatePackageDescr::package_snippet($package);
print PACKAGES $out;
}
close(PACKAGES);
# read the problems out of installcheck
open( INSTALLCHECK, "installcheck $arch $pfile|" );
while (<INSTALLCHECK>) {
chomp;
if (m/^can't install (.*)\-[^-]*\-[^-]*\.($arch|noarch):/) {
$cproblem = $1;
$cproblem =~ s/kmp-([^-]*)/kmp-default/;
$cproblem = find_source_container($cproblem);
$followup = 0;
next;
}
$followup = 1 if ( $_ =~ m/none of the providers can be installed/ );
# not interesting for me
next if (m/ \(we have /);
next if ($followup);
# very thin ice here
s,\(\)\(64bit\),,;
s,(needed by [^ ]*)\-[^-]*\-[^-]*\.($arch|noarch)$,$1,;
s,^\s*,,;
# patterns are too spammy and rebuilding doesn't help
next if (grep { $_ eq $cproblem } qw(patterns-openSUSE));
$problems{$cproblem}->{$_} = 1;
}
close(INSTALLCHECK);
unlink($pfile);
rmdir(dirname($pfile));
for my $package ( sort keys %problems ) {
$problems{$package} = join( ', ', sort( keys %{ $problems{$package} } ) );
}
my @other_problems;
my %oproblems;
open( PROBLEMS, "problems" );
while (<PROBLEMS>) {
chomp;
if (m,^$project/$repo/$arch/([^:]*):\s*(.*)$,) {
my $package = $1;
my $oproblem = $2;
# remember old problems for current project/repo
$oproblems{$package} = $oproblem;
}
else {
# keep all lines for other projects/repos as they are
push @other_problems, $_;
}
}
close(PROBLEMS);
exit(0) if ( !%problems );
# check for succeeded packages - we can't filter as we don't know if the problems are all in the top project ;(
my $api = "/build/$project/_result?repository=$repo&arch=$arch&code=succeeded";
open( RESULT, "osc api '$api'|" );
@result = <RESULT>;
my $results = XMLin( join( '', @result ), ForceArray => ['status'] );
close(RESULT);
my @packages = @{ $results->{result}->{status} };
my $rebuildit = 0;
$api = "/build/$project?cmd=rebuild&repository=$repo&arch=$arch";
for my $package (@packages) {
$package = $package->{package};
if (!$problems{$package}) {
# it can go
delete $oproblems{$package};
next;
}
my $oproblem = $oproblems{$package} || '';
if ($problems{$package} eq $oproblem) {
# rebuild won't help
next;
}
$rebuildit = 1;
print "rebuild ", $package, ": ",
$problems{ $package }, "\n";
$api .= "&package=" . uri_escape( $package );
$oproblems{$package} = $problems{$package};
}
open( PROBLEMS, ">problems" );
# write all lines for other projects/repos as they are
foreach (@other_problems) {
print PROBLEMS $_, "\n";
}
for my $package (keys %oproblems) {
print PROBLEMS "$project/$repo/$arch/"
. $package . ": "
. $oproblems{ $package }, "\n";
}
close(PROBLEMS);
if ($rebuildit) {
print "API '$api'\n";
system("osc api -X POST '$api'");
}