Skip to content

Commit

Permalink
pbuild: add support for --rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
mlschroe committed Mar 1, 2021
1 parent c6a10e4 commit edfeaee
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
3 changes: 3 additions & 0 deletions PBuild/Checker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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()) {
Expand Down
17 changes: 9 additions & 8 deletions PBuild/Options.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}

Expand Down
18 changes: 18 additions & 0 deletions pbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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'}: " : '';
Expand Down
19 changes: 18 additions & 1 deletion pbuild.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit edfeaee

Please sign in to comment.