If a build step fail, immediately fail all queued builds that depend on it

This prevents unnecessary work, but it's mostly a refactoring to
support combining notification emails.
This commit is contained in:
Eelco Dolstra 2013-05-03 18:30:13 +02:00
parent 507e5bb190
commit f762d111f1

View file

@ -215,6 +215,57 @@ sub addBuildStepOutputs {
}
sub nextFreeStepNr {
my ($build) = @_;
my $max = $build->buildsteps->find(
{}, {select => {max => 'stepnr + 1'}, as => ['max']});
return (defined $max && defined $max->get_column('max')) ? $max->get_column('max') : 1;
}
sub failDependents {
my ($drvPath, $errorMsg) = @_;
# Get the referrer closure of $drvPath.
my @dependentDrvs = computeFSClosure(1, 0, $drvPath);
my $time = time();
txn_do($db, sub {
my @dependentBuilds = $db->resultset('Builds')->search(
{ drvpath => [ @dependentDrvs ], finished => 0, busy => 0 });
for my $d (@dependentBuilds) {
print STDERR "failing dependent build ", $d->id, " of ", $d->project->name, ":", $d->jobset->name, ":", $d->job->name, "\n";
$d->update(
{ finished => 1
, logfile => ''
, timestamp => time # !!! Why change the timestamp?
, iscachedbuild => 0
, buildstatus => $drvPath eq $d->drvpath ? 1 : 2
, starttime => $time
, stoptime => $time
, errormsg => undef
});
my $step = $d->buildsteps->create(
{ stepnr => nextFreeStepNr($d)
, type => 0 # = build
, drvpath => $drvPath
, busy => 0
, status => 1
, starttime => time
, stoptime => time
, errormsg => $errorMsg
});
addBuildStepOutputs($step);
}
});
}
sub doBuild {
my ($build) = @_;
@ -252,10 +303,7 @@ sub doBuild {
"--no-build-output --log-type flat --print-build-trace " .
"--add-root " . gcRootFor($outputs{out} // $outputs{(sort keys %outputs)[0]}) . " 2>&1";
my $max = $build->buildsteps->find(
{}, {select => {max => 'stepnr + 1'}, as => ['max']});
my $buildStepNr = (defined $max && defined $max->get_column('max')) ? $max->get_column('max') : 1;
my $buildStepNr = nextFreeStepNr($build);
my %buildSteps;
open OUT, "$cmd |" or die;
@ -328,6 +376,9 @@ sub doBuild {
addBuildStepOutputs($step);
}
});
# Immediately fail all builds that depend on this derivation.
failDependents($drvPathStep, $errorMsg);
}
elsif (/^@\s+substituter-started\s+(\S+)\s+(\S+)$/) {