#!/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); $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; Build::define($def); next; } if ($ARGV[0] eq '--with') { shift @ARGV; my $def = shift @ARGV; Build::define("_with_$def --with-$def"); next; } if ($ARGV[0] eq '--without') { shift @ARGV; my $def = shift @ARGV; Build::define("_without_$def --without-$def"); 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 @extradeps; for my $arg (@ARGV) { my $buildtype = Build::recipe2buildtype($arg); if ($buildtype) { die("can only work with at most one recipe file\n") if defined $recipe; $recipe = $arg; } else { push @extradeps, $arg; } } my $binarytype; my @archs = split(':', $archs); if ($recipe =~ /(^|\/)PKGBUILD$/) { push @archs, 'any' unless grep {$_ eq 'any'} @archs; $binarytype = 'arch'; } elsif ($recipe =~ /\.dsc$/) { push @archs, 'all' unless grep {$_ eq 'noarch'} @archs; $binarytype = 'deb'; } else { push @archs, 'noarch' unless grep {$_ eq 'noarch'} @archs; $binarytype = 'rpm'; } # read dist if we can my $cf; if (defined($dist) && $dist ne '') { $cf = Build::read_config_dist($dist, $archs[0], $configdir); $binarytype = $cf->{'binarytype'} if $cf->{'binarytype'} && $cf->{'binarytype'} ne 'UNDEFINED'; } my (%fn, %prov, %req, %con, %obs); 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); 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() { 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 (/^I:(.*?)-\d+\/\d+\/\d+: (.*)$/) { next 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 $con{$i}; delete $obs{$i}; $req{$i} = $pkgR; $con{$i} = $pkgC if defined $pkgC; $obs{$i} = $pkgO if defined $pkgO; } undef $pkgF; undef $pkgP; undef $pkgR; undef $pkgC; undef $pkgO; } 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 :( if ($dist =~ /^sles11-/) { my %res = Build::Rpm::rpmq($rpmfn, 1049); $dist =~ s/^sles11-/sles11sp2-/ if grep {/^liblzma/} @{$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; my $dofileprovides = %{$cf->{'fileprovides'}}; $dofileprovides = 1 if ($binarytype || 'rpm') ne 'rpm'; for my $pack (keys %packs) { my $r = {}; my (@s, $s, @pr, @re, @co, @ob); @s = split(' ', $prov{$packs{$pack}} || ''); while (@s) { $s = shift @s; next if !$dofileprovides && $s =~ /^\//; if ($s =~ /^rpmlib\(/) { splice(@s, 0, 2); next; } push @pr, $s; while (@s && $s[0] =~ /^[\(<=>|]/) { $pr[-1] .= " $s[0] $s[1]"; $pr[-1] =~ s/ \((.*)\)/ $1/; $pr[-1] =~ s/(<|>){2}/$1/; splice(@s, 0, 2); } } @s = split(' ', $req{$packs{$pack}} || ''); while (@s) { $s = shift @s; next if !$dofileprovides && $s =~ /^\//; if ($s =~ /^rpmlib\(/) { splice(@s, 0, 2); next; } push @re, $s; while (@s && $s[0] =~ /^[\(<=>|]/) { $re[-1] .= " $s[0] $s[1]"; $re[-1] =~ s/ \((.*)\)/ $1/; $re[-1] =~ s/(<|>){2}/$1/; splice(@s, 0, 2); } } @s = split(' ', $con{$packs{$pack}} || ''); while (@s) { $s = shift @s; next if !$dofileprovides && $s =~ /^\//; push @co, $s; while (@s && $s[0] =~ /^[\(<=>|]/) { $co[-1] .= " $s[0] $s[1]"; $co[-1] =~ s/ \((.*)\)/ $1/; $co[-1] =~ s/(<|>){2}/$1/; splice(@s, 0, 2); } } @s = split(' ', $obs{$packs{$pack}} || ''); while (@s) { $s = shift @s; next if !$dofileprovides && $s =~ /^\//; push @ob, $s; while (@s && $s[0] =~ /^[\(<=>|]/) { $ob[-1] .= " $s[0] $s[1]"; $ob[-1] =~ s/ \((.*)\)/ $1/; $ob[-1] =~ s/(<|>){2}/$1/; splice(@s, 0, 2); } } $r->{'provides'} = \@pr; $r->{'requires'} = \@re; $r->{'conflicts'} = \@co; $r->{'obsoletes'} = \@ob; $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() { 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 ($packname, $packvers, $subpacks, @packdeps); $subpacks = []; if ($recipe) { my $d = Build::parse($cf, $recipe) || {}; my $buildtype = Build::recipe2buildtype($recipe) || ''; $cf->{'type'} = $buildtype if $buildtype; if ($buildtype eq 'kiwi') { # lets see if this is a product or image build my $type = $d->{'imagetype'} && $d->{'imagetype'}->[0] eq 'product' ? 'product' : 'image'; my @kdeps; if ($type eq 'image') { @kdeps = @{$cf->{'substitute'}->{'kiwi-setup:image'} || []}; @kdeps = ('kiwi', 'createrepo', 'tar') unless @kdeps; } else { @kdeps = @{$cf->{'substitute'}->{'kiwi-setup:product'} || []}; @kdeps = ('kiwi') unless @kdeps; } push @kdeps, grep {/^kiwi-.*:/} @{$d->{'deps'} || []}; $d = { 'deps' => \@kdeps, 'subpacks' => [] }; } $packname = $d->{'name'}; $packvers = $d->{'version'}; $subpacks = $d->{'subpacks'}; @packdeps = @{$d->{'deps'} || []}; if ($d->{'prereqs'}) { my %deps = map {$_ => 1} (@packdeps, @{$d->{'subpacks'} || []}); push @packdeps, '--directdepsend--', grep {!$deps{$_} && !/^%/} @{$d->{'prereqs'}}; } } Build::readdeps($cf, undef, \%repo); ####################################################################### my @bdeps = Build::get_build($cf, $subpacks, @packdeps, @extradeps); if (!shift @bdeps) { print STDERR "expansion error\n"; print STDERR " $_\n" for @bdeps; exit(1); } my @sysdeps = Build::get_sysbuild($cf); 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); } # make sure all preinstalls are in bdeps; # XXX: also add vmdeps? @bdeps = Build::unify(@bdeps, Build::get_preinstalls($cf)); print_rpmlist(@bdeps);