forked from openSUSE/obs-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
expanddeps
executable file
·432 lines (386 loc) · 11.4 KB
/
expanddeps
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
#!/usr/bin/perl -w
################################################################
#
# Copyright (c) 1995-2014 SUSE Linux Products GmbH
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or 3 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
#
################################################################
BEGIN {
unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
}
use strict;
use Build;
my ($dist, $rpmdeps, $archs, $configdir, $useusedforbuild, $installonly, $noinstall, $isvm);
my ($obspackage, $buildflavor);
my @distmacros;
$configdir = ($::ENV{'BUILD_DIR'} || '/usr/lib/build') . '/configs';
while (@ARGV) {
if ($ARGV[0] eq '--dist') {
shift @ARGV;
$dist = shift @ARGV;
next;
}
if ($ARGV[0] eq '--depfile') {
shift @ARGV;
$rpmdeps = shift @ARGV;
next;
}
if ($ARGV[0] eq '--archpath') {
shift @ARGV;
$archs = shift @ARGV;
next;
}
if ($ARGV[0] eq '--configdir') {
shift @ARGV;
$configdir = shift @ARGV;
next;
}
if ($ARGV[0] eq '--useusedforbuild') {
shift @ARGV;
$useusedforbuild = 1;
next;
}
if ($ARGV[0] eq '--define') {
shift @ARGV;
my $def = shift @ARGV;
push @distmacros, $def;
next;
}
if ($ARGV[0] eq '--with') {
shift @ARGV;
my $def = shift @ARGV;
push @distmacros, "_with_$def --with-$def";
next;
}
if ($ARGV[0] eq '--without') {
shift @ARGV;
my $def = shift @ARGV;
push @distmacros, "_without_$def --without-$def";
next;
}
if ($ARGV[0] eq '--vm') {
shift @ARGV;
$isvm = 1;
next;
}
if ($ARGV[0] eq '--buildflavor') {
shift @ARGV;
$buildflavor = shift @ARGV;
next;
}
if ($ARGV[0] eq '--obspackage') {
shift @ARGV;
$obspackage = shift @ARGV;
next;
}
last;
}
$archs = '' unless defined $archs;
die("you must specfiy a depfile!\n") unless defined $rpmdeps;
# split args in recipe and pkgnames
my $recipe;
my $buildtype = '';
my @extradeps;
for my $arg (@ARGV) {
my $bt = Build::recipe2buildtype($arg);
if ($bt) {
die("can only work with at most one recipe file\n") if defined $recipe;
$recipe = $arg;
$buildtype = $bt;
} else {
push @extradeps, $arg;
}
}
my @archs = split(':', $archs);
my $binarytype;
$binarytype = 'arch' if $buildtype eq 'arch';
$binarytype = 'deb' if $buildtype eq 'dsc';
$binarytype ||= 'rpm';
# read dist if we can
my $cf;
$cf = Build::read_config_dist($dist, $archs[0] || 'noarch', $configdir) if defined($dist) && $dist ne '';
$binarytype = $cf->{'binarytype'} if $cf && $cf->{'binarytype'} && $cf->{'binarytype'} ne 'UNDEFINED';
my $noarch;
$noarch = 'any' if $binarytype eq 'arch';
$noarch = 'all' if $binarytype eq 'deb';
$noarch ||= 'noarch';
push @archs, $noarch unless grep {$_ eq $noarch} @archs;
my (%fn, %prov, %req, %con, %obs, %rec, %sup);
my %packs;
my %repo;
my %ids;
my %packs_arch;
my %packs_done;
open(F, '<', $rpmdeps) || die("$rpmdeps: $!\n");
# WARNING: the following code assumes that the 'I' tag comes last
my ($pkgF, $pkgP, $pkgR, $pkgC, $pkgO, $pkgr, $pkgs);
my $verscmp = \&Build::Rpm::verscmp;
if ($binarytype && $binarytype eq 'deb') {
$verscmp = \&Build::Deb::verscmp;
for my $arch (@archs) {
$arch = Build::Deb::basearch($arch) unless $arch =~ /^i[456]86$/;
}
}
while(<F>) {
chomp;
if (/^F:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
$pkgF = $2;
} elsif (/^P:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
$pkgP = $2;
} elsif (/^R:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
$pkgR = $2;
} elsif (/^C:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
$pkgC = $2;
} elsif (/^O:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
$pkgO = $2;
} elsif (/^r:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
$pkgr = $2;
} elsif (/^s:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
$pkgs = $2;
} elsif (/^I:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
if (!$packs_done{$1}) {
my ($i, $newid) = ($1, $2);
undef $i unless !$ids{$i} || $verscmp->($ids{$i}, $newid) < 0;
undef $i unless defined($pkgF) && defined($pkgP);
if (defined $i) {
$i =~ /^(.*)\.([^\.]+)$/ or die;
push @{$packs_arch{$2}}, $1;
$ids{$i} = $newid;
$fn{$i} = $pkgF;
$prov{$i} = $pkgP;
delete $req{$i};
delete $rec{$i};
delete $con{$i};
delete $obs{$i};
delete $rec{$i};
delete $sup{$i};
$req{$i} = $pkgR;
$con{$i} = $pkgC if defined $pkgC;
$obs{$i} = $pkgO if defined $pkgO;
$rec{$i} = $pkgr if defined $pkgr;
$sup{$i} = $pkgs if defined $pkgs;
}
}
undef $pkgF;
undef $pkgP;
undef $pkgR;
undef $pkgC;
undef $pkgO;
undef $pkgr;
undef $pkgs;
} elsif ($_ eq 'D:') {
%packs_done = %ids;
}
}
close F;
for my $arch (@archs) {
$packs{$_} ||= "$_.$arch" for @{$packs_arch{$arch} || []};
}
# XXX: move to separate tool
if (!defined($dist) || $dist eq '') {
my $rpmarch = (grep {$fn{"rpm.$_"}} @archs)[0];
if (!$rpmarch) {
$dist = 'default';
} else {
my $rpmfn = $fn{"rpm.$rpmarch"};
if ($rpmfn =~ /^[a-z]+:\/\//) {
require File::Temp;
my $tmpdir = File::Temp::tempdir('CLEANUP' => 1);
$rpmfn =~ s/.*\//$tmpdir\// unless system("$INC[0]/download", $tmpdir, $rpmfn);
}
my $rpmdist = '';
if ($rpmfn =~ /^\// && -e $rpmfn) {
my %res = Build::Rpm::rpmq($rpmfn, 1010);
$rpmdist = $res{1010}->[0] || '';
}
$dist = Build::dist_canon($rpmdist, $archs[0]);
# need some extra work for sles11 and sles15 :(
if ($dist =~ /^sles11-/) {
my %res = Build::Rpm::rpmq($rpmfn, 1049);
$dist =~ s/^sles11-/sles11sp2-/ if grep {/^liblzma/} @{$res{1049} || []};
}
if ($dist =~ /^sles15-/) {
my %res = Build::Rpm::rpmq($rpmfn, 1049);
$dist =~ s/^sles15-/sles15sp2-/ if grep {/^libgcrypt/} @{$res{1049} || []};
}
}
print STDERR "Warning: distribution not specified, assuming '$dist' (see $configdir).\n";
}
$cf ||= Build::read_config_dist($dist, $archs[0], $configdir);
$cf->{'warnings'} = 1;
$cf->{'buildflavor'} = $buildflavor if defined $buildflavor;
$cf->{'obspackage'} = $obspackage if defined $obspackage;
$cf->{'no_vminstall_expand'} = 1 unless $isvm;
Build::add_distmacro($cf, $_) for @distmacros;
my $dofileprovides = %{$cf->{'fileprovides'}};
$dofileprovides = 1 if ($binarytype || 'rpm') ne 'rpm';
sub parsedepline {
return [] unless defined $_[0];
my @s = split(' ', $_[0]);
my @r;
while (@s) {
my $s = shift @s;
next if !$dofileprovides && $s =~ /^\//;
if ($s =~ /^rpmlib\(/) {
splice(@s, 0, 2);
next;
}
if ($s =~ /^\(/) {
unshift @s, $s;
push @r, Build::Rpm::shiftrich(\@s);
next;
}
push @r, $s;
while (@s && $s[0] =~ /^\(?[<=>|]/) {
$r[-1] .= " $s[0] $s[1]";
$r[-1] =~ s/ \((.*)\)/ $1/;
$r[-1] =~ s/(<|>){2}/$1/;
splice(@s, 0, 2);
}
}
return \@r;
}
for my $pack (keys %packs) {
my $r = {};
$r->{'provides'} = parsedepline($prov{$packs{$pack}});
$r->{'requires'} = parsedepline($req{$packs{$pack}});
$r->{'conflicts'} = parsedepline($con{$packs{$pack}});
$r->{'obsoletes'} = parsedepline($obs{$packs{$pack}});
$r->{'recommends'} = parsedepline($rec{$packs{$pack}});
$r->{'supplements'} = parsedepline($sup{$packs{$pack}});
$repo{$pack} = $r;
}
#######################################################################
sub print_rpmlist {
for (@_) {
print "$_ $fn{$packs{$_}}\n";
print "rpmid: $_:$ids{$packs{$_}}\n" if exists $ids{$packs{$_}};
}
print "preinstall: @{$cf->{'preinstall'} || []}\n";
print "vminstall: @{$cf->{'vminstall'} || []}\n";
print "runscripts: @{$cf->{'runscripts'} || []}\n";
print "dist: $dist\n" if defined $dist;
print "installonly: $installonly\n" if defined $installonly;
print "noinstall: $noinstall\n" if defined $noinstall;
}
if ($useusedforbuild) {
die("Need a recipe file for --usedforbuild\n") unless defined $recipe;
local *F;
open(F, '<', $recipe) || die("$recipe: $!\n");
my @usedforbuild;
my @buildrequires;
while(<F>) {
chomp;
if (/^#\s*usedforbuild\s*(.*)$/) {
push @usedforbuild, split(' ', $1);
}
if (/^buildrequires:\s*(.*)$/i) {
push @buildrequires, split(' ', $1);
}
}
close F;
@usedforbuild = @buildrequires unless @usedforbuild;
@usedforbuild = Build::unify(@usedforbuild) if @usedforbuild;
my @errors;
for (@usedforbuild) {
push @errors, "package $_ not found" unless $packs{$_} && $fn{$packs{$_}};
}
if (@errors) {
print STDERR "expansion error\n";
print STDERR " $_\n" for @errors;
exit(1);
}
print_rpmlist(@usedforbuild);
exit(0);
}
#######################################################################
my $subpacks = [];
my $extrasysdeps;
sub includecallback {
my ($recipe, $file) = @_;
$file =~ s/.*\///;
$recipe =~ s/[^\/]+$//;
$file = "$recipe$file";
my $fd;
my $str;
if (open($fd, '<', $file)) {
local $/;
$str = <$fd>;
close($fd);
}
return $str;
}
if ($recipe) {
local $Build::Rpm::includecallback = sub { includecallback($recipe, @_) };
my $d = Build::parse($cf, $recipe) || {};
$cf->{'type'} = $buildtype if $buildtype;
if ($buildtype eq 'kiwi') {
# lets see if this is a product or image build
$buildtype = $d->{'imagetype'} && $d->{'imagetype'}->[0] eq 'product' ? 'kiwi-product' : 'kiwi-image';
$extrasysdeps = [ grep {/^kiwi-.*:/} @{$d->{'deps'} || []} ];
}
$subpacks = $d->{'subpacks'};
unshift @extradeps, @{$d->{'deps'} || []};
if ($d->{'prereqs'}) {
my %deps = map {$_ => 1} (@extradeps, @{$d->{'subpacks'} || []});
push @extradeps, '--directdepsend--', grep {!$deps{$_} && !/^%/} @{$d->{'prereqs'}};
}
}
Build::readdeps($cf, undef, \%repo);
#######################################################################
my @sysdeps = Build::get_sysbuild($cf, $buildtype, $extrasysdeps);
if ($buildtype eq 'kiwi-image' || $buildtype eq 'kiwi-product') {
if (!shift @sysdeps) {
print STDERR "expansion error\n";
print STDERR " $_\n" for @sysdeps;
exit(1);
}
# just use the sysdeps for now, ignore real deps
print_rpmlist(@sysdeps);
exit(0);
}
push @extradeps, '--ignoreignore--' if @sysdeps;
my @bdeps = Build::get_build($cf, $subpacks, @extradeps);
if (!shift @bdeps) {
print STDERR "expansion error\n";
print STDERR " $_\n" for @bdeps;
exit(1);
}
if (@sysdeps) {
if (!shift @sysdeps) {
print STDERR "expansion error\n";
print STDERR " $_\n" for @sysdeps;
exit(1);
}
my %sysdeps = map {$_ => 1} @sysdeps;
my %bdeps = map {$_ => 1} @bdeps;
$installonly = join(' ', grep {!$bdeps{$_}} @sysdeps);
$noinstall = join(' ', grep {!$sysdeps{$_}} @bdeps);
@bdeps = Build::unify(@sysdeps, @bdeps);
}
# get preinstalls/vminstalls and check if the packages exist
my @xdeps = Build::get_preinstalls($cf);
push @xdeps, Build::get_vminstalls($cf) if $isvm;
my @missing = grep {!$packs{$_}} @xdeps;
if (@missing) {
@missing = sort(Build::unify(@missing));
print STDERR "expansion error\n";
print STDERR " missing pre/vminstalls: ".join(', ', @missing)."\n";
exit(1);
}
# make sure all preinstalls/vminstalls are in bdeps
@bdeps = Build::unify(@bdeps, @xdeps);
print_rpmlist(@bdeps);