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], $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], $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;
278 } elsif ($_ eq 'D:') {
284 for my $arch (@archs) {
285 $packs{$_} ||= "$_.$arch" for @{$packs_arch{$arch} || []};
289 for my $pack (keys %packs) {
291 my (@s, $s, @pr, @re, @co, @ob, @rc, @su);
292 @s = split(' ', $prov{$packs{$pack}} || '');
295 next if !$dofileprovides && $s =~ /^\//;
296 if ($s =~ /^rpmlib\(/) {
301 while (@s && $s[0] =~ /^[\(<=>|]/) {
302 $pr[-1] .= " $s[0] $s[1]";
303 $pr[-1] =~ s/ \((.*)\)/ $1/;
304 $pr[-1] =~ s/(<|>){2}/$1/;
308 @s = split(' ', $req{$packs{$pack}} || '');
311 next if !$dofileprovides && $s =~ /^\//;
312 if ($s =~ /^rpmlib\(/) {
317 while (@s && $s[0] =~ /^[\(<=>|]/) {
318 $re[-1] .= " $s[0] $s[1]";
319 $re[-1] =~ s/ \((.*)\)/ $1/;
320 $re[-1] =~ s/(<|>){2}/$1/;
324 @s = split(' ', $con{$packs{$pack}} || '');
327 next if !$dofileprovides && $s =~ /^\//;
329 while (@s && $s[0] =~ /^[\(<=>|]/) {
330 $co[-1] .= " $s[0] $s[1]";
331 $co[-1] =~ s/ \((.*)\)/ $1/;
332 $co[-1] =~ s/(<|>){2}/$1/;
336 @s = split(' ', $obs{$packs{$pack}} || '');
339 next if !$dofileprovides && $s =~ /^\//;
341 while (@s && $s[0] =~ /^[\(<=>|]/) {
342 $ob[-1] .= " $s[0] $s[1]";
343 $ob[-1] =~ s/ \((.*)\)/ $1/;
344 $ob[-1] =~ s/(<|>){2}/$1/;
348 @s = split(' ', $rec{$packs{$pack}} || '');
351 next if !$dofileprovides && $s =~ /^\//;
352 if ($s =~ /^rpmlib\(/) {
357 while (@s && $s[0] =~ /^[\(<=>|]/) {
358 $rc[-1] .= " $s[0] $s[1]";
359 $rc[-1] =~ s/ \((.*)\)/ $1/;
360 $rc[-1] =~ s/(<|>){2}/$1/;
364 @s = split(' ', $sup{$packs{$pack}} || '');
367 next if !$dofileprovides && $s =~ /^\//;
368 if ($s =~ /^rpmlib\(/) {
373 while (@s && $s[0] =~ /^[\(<=>|]/) {
374 $su[-1] .= " $s[0] $s[1]";
375 $su[-1] =~ s/ \((.*)\)/ $1/;
376 $su[-1] =~ s/(<|>){2}/$1/;
380 $r->{'provides'} = \@pr;
381 $r->{'requires'} = \@re;
382 $r->{'conflicts'} = \@co;
383 $r->{'obsoletes'} = \@ob;
384 $r->{'recommends'} = \@rc;
385 $r->{'supplements'} = \@su;
390 #######################################################################
394 print "$_ $fn{$packs{$_}}\n";
395 print "rpmid: $_:$ids{$packs{$_}}\n" if exists $ids{$packs{$_}};
397 print "preinstall: @{$cf->{'preinstall'} || []}\n";
398 print "vminstall: @{$cf->{'vminstall'} || []}\n";
399 print "runscripts: @{$cf->{'runscripts'} || []}\n";
400 print "dist: $dist\n" if defined $dist;
401 print "installonly: $installonly\n" if defined $installonly;
402 print "noinstall: $noinstall\n" if defined $noinstall;
405 if ($useusedforbuild) {
406 die("Need a recipe file for --usedforbuild\n") unless defined $recipe;
408 open(F, '<', $recipe) || die("$recipe: $!\n");
413 if (/^#\s*usedforbuild\s*(.*)$/) {
414 push @usedforbuild, split(' ', $1);
416 if (/^buildrequires:\s*(.*)$/i) {
417 push @buildrequires, split(' ', $1);
421 @usedforbuild = @buildrequires unless @usedforbuild;
422 @usedforbuild = Build::unify(@usedforbuild) if @usedforbuild;
424 for (@usedforbuild) {
425 push @errors, "package $_ not found" unless $packs{$_} && $fn{$packs{$_}};
428 print STDERR "expansion error\n";
429 print STDERR " $_\n" for @errors;
432 print_rpmlist(@usedforbuild);
436 #######################################################################
444 my $d = Build::parse($cf, $recipe) || {};
445 $buildtype = Build::recipe2buildtype($recipe) || '';
446 $cf->{'type'} = $buildtype if $buildtype;
447 if ($buildtype eq 'kiwi') {
448 # lets see if this is a product or image build
449 $buildtype = $d->{'imagetype'} && $d->{'imagetype'}->[0] eq 'product' ? 'kiwi-product' : 'kiwi-image';
450 $extrasysdeps = [ grep {/^kiwi-.*:/} @{$d->{'deps'} || []} ];
452 $subpacks = $d->{'subpacks'};
453 unshift @extradeps, @{$d->{'deps'} || []};
454 if ($d->{'prereqs'}) {
455 my %deps = map {$_ => 1} (@extradeps, @{$d->{'subpacks'} || []});
456 push @extradeps, '--directdepsend--', grep {!$deps{$_} && !/^%/} @{$d->{'prereqs'}};
460 Build::readdeps($cf, undef, \%repo);
462 #######################################################################
464 my @sysdeps = Build::get_sysbuild($cf, $buildtype, $extrasysdeps);
466 if ($buildtype eq 'kiwi-image' || $buildtype eq 'kiwi-product') {
467 # just use the sysdeps for now, ignore real deps
468 print_rpmlist(@sysdeps);
472 push @extradeps, '--ignoreignore--' if @sysdeps;
474 push @packdeps, @{$cf->{'vminstall'}};
476 my @bdeps = Build::get_build($cf, $subpacks, @extradeps);
479 print STDERR "expansion error\n";
480 print STDERR " $_\n" for @bdeps;
485 if (!shift @sysdeps) {
486 print STDERR "expansion error\n";
487 print STDERR " $_\n" for @sysdeps;
490 my %sysdeps = map {$_ => 1} @sysdeps;
491 my %bdeps = map {$_ => 1} @bdeps;
492 $installonly = join(' ', grep {!$bdeps{$_}} @sysdeps);
493 $noinstall = join(' ', grep {!$sysdeps{$_}} @bdeps);
494 @bdeps = Build::unify(@sysdeps, @bdeps);
497 # make sure all preinstalls are in bdeps;
498 @bdeps = Build::unify(@bdeps, Build::get_preinstalls($cf));
499 @bdeps = Build::unify(@bdeps, Build::get_vminstalls($cf)) if $isvm;
501 print_rpmlist(@bdeps);