From 870069125533f903a5dadfcedbe8003388e372d8 Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Fri, 19 Feb 2021 15:14:58 +0100 Subject: [PATCH] Small code cleanups --- PBuild/Checker.pm | 63 ++++++++++++++++++++++++++--------------------- PBuild/Job.pm | 5 ++-- pbuild | 14 +++++------ 3 files changed, 44 insertions(+), 38 deletions(-) diff --git a/PBuild/Checker.pm b/PBuild/Checker.pm index f94351cdb..d0bb5b63c 100644 --- a/PBuild/Checker.pm +++ b/PBuild/Checker.pm @@ -153,7 +153,7 @@ sub pkgcheck { # cycle handling code my $incycle = 0; if ($cychash->{$packid}) { - ($packid, $incycle) = PBuild::Checker::handlecycle($ctx, $packid, \@cpacks, \%cycpass, \%packstatus); + ($packid, $incycle) = handlecycle($ctx, $packid, \@cpacks, \%cycpass, \%packstatus); next unless $incycle; } my $p = $pkgsrc->{$packid}; @@ -181,7 +181,7 @@ sub pkgcheck { next; } - my ($status, $error) = PBuild::Checker::check($ctx, $packid, $incycle); + my ($status, $error) = check($ctx, $p, $incycle); #printf("%s -> %s%s", $packid, $status, $error && $status ne 'scheduled' ? " ($error)" : ''); if ($status eq 'scheduled') { my $builder; @@ -193,7 +193,7 @@ sub pkgcheck { if (!$builder) { ($status, $error) = ('waiting', undef); } else { - ($status, $error) = PBuild::Checker::build($ctx, $packid, $error, $builder); + ($status, $error) = build($ctx, $p, $error, $builder); } if ($status eq 'building') { my $job = $error; @@ -227,34 +227,42 @@ sub pkgcheck { return \%result; } +# +# Generate the dependency tracking data for a image/container +# +sub genmeta_image { + my ($ctx, $p, $edeps) = @_; + if ($p->{'buildtype'} eq 'preinstallimage') { + my @pdeps = Build::get_preinstalls($ctx->{'bconf'}); + my @vmdeps = Build::get_vminstalls($ctx->{'bconf'}); + $edeps = [ PBuild::Util::unify(@$edeps, @pdeps, @vmdeps) ]; + } + my $dep2pkg = $ctx->{'dep2pkg'}; + my @new_meta; + for my $bin (@$edeps) { + my $q = $dep2pkg->{$bin}; + push @new_meta, (($q || {})->{'hdrmd5'} || 'd0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0')." $bin"; + } + @new_meta = sort {substr($a, 34) cmp substr($b, 34) || $a cmp $b} @new_meta; + unshift @new_meta, ($p->{'verifymd5'} || $p->{'srcmd5'})." $p->{'pkg'}"; + return \@new_meta; +} + # # Generate the dependency tracking data for a package # sub genmeta { my ($ctx, $p, $edeps) = @_; + my $buildtype = $p->{'buildtype'}; + return genmeta_image($ctx, $p, $edeps) if $buildtype eq 'kiwi' || $buildtype eq 'docker' || $buildtype eq 'preinstallimage'; my $dep2pkg = $ctx->{'dep2pkg'}; - if ($p->{'buildtype'} eq 'kiwi' || $p->{'buildtype'} eq 'docker' || $p->{'buildtype'} eq 'preinstallimage') { - if ($p->{'buildtype'} eq 'preinstallimage') { - my @pdeps = Build::get_preinstalls($ctx->{'bconf'}); - my @vmdeps = Build::get_vminstalls($ctx->{'bconf'}); - $edeps = [ PBuild::Util::unify(@$edeps, @pdeps, @vmdeps) ]; - } - my @new_meta; - for my $bin (@$edeps) { - my $q = $dep2pkg->{$bin}; - push @new_meta, (($q || {})->{'hdrmd5'} || 'd0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0')." $bin"; - } - @new_meta = sort {substr($a, 34) cmp substr($b, 34) || $a cmp $b} @new_meta; - unshift @new_meta, ($p->{'verifymd5'} || $p->{'srcmd5'})." $p->{'pkg'}"; - return \@new_meta; - } my $metacache = $ctx->{'metacache'}; my @new_meta; my $builddir = $ctx->{'builddir'}; for my $bin (@$edeps) { my $q = $dep2pkg->{$bin}; my $binpackid = $q->{'packid'}; - if (!$binpackid) { + if (!defined $binpackid) { # use the hdrmd5 for non-local packages push @new_meta, ($q->{'hdrmd5'} || 'd0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0')." $bin"; next; @@ -269,7 +277,7 @@ sub genmeta { close($mfd); die("$mf: bad meta\n") unless length($metacache->{$binpackid}) > 34; } - PBuild::Meta::add_meta(\@new_meta, $metacache->{$q->{'packid'}}, $bin, $p->{'pkg'}); + PBuild::Meta::add_meta(\@new_meta, $metacache->{$binpackid}, $bin, $p->{'pkg'}); } @new_meta = PBuild::Meta::gen_meta($ctx->{'subpacks'}->{$p->{'name'}} || [], @new_meta); unshift @new_meta, ($p->{'verifymd5'} || $p->{'srcmd5'})." $p->{'pkg'}"; @@ -280,9 +288,8 @@ sub genmeta { # Check the status of a single image/container # sub check_image { - my ($ctx, $packid) = @_; + my ($ctx, $p) = @_; my $bconf = $ctx->{'bconf'}; - my $p = $ctx->{'pkgsrc'}->{$packid}; my $edeps = $p->{'dep_expanded'} || []; my $notready = $ctx->{'notready'}; my $dep2src = $ctx->{'dep2src'}; @@ -293,6 +300,7 @@ sub check_image { return ('blocked', join(', ', @blocked)); } my $new_meta = genmeta($ctx, $p, $edeps); + my $packid = $p->{'pkg'}; my $dst = "$ctx->{'builddir'}/$packid"; my @meta; my $mfp; @@ -321,12 +329,12 @@ sub check_image { # Check the status of a single package # sub check { - my ($ctx, $packid, $incycle) = @_; + my ($ctx, $p, $incycle) = @_; - my $p = $ctx->{'pkgsrc'}->{$packid}; my $buildtype = $p->{'buildtype'}; - return check_image($ctx, $packid) if $buildtype eq 'kiwi' || $buildtype eq 'docker' || $buildtype eq 'preinstallimage'; + return check_image($ctx, $p) if $buildtype eq 'kiwi' || $buildtype eq 'docker' || $buildtype eq 'preinstallimage'; + my $packid = $p->{'pkg'}; my $notready = $ctx->{'notready'}; my $dep2src = $ctx->{'dep2src'}; my $edeps = $p->{'dep_expanded'} || []; @@ -510,13 +518,12 @@ sub handlecycle { # Start the build of a package # sub build { - my ($ctx, $packid, $data, $builder) = @_; + my ($ctx, $p, $data, $builder) = @_; + my $packid = $p->{'pkg'}; my $reason = $data->[0]; #print Dumper($reason); my $nounchanged = 1 if $packid && $ctx->{'cychash'}->{$packid}; my @btdeps; - my $p = $ctx->{'pkgsrc'}->{$packid}; - die if $p->{'pkg'} ne $packid; # just in case my $edeps = $p->{'dep_expanded'} || []; my $bconf = $ctx->{'bconf'}; my $buildtype = $p->{'buildtype'}; diff --git a/PBuild/Job.pm b/PBuild/Job.pm index 370a65c76..e1eee5e0c 100644 --- a/PBuild/Job.pm +++ b/PBuild/Job.pm @@ -150,6 +150,8 @@ sub collect_result { # # Create a new build job # +# ctx usage: opts hostarch bconf arch repos dep2pkg buildconfig debuginfo +# sub createjob { my ($ctx, $jobname, $nbuilders, $buildroot, $p, $bdeps, $pdeps, $vmdeps, $sysdeps, $nounchanged) = @_; my $opts = $ctx->{'opts'}; @@ -242,7 +244,7 @@ sub createjob { push @args, "--$opt=$opts->{$opt}" if defined $opts->{$opt}, } } else { - print "VM-TYPE $vm not detected" if $vm; + warn("VM-TYPE $vm is unknown\n") if $vm; push @args, "--root=$buildroot"; push @args, "--vm-type=$vm" if $vm; } @@ -292,7 +294,6 @@ sub createjob { unlink("$buildroot/.build.log"); #print "building $p->{'pkg'}/$p->{'recipe'}\n"; - unlink("$buildroot/.build.log"); my $pid = forkjob(\@args); return { 'name' => $jobname, 'nbuilders' => $nbuilders, 'pid' => $pid, 'buildroot' => $buildroot, 'vm_type' => $vm, 'pdata' => $p, 'logfile' => "$buildroot/.build.log", 'logfile_lines' => 0, 'starttime' => time() }; } diff --git a/pbuild b/pbuild index 6bfd5cb7a..9d4aa892e 100755 --- a/pbuild +++ b/pbuild @@ -260,21 +260,23 @@ for my $no (1..$opts->{'buildjobs'}) { } # the big loop: while there is something to do +my $runs = 0; while (1) { # create and setup checker if (!$ctx) { $ctx = PBuild::Checker::create($bconf, $myarch, $buildtype, \%pkgsrc, $builddir, $opts); - print "preparing package pool\n"; + print "preparing package pool\n" unless $runs; PBuild::Checker::prepare($ctx, \@repos); - print "expanding dependencies\n"; + print "expanding dependencies\n" unless $runs; PBuild::Checker::pkgexpand($ctx, @pkgs); - print "sorting packages\n"; + print "sorting packages\n" unless $runs; @pkgs = PBuild::Checker::pkgsort($ctx, @pkgs); } + $runs++; $ctx->{'buildconfig'} = $buildconfig; $ctx->{'lastcheck'} = \%lastcheck; - # check all packages + # check status of all packages my $result = PBuild::Checker::pkgcheck($ctx, \@builders, @pkgs); # update on-disk data @@ -314,10 +316,6 @@ while (1) { $repos[0]->{'bins'} = $localbins; # we also need a new checker undef $ctx; - $ctx = PBuild::Checker::create($bconf, $myarch, $buildtype, \%pkgsrc, $builddir, $opts); - PBuild::Checker::prepare($ctx, \@repos); - PBuild::Checker::pkgexpand($ctx, @pkgs); - @pkgs = PBuild::Checker::pkgsort($ctx, @pkgs); } } }