3 ################################################################
5 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License version 2 or 3 as
9 # published by the Free Software Foundation.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program (see the file COPYING); if not, write to the
18 # Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 ################################################################
24 unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
32 my ($dist, $rpmdeps, $archs, $configdir, $useusedforbuild, $installonly, $noinstall, $usehigherdeps, $isvm);
34 $configdir = ($::ENV{'BUILD_DIR'} || '/usr/lib/build') . '/configs';
37 if ($ARGV[0] eq '--dist') {
42 if ($ARGV[0] eq '--depfile') {
44 $rpmdeps = shift @ARGV;
47 if ($ARGV[0] eq '--archpath') {
52 if ($ARGV[0] eq '--configdir') {
54 $configdir = shift @ARGV;
57 if ($ARGV[0] eq '--useusedforbuild') {
62 if ($ARGV[0] eq '--define') {
64 my $def = shift @ARGV;
68 if ($ARGV[0] eq '--with') {
70 my $def = shift @ARGV;
71 Build::define("_with_$def --with-$def");
74 if ($ARGV[0] eq '--without') {
76 my $def = shift @ARGV;
77 Build::define("_without_$def --without-$def");
80 if ($ARGV[0] eq '--usehigherdeps') {
85 if ($ARGV[0] eq '--vm') {
93 $archs = '' unless defined $archs;
94 die("you must specfiy a depfile!\n") unless defined $rpmdeps;
96 # split args in recipe and pkgnames
100 my $buildtype = Build::recipe2buildtype($arg);
102 die("can only work with at most one recipe file\n") if defined $recipe;
105 push @extradeps, $arg;
110 my @archs = split(':', $archs);
111 if ($recipe && $recipe =~ /(^|\/)PKGBUILD$/) {
112 push @archs, 'any' unless grep {$_ eq 'any'} @archs;
113 $binarytype = 'arch';
114 } elsif ($recipe && $recipe =~ /\.dsc$/) {
115 push @archs, 'all' unless grep {$_ eq 'noarch'} @archs;
118 push @archs, 'noarch' unless grep {$_ eq 'noarch'} @archs;
122 # read dist if we can
124 if (defined($dist) && $dist ne '') {
125 $cf = Build::read_config_dist($dist, $archs[0] || 'noarch', $configdir);
126 $binarytype = $cf->{'binarytype'} if $cf->{'binarytype'} && $cf->{'binarytype'} ne 'UNDEFINED';
129 my (%fn, %prov, %req, %con, %obs, %rec, %sup);
138 # XXX: move to separate tool
139 if (!defined($dist) || $dist eq '') {
140 my $rpmarch = (grep {$fn{"rpm.$_"}} @archs)[0];
144 my $rpmfn = $fn{"rpm.$rpmarch"};
145 if ($rpmfn =~ /^[a-z]+:\/\//) {
147 my $tmpdir = File::Temp::tempdir('CLEANUP' => 1);
148 $rpmfn =~ s/.*\//$tmpdir\// unless system("$INC[0]/download", $tmpdir, $rpmfn);
151 if ($rpmfn =~ /^\// && -e $rpmfn) {
152 my %res = Build::Rpm::rpmq($rpmfn, 1010);
153 $rpmdist = $res{1010}->[0] || '';
155 $dist = Build::dist_canon($rpmdist, $archs[0]);
156 # need some extra work for sles11 :(
157 if ($dist =~ /^sles11-/) {
158 my %res = Build::Rpm::rpmq($rpmfn, 1049);
159 $dist =~ s/^sles11-/sles11sp2-/ if grep {/^liblzma/} @{$res{1049} || []};
162 print STDERR "Warning: distribution not specified, assuming '$dist' (see $configdir).\n";
165 $cf ||= Build::read_config_dist($dist, $archs[0] || 'noarch', $configdir);
166 $cf->{'warnings'} = 1;
168 my $dofileprovides = %{$cf->{'fileprovides'}};
170 my %exportfilters = %{$cf->{'exportfilter'}};
172 open(F, '<', $rpmdeps) || die("$rpmdeps: $!\n");
173 # WARNING: the following code assumes that the 'I' tag comes last
174 my ($pkgF, $pkgP, $pkgR, $pkgC, $pkgO, $pkgr, $pkgs);
176 my $verscmp = \&Build::Rpm::verscmp;
178 if ($binarytype && $binarytype eq 'deb') {
179 $verscmp = \&Build::Deb::verscmp;
180 for my $arch (@archs) {
181 $arch = Build::Deb::basearch($arch) unless $arch =~ /^i[456]86$/;
187 if (/^F:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
188 my $pkgname = basename($2);
193 $pack =~ /^(.*)\.([^\.]+)$/ or die;
194 push @{$packs_arch{$2}}, $1;
197 for(keys %exportfilters) {
198 next if ($pkgname !~ /$_/);
199 for (@{$exportfilters{$_}}) {
202 next if (! grep ($_ eq $a, @archs));
203 $packs{$basename} = "$basename.$arch"
206 } elsif (/^P:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
210 } elsif (/^R:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
214 } elsif (/^C:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
218 } elsif (/^O:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
222 } elsif (/^r:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
224 } elsif (/^s:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
226 } elsif (/^I:(.*?)-\d+\/\d+\/\d+: (.*)$/) {
227 #next if $packs_done{$1};
229 if ($usehigherdeps) {
232 if ($packs_done{$1}) {
247 my ($i, $newid) = ($1, $2);
248 undef $i unless !$ids{$i} || $verscmp->($ids{$i}, $newid) < 0;
249 undef $i unless defined($pkgF) && defined($pkgP) && defined($pkgR);
251 $i =~ /^(.*)\.([^\.]+)$/ or die;
252 push @{$packs_arch{$2}}, $1;
262 $req{$i} = $pkgR if defined $pkgR;
263 $con{$i} = $pkgC if defined $pkgC;
264 $obs{$i} = $pkgO if defined $pkgO;
265 $rec{$i} = $pkgr if defined $pkgr;
266 $sup{$i} = $pkgs if defined $pkgs;
268 #also need to clean the below values.
286 } elsif ($_ eq 'D:') {
292 for my $arch (@archs) {
293 $packs{$_} ||= "$_.$arch" for @{$packs_arch{$arch} || []};
297 for my $pack (keys %packs) {
299 my (@s, $s, @pr, @re, @co, @ob, @rc, @su);
300 @s = split(' ', $prov{$packs{$pack}} || '');
303 next if !$dofileprovides && $s =~ /^\//;
304 if ($s =~ /^rpmlib\(/) {
309 while (@s && $s[0] =~ /^[\(<=>|]/) {
310 $pr[-1] .= " $s[0] $s[1]";
311 $pr[-1] =~ s/ \((.*)\)/ $1/;
312 $pr[-1] =~ s/(<|>){2}/$1/;
316 @s = split(' ', $req{$packs{$pack}} || '');
319 next if !$dofileprovides && $s =~ /^\//;
320 if ($s =~ /^rpmlib\(/) {
325 while (@s && $s[0] =~ /^[\(<=>|]/) {
326 $re[-1] .= " $s[0] $s[1]";
327 $re[-1] =~ s/ \((.*)\)/ $1/;
328 $re[-1] =~ s/(<|>){2}/$1/;
332 @s = split(' ', $con{$packs{$pack}} || '');
335 next if !$dofileprovides && $s =~ /^\//;
337 while (@s && $s[0] =~ /^[\(<=>|]/) {
338 $co[-1] .= " $s[0] $s[1]";
339 $co[-1] =~ s/ \((.*)\)/ $1/;
340 $co[-1] =~ s/(<|>){2}/$1/;
344 @s = split(' ', $obs{$packs{$pack}} || '');
347 next if !$dofileprovides && $s =~ /^\//;
349 while (@s && $s[0] =~ /^[\(<=>|]/) {
350 $ob[-1] .= " $s[0] $s[1]";
351 $ob[-1] =~ s/ \((.*)\)/ $1/;
352 $ob[-1] =~ s/(<|>){2}/$1/;
356 @s = split(' ', $rec{$packs{$pack}} || '');
359 next if !$dofileprovides && $s =~ /^\//;
360 if ($s =~ /^rpmlib\(/) {
365 while (@s && $s[0] =~ /^[\(<=>|]/) {
366 $rc[-1] .= " $s[0] $s[1]";
367 $rc[-1] =~ s/ \((.*)\)/ $1/;
368 $rc[-1] =~ s/(<|>){2}/$1/;
372 @s = split(' ', $sup{$packs{$pack}} || '');
375 next if !$dofileprovides && $s =~ /^\//;
376 if ($s =~ /^rpmlib\(/) {
381 while (@s && $s[0] =~ /^[\(<=>|]/) {
382 $su[-1] .= " $s[0] $s[1]";
383 $su[-1] =~ s/ \((.*)\)/ $1/;
384 $su[-1] =~ s/(<|>){2}/$1/;
388 $r->{'provides'} = \@pr;
389 $r->{'requires'} = \@re;
390 $r->{'conflicts'} = \@co;
391 $r->{'obsoletes'} = \@ob;
392 $r->{'recommends'} = \@rc;
393 $r->{'supplements'} = \@su;
398 #######################################################################
402 print "$_ $fn{$packs{$_}}\n";
403 print "rpmid: $_:$ids{$packs{$_}}\n" if exists $ids{$packs{$_}};
405 print "preinstall: @{$cf->{'preinstall'} || []}\n";
406 print "vminstall: @{$cf->{'vminstall'} || []}\n";
407 print "runscripts: @{$cf->{'runscripts'} || []}\n";
408 print "dist: $dist\n" if defined $dist;
409 print "installonly: $installonly\n" if defined $installonly;
410 print "noinstall: $noinstall\n" if defined $noinstall;
413 if ($useusedforbuild) {
414 die("Need a recipe file for --usedforbuild\n") unless defined $recipe;
416 open(F, '<', $recipe) || die("$recipe: $!\n");
421 if (/^#\s*usedforbuild\s*(.*)$/) {
422 push @usedforbuild, split(' ', $1);
424 if (/^buildrequires:\s*(.*)$/i) {
425 push @buildrequires, split(' ', $1);
429 @usedforbuild = @buildrequires unless @usedforbuild;
430 @usedforbuild = Build::unify(@usedforbuild) if @usedforbuild;
432 for (@usedforbuild) {
433 push @errors, "package $_ not found" unless $packs{$_} && $fn{$packs{$_}};
436 print STDERR "expansion error\n";
437 print STDERR " $_\n" for @errors;
440 print_rpmlist(@usedforbuild);
444 #######################################################################
452 my $d = Build::parse($cf, $recipe) || {};
453 $buildtype = Build::recipe2buildtype($recipe) || '';
454 $cf->{'type'} = $buildtype if $buildtype;
455 if ($buildtype eq 'kiwi') {
456 # lets see if this is a product or image build
457 $buildtype = $d->{'imagetype'} && $d->{'imagetype'}->[0] eq 'product' ? 'kiwi-product' : 'kiwi-image';
458 $extrasysdeps = [ grep {/^kiwi-.*:/} @{$d->{'deps'} || []} ];
460 $subpacks = $d->{'subpacks'};
461 unshift @extradeps, @{$d->{'deps'} || []};
462 if ($d->{'prereqs'}) {
463 my %deps = map {$_ => 1} (@extradeps, @{$d->{'subpacks'} || []});
464 push @extradeps, '--directdepsend--', grep {!$deps{$_} && !/^%/} @{$d->{'prereqs'}};
468 Build::readdeps($cf, undef, \%repo);
470 #######################################################################
472 my @sysdeps = Build::get_sysbuild($cf, $buildtype, $extrasysdeps);
474 if ($buildtype eq 'kiwi-image' || $buildtype eq 'kiwi-product') {
475 # just use the sysdeps for now, ignore real deps
476 print_rpmlist(@sysdeps);
480 push @extradeps, '--ignoreignore--' if @sysdeps;
482 push @packdeps, @{$cf->{'vminstall'}};
484 my @bdeps = Build::get_build($cf, $subpacks, @extradeps);
487 print STDERR "expansion error\n";
488 print STDERR " $_\n" for @bdeps;
493 if (!shift @sysdeps) {
494 print STDERR "expansion error\n";
495 print STDERR " $_\n" for @sysdeps;
498 my %sysdeps = map {$_ => 1} @sysdeps;
499 my %bdeps = map {$_ => 1} @bdeps;
500 $installonly = join(' ', grep {!$bdeps{$_}} @sysdeps);
501 $noinstall = join(' ', grep {!$sysdeps{$_}} @bdeps);
502 @bdeps = Build::unify(@sysdeps, @bdeps);
505 # make sure all preinstalls are in bdeps;
506 @bdeps = Build::unify(@bdeps, Build::get_preinstalls($cf));
507 @bdeps = Build::unify(@bdeps, Build::get_vminstalls($cf)) if $isvm;
509 print_rpmlist(@bdeps);