From edfeaeebe2ce0f14b96ff82fa2dc95b0f499930b Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Mon, 1 Mar 2021 12:12:21 +0100 Subject: [PATCH] pbuild: add support for --rebuild --- PBuild/Checker.pm | 3 +++ PBuild/Options.pm | 17 +++++++++-------- pbuild | 18 ++++++++++++++++++ pbuild.1 | 19 ++++++++++++++++++- 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/PBuild/Checker.pm b/PBuild/Checker.pm index 01dc196ee..0d5869ae8 100644 --- a/PBuild/Checker.pm +++ b/PBuild/Checker.pm @@ -311,6 +311,7 @@ sub check_image { } return ('scheduled', [ { 'explain' => 'new build' } ]) if !@meta; return ('scheduled', [ { 'explain' => 'source change', 'oldsource' => substr($meta[0], 0, 32) } ]) if $meta[0] ne $new_meta->[0]; + return ('scheduled', [ { 'explain' => 'forced rebuild' } ]) if $p->{'force_rebuild'}; my $rebuildmethod = $ctx->{'rebuild'} || 'transitive'; if ($rebuildmethod eq 'local') { return ('scheduled', [ { 'explain' => 'rebuild counter sync' } ]) if $ctx->{'relsynctrigger'}->{$packid}; @@ -393,6 +394,8 @@ sub check { return ('scheduled', [ { 'explain' => 'new build' } ]); } elsif (substr($mylastcheck, 0, 32) ne ($p->{'verifymd5'} || $p->{'srcmd5'})) { return ('scheduled', [ { 'explain' => 'source change', 'oldsource' => substr($mylastcheck, 0, 32) } ]); + } elsif ($p->{'force_rebuild'}) { + return ('scheduled', [ { 'explain' => 'forced rebuild' } ]); } elsif (substr($mylastcheck, 32, 32) eq 'fakefakefakefakefakefakefakefake') { my @s = stat("$dst/_meta"); if (!@s || $s[9] + 14400 > time()) { diff --git a/PBuild/Options.pm b/PBuild/Options.pm index 2e75ab1f1..1bbc82eeb 100644 --- a/PBuild/Options.pm +++ b/PBuild/Options.pm @@ -45,10 +45,13 @@ my %known_options = ( 'repository' => 'repo::', 'registry' => 'registry::', 'obs' => 'obs:', - 'result' => \&result_special, + 'result' => \&result_rebuild_special, 'result-pkg' => 'result-pkg::', 'result-code' => 'result-code::', 'details' => 'result-details', + 'rebuild' => \&result_rebuild_special, + 'rebuild-pkg' => 'rebuild-pkg::', + 'rebuild-code' => 'rebuild-code::', 'xen' => \&vm_type_special, 'kvm' => \&vm_type_special, 'uml' => \&vm_type_special, @@ -116,18 +119,16 @@ sub vm_type_special { my @codes = qw{broken succeeded failed unresolvable blocked scheduled waiting building excluded disabled locked}; my %known_codes = map {$_ => 1} @codes; -sub result_special { +sub result_rebuild_special { my ($opts, $origopt, $opt, $args) = @_; my $arg; $arg = getarg($origopt, $args, 1) if @$args && (ref($args->[0]) || $args->[0] !~ /\//); if (!defined($arg) || $arg eq 'all') { - push @{$opts->{'result-code'}}, 'all'; - return; - } - if ($known_codes{$arg}) { - push @{$opts->{'result-code'}}, $arg; + push @{$opts->{"$opt-code"}}, 'all'; + } elsif ($known_codes{$arg}) { + push @{$opts->{"$opt-code"}}, $arg; } else { - push @{$opts->{'result-pkg'}}, $arg; + push @{$opts->{"$opt-pkg"}}, $arg; } } diff --git a/pbuild b/pbuild index 0b0eca91a..8ec7a21c8 100755 --- a/pbuild +++ b/pbuild @@ -240,6 +240,23 @@ for my $pkg (@pkgs) { my $p = $pkgsrc{$pkg}; $p->{'useforbuildenabled'} = 1; } +# force rebuilds if requested +if ($opts->{'rebuild-code'} || $opts->{'rebuild-pkg'}) { + my %codefilter = map {$_ => 1} @{$opts->{'rebuild-code'} || []}; + my %pkgfilter = map {$_ => 1} @{$opts->{'rebuild-pkg'} || []}; + for my $pkg (sort keys %pkgfilter) { + die("rebuild: unknown package $pkg\n") unless $pkgsrc{$pkg}; + } + my $oldresult = {}; + $oldresult = PBuild::Util::retrieve("$builddir/.pbuild/_result") if %codefilter && !$codefilter{'all'}; + for my $pkg (@pkgs) { + my $p = $pkgsrc{$pkg}; + my $code = ($oldresult->{$pkg} || {})->{'code'} || 'unknown'; + next if %pkgfilter && !$pkgfilter{$pkg}; + next if %codefilter && !$codefilter{'all'} && !$codefilter{$code}; + $p->{'force_rebuild'} = 1; + } +} # delete obsolete entries from builddir PBuild::LocalRepo::cleanup_builddir($builddir, \%pkgsrc); @@ -327,6 +344,7 @@ while (1) { # process finished job my ($code, $buildresult) = PBuild::Job::finishjob($job); my $p = $job->{'pdata'}; + delete $p->{'force_rebuild'}; my $duration = $job->{'endtime'} - $job->{'starttime'}; $duration = sprintf("%d:%02d", int($duration / 60), $duration % 60); my $bid = ($job->{'nbuilders'} || 1) > 1 ? "$job->{'name'}: " : ''; diff --git a/pbuild.1 b/pbuild.1 index ee4554a8c..530506c45 100644 --- a/pbuild.1 +++ b/pbuild.1 @@ -80,6 +80,20 @@ obs:/ urls need to be resolved. .BI "\-\-buildjobs " num Start up to \fInum\fP processes to build packages in parallel. .TP +.BI "\-\-rebuild-pkg " packagename +Force a rebuild of the specified package. This option can be +used multiple times. +.TP +.BI "\-\-rebuild-code " code +Force a rebuild of the packages in state "code". This option can be +used multiple times. +.TP +.BI "\-\-rebuild " \fR[\fPcode_or_packagename\fR]\fP +Short hand form to force a rebuild. If no argument is given, +all packages are rebuilt. If the argument is a known +result code, packages with a state matching the specified code are rebuilt. +Otherwise it is assumed that the argument is a package name. +.TP .B "\-\-vm-..." .PD 0 .TP @@ -107,10 +121,13 @@ Only show build results for builds that resulted in the specified code. This option can be used multiple times. .TP .BI "\-\-result " \fR[\fPcode_or_packagename\fR]\fP -This is a short hand form for resut querying. If no argument is given, +This is a short hand form for result querying. If no argument is given, the results for all packages are shown. If the argument is a known result code, builds that resulted in the specified code are shown. Otherwise it is assumed that the argument is a package name. +.TP +.B "\-\-details" +Show more information about the package state. .SH MISC OPTIONS .TP