2009-10-26 15:39:14 +00:00
|
|
|
|
package Hydra::Helper::AddBuilds;
|
|
|
|
|
|
|
|
|
|
use strict;
|
2013-09-25 15:51:03 +02:00
|
|
|
|
use utf8;
|
2015-04-14 15:20:56 +02:00
|
|
|
|
use Encode;
|
2014-09-30 00:20:54 +02:00
|
|
|
|
use JSON;
|
2009-10-26 17:01:23 +00:00
|
|
|
|
use IPC::Run;
|
2011-11-30 15:25:28 +01:00
|
|
|
|
use Nix::Store;
|
2013-02-13 18:26:00 +01:00
|
|
|
|
use Nix::Config;
|
2012-03-13 12:10:19 +01:00
|
|
|
|
use Hydra::Model::DB;
|
2009-10-26 15:39:14 +00:00
|
|
|
|
use Hydra::Helper::Nix;
|
2010-07-27 11:14:24 +00:00
|
|
|
|
use Digest::SHA qw(sha256_hex);
|
2010-09-02 09:00:06 +00:00
|
|
|
|
use File::Basename;
|
|
|
|
|
use File::stat;
|
2010-07-27 11:14:24 +00:00
|
|
|
|
use File::Path;
|
2011-12-04 22:01:53 +01:00
|
|
|
|
use File::Temp;
|
2013-02-13 18:26:00 +01:00
|
|
|
|
use File::Spec;
|
2013-02-13 16:49:28 +00:00
|
|
|
|
use File::Slurp;
|
2013-07-08 13:35:34 -04:00
|
|
|
|
use Hydra::Helper::PluginHooks;
|
2013-11-11 21:17:22 +00:00
|
|
|
|
use Hydra::Helper::CatalystUtils;
|
2009-10-26 15:39:14 +00:00
|
|
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
2011-12-01 13:25:54 +01:00
|
|
|
|
our @EXPORT = qw(
|
2013-05-25 15:36:58 -04:00
|
|
|
|
fetchInput evalJobs checkBuild inputsToArgs
|
2015-05-28 17:39:29 +02:00
|
|
|
|
restartBuild getPrevJobsetEval
|
2011-12-01 13:25:54 +01:00
|
|
|
|
);
|
|
|
|
|
|
2009-10-26 15:39:14 +00:00
|
|
|
|
|
|
|
|
|
sub parseJobName {
|
|
|
|
|
# Parse a job specification of the form `<project>:<jobset>:<job>
|
|
|
|
|
# [attrs]'. The project, jobset and attrs may be omitted. The
|
|
|
|
|
# attrs have the form `name = "value"'.
|
|
|
|
|
my ($s) = @_;
|
|
|
|
|
our $key;
|
|
|
|
|
our %attrs = ();
|
|
|
|
|
# hm, maybe I should stop programming Perl before it's too late...
|
2012-01-06 23:04:48 +01:00
|
|
|
|
$s =~ / ^ (?: (?: ([\w\-]+) : )? ([\w\-]+) : )? ([\w\-\.]+) \s*
|
2009-10-26 15:39:14 +00:00
|
|
|
|
(\[ \s* (
|
|
|
|
|
([\w]+) (?{ $key = $^N; }) \s* = \s* \"
|
|
|
|
|
([\w\-]+) (?{ $attrs{$key} = $^N; }) \"
|
|
|
|
|
\s* )* \])? $
|
|
|
|
|
/x
|
|
|
|
|
or die "invalid job specifier `$s'";
|
|
|
|
|
return ($1, $2, $3, \%attrs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub attrsToSQL {
|
|
|
|
|
my ($attrs, $id) = @_;
|
|
|
|
|
|
|
|
|
|
my $query = "1 = 1";
|
|
|
|
|
|
|
|
|
|
foreach my $name (keys %{$attrs}) {
|
|
|
|
|
my $value = $attrs->{$name};
|
|
|
|
|
$name =~ /^[\w\-]+$/ or die;
|
|
|
|
|
$value =~ /^[\w\-]+$/ or die;
|
|
|
|
|
# !!! Yes, this is horribly injection-prone... (though
|
|
|
|
|
# name/value are filtered above). Should use SQL::Abstract,
|
|
|
|
|
# but it can't deal with subqueries. At least we should use
|
|
|
|
|
# placeholders.
|
|
|
|
|
$query .= " and exists (select 1 from buildinputs where build = $id and name = '$name' and value = '$value')";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $query;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-05 16:16:49 +00:00
|
|
|
|
|
2009-11-17 15:16:41 +00:00
|
|
|
|
sub fetchInputBuild {
|
2011-12-04 22:18:23 +01:00
|
|
|
|
my ($db, $project, $jobset, $name, $value) = @_;
|
2009-10-26 15:39:14 +00:00
|
|
|
|
|
2013-11-11 21:36:26 +00:00
|
|
|
|
my $prevBuild;
|
|
|
|
|
|
|
|
|
|
if ($value =~ /^\d+$/) {
|
|
|
|
|
$prevBuild = $db->resultset('Builds')->find({ id => int($value) });
|
|
|
|
|
} else {
|
|
|
|
|
my ($projectName, $jobsetName, $jobName, $attrs) = parseJobName($value);
|
|
|
|
|
$projectName ||= $project->name;
|
|
|
|
|
$jobsetName ||= $jobset->name;
|
|
|
|
|
|
|
|
|
|
# Pick the most recent successful build of the specified job.
|
|
|
|
|
$prevBuild = $db->resultset('Builds')->search(
|
|
|
|
|
{ finished => 1, project => $projectName, jobset => $jobsetName
|
|
|
|
|
, job => $jobName, buildStatus => 0 },
|
|
|
|
|
{ order_by => "me.id DESC", rows => 1
|
|
|
|
|
, where => \ attrsToSQL($attrs, "me.id") })->single;
|
|
|
|
|
}
|
2009-10-26 15:39:14 +00:00
|
|
|
|
|
2014-11-18 11:13:34 +01:00
|
|
|
|
return () if !defined $prevBuild || !isValidPath(getMainOutput($prevBuild)->path);
|
2009-10-26 15:39:14 +00:00
|
|
|
|
|
2010-03-05 16:16:49 +00:00
|
|
|
|
#print STDERR "input `", $name, "': using build ", $prevBuild->id, "\n";
|
2009-10-26 15:39:14 +00:00
|
|
|
|
|
2010-03-05 16:16:49 +00:00
|
|
|
|
my $pkgNameRE = "(?:(?:[A-Za-z0-9]|(?:-[^0-9]))+)";
|
|
|
|
|
my $versionRE = "(?:[A-Za-z0-9\.\-]+)";
|
2009-10-26 15:39:14 +00:00
|
|
|
|
|
2012-03-05 21:52:47 +01:00
|
|
|
|
my $relName = ($prevBuild->releasename or $prevBuild->nixname);
|
2010-03-05 16:16:49 +00:00
|
|
|
|
my $version = $2 if $relName =~ /^($pkgNameRE)-($versionRE)$/;
|
2012-06-26 08:04:35 +02:00
|
|
|
|
|
2015-08-10 08:02:10 -04:00
|
|
|
|
my $mainOutput = getMainOutput($prevBuild);
|
|
|
|
|
|
2015-08-10 13:47:39 -04:00
|
|
|
|
my $result =
|
2015-08-10 08:02:10 -04:00
|
|
|
|
{ storePath => $mainOutput->path
|
2010-03-05 16:16:49 +00:00
|
|
|
|
, id => $prevBuild->id
|
|
|
|
|
, version => $version
|
2015-08-10 08:02:10 -04:00
|
|
|
|
, outputName => $mainOutput->name
|
2010-03-05 16:16:49 +00:00
|
|
|
|
};
|
2015-08-10 13:59:22 -04:00
|
|
|
|
if (isValidPath($prevBuild->drvpath)) {
|
|
|
|
|
$result->{drvPath} = $prevBuild->drvpath;
|
2015-08-10 13:47:39 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
2009-11-17 15:16:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-05 16:16:49 +00:00
|
|
|
|
|
2010-01-19 14:15:31 +00:00
|
|
|
|
sub fetchInputSystemBuild {
|
2011-12-04 22:18:23 +01:00
|
|
|
|
my ($db, $project, $jobset, $name, $value) = @_;
|
2010-01-19 14:15:31 +00:00
|
|
|
|
|
2010-03-05 16:16:49 +00:00
|
|
|
|
my ($projectName, $jobsetName, $jobName, $attrs) = parseJobName($value);
|
|
|
|
|
$projectName ||= $project->name;
|
|
|
|
|
$jobsetName ||= $jobset->name;
|
2010-01-19 14:15:31 +00:00
|
|
|
|
|
2010-03-05 16:16:49 +00:00
|
|
|
|
my @latestBuilds = $db->resultset('LatestSucceededForJob')
|
|
|
|
|
->search({}, {bind => [$projectName, $jobsetName, $jobName]});
|
2010-01-19 14:15:31 +00:00
|
|
|
|
|
2010-03-05 16:16:49 +00:00
|
|
|
|
my @validBuilds = ();
|
|
|
|
|
foreach my $build (@latestBuilds) {
|
2013-02-26 15:51:56 +01:00
|
|
|
|
push(@validBuilds, $build) if isValidPath(getMainOutput($build)->path);
|
2010-03-05 16:16:49 +00:00
|
|
|
|
}
|
2012-06-26 08:04:35 +02:00
|
|
|
|
|
2010-03-05 16:16:49 +00:00
|
|
|
|
if (scalar(@validBuilds) == 0) {
|
|
|
|
|
print STDERR "input `", $name, "': no previous build available\n";
|
2013-05-25 15:36:58 -04:00
|
|
|
|
return ();
|
2010-03-05 16:16:49 +00:00
|
|
|
|
}
|
2012-06-26 08:04:35 +02:00
|
|
|
|
|
2010-03-05 16:16:49 +00:00
|
|
|
|
my @inputs = ();
|
2012-06-26 08:04:35 +02:00
|
|
|
|
|
2010-03-05 16:16:49 +00:00
|
|
|
|
foreach my $prevBuild (@validBuilds) {
|
|
|
|
|
my $pkgNameRE = "(?:(?:[A-Za-z0-9]|(?:-[^0-9]))+)";
|
|
|
|
|
my $versionRE = "(?:[A-Za-z0-9\.\-]+)";
|
2012-06-26 08:04:35 +02:00
|
|
|
|
|
2012-03-05 21:52:47 +01:00
|
|
|
|
my $relName = ($prevBuild->releasename or $prevBuild->nixname);
|
2010-03-05 16:16:49 +00:00
|
|
|
|
my $version = $2 if $relName =~ /^($pkgNameRE)-($versionRE)$/;
|
2012-06-26 08:04:35 +02:00
|
|
|
|
|
2010-03-05 16:16:49 +00:00
|
|
|
|
my $input =
|
2013-02-13 16:49:28 +00:00
|
|
|
|
{ storePath => getMainOutput($prevBuild)->path
|
2010-03-05 16:16:49 +00:00
|
|
|
|
, id => $prevBuild->id
|
|
|
|
|
, version => $version
|
|
|
|
|
, system => $prevBuild->system
|
|
|
|
|
};
|
|
|
|
|
push(@inputs, $input);
|
|
|
|
|
}
|
2012-06-26 08:04:35 +02:00
|
|
|
|
|
|
|
|
|
return @inputs;
|
2010-01-19 14:15:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-11 21:17:22 +00:00
|
|
|
|
|
|
|
|
|
sub fetchInputEval {
|
|
|
|
|
my ($db, $project, $jobset, $name, $value) = @_;
|
|
|
|
|
|
|
|
|
|
my $eval;
|
|
|
|
|
|
|
|
|
|
if ($value =~ /^\d+$/) {
|
|
|
|
|
$eval = $db->resultset('JobsetEvals')->find({ id => int($value) });
|
|
|
|
|
die "evaluation $eval->{id} does not exist\n" unless defined $eval;
|
|
|
|
|
} elsif ($value =~ /^($projectNameRE):($jobsetNameRE)$/) {
|
|
|
|
|
my $jobset = $db->resultset('Jobsets')->find({ project => $1, name => $2 });
|
|
|
|
|
die "jobset ‘$value’ does not exist\n" unless defined $jobset;
|
|
|
|
|
$eval = getLatestFinishedEval($jobset);
|
|
|
|
|
die "jobset ‘$value’ does not have a finished evaluation\n" unless defined $eval;
|
|
|
|
|
} elsif ($value =~ /^($projectNameRE):($jobsetNameRE):($jobNameRE)$/) {
|
|
|
|
|
$eval = $db->resultset('JobsetEvals')->find(
|
|
|
|
|
{ project => $1, jobset => $2, hasnewbuilds => 1 },
|
|
|
|
|
{ order_by => "id DESC", rows => 1
|
|
|
|
|
, where =>
|
|
|
|
|
\ [ # All builds in this jobset should be finished...
|
|
|
|
|
"not exists (select 1 from JobsetEvalMembers m join Builds b on m.build = b.id where m.eval = me.id and b.finished = 0) "
|
|
|
|
|
# ...and the specified build must have succeeded.
|
|
|
|
|
. "and exists (select 1 from JobsetEvalMembers m join Builds b on m.build = b.id where m.eval = me.id and b.job = ? and b.buildstatus = 0)"
|
|
|
|
|
, [ 'name', $3 ] ]
|
|
|
|
|
});
|
|
|
|
|
die "there is no successful build of ‘$value’ in a finished evaluation\n" unless defined $eval;
|
|
|
|
|
} else {
|
|
|
|
|
die;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $jobs = {};
|
|
|
|
|
foreach my $build ($eval->builds) {
|
|
|
|
|
next unless $build->finished == 1 && $build->buildstatus == 0;
|
|
|
|
|
# FIXME: Handle multiple outputs.
|
|
|
|
|
my $out = $build->buildoutputs->find({ name => "out" });
|
|
|
|
|
next unless defined $out;
|
|
|
|
|
# FIXME: Should we fail if the path is not valid?
|
|
|
|
|
next unless isValidPath($out->path);
|
|
|
|
|
$jobs->{$build->get_column('job')} = $out->path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { jobs => $jobs };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-11-17 15:16:41 +00:00
|
|
|
|
sub fetchInput {
|
2013-10-08 14:47:24 -04:00
|
|
|
|
my ($plugins, $db, $project, $jobset, $name, $type, $value, $emailresponsible) = @_;
|
2011-12-05 17:13:20 +01:00
|
|
|
|
my @inputs;
|
2009-11-17 15:16:41 +00:00
|
|
|
|
|
2013-05-25 15:36:58 -04:00
|
|
|
|
if ($type eq "build") {
|
|
|
|
|
@inputs = fetchInputBuild($db, $project, $jobset, $name, $value);
|
2009-11-17 15:16:41 +00:00
|
|
|
|
}
|
2010-01-19 14:15:31 +00:00
|
|
|
|
elsif ($type eq "sysbuild") {
|
2013-05-25 15:36:58 -04:00
|
|
|
|
@inputs = fetchInputSystemBuild($db, $project, $jobset, $name, $value);
|
2012-06-26 08:04:35 +02:00
|
|
|
|
}
|
2013-11-11 21:17:22 +00:00
|
|
|
|
elsif ($type eq "eval") {
|
|
|
|
|
@inputs = fetchInputEval($db, $project, $jobset, $name, $value);
|
|
|
|
|
}
|
2013-09-30 12:03:25 +02:00
|
|
|
|
elsif ($type eq "string" || $type eq "nix") {
|
2009-10-26 15:39:14 +00:00
|
|
|
|
die unless defined $value;
|
2013-05-25 15:36:58 -04:00
|
|
|
|
@inputs = { value => $value };
|
2012-06-26 08:04:35 +02:00
|
|
|
|
}
|
2009-10-26 15:39:14 +00:00
|
|
|
|
elsif ($type eq "boolean") {
|
|
|
|
|
die unless defined $value && ($value eq "true" || $value eq "false");
|
2013-05-25 15:36:58 -04:00
|
|
|
|
@inputs = { value => $value };
|
2012-06-26 08:04:35 +02:00
|
|
|
|
}
|
2009-10-26 15:39:14 +00:00
|
|
|
|
else {
|
2013-05-25 15:36:58 -04:00
|
|
|
|
my $found = 0;
|
|
|
|
|
foreach my $plugin (@{$plugins}) {
|
2013-07-29 15:33:22 -04:00
|
|
|
|
@inputs = $plugin->fetchInput($type, $name, $value, $project, $jobset);
|
2013-05-25 15:36:58 -04:00
|
|
|
|
if (defined $inputs[0]) {
|
|
|
|
|
$found = 1;
|
|
|
|
|
last;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
die "input `$name' has unknown type `$type'." unless $found;
|
2009-10-26 15:39:14 +00:00
|
|
|
|
}
|
2011-12-04 22:18:23 +01:00
|
|
|
|
|
2013-10-07 10:17:22 -04:00
|
|
|
|
foreach my $input (@inputs) {
|
|
|
|
|
$input->{type} = $type;
|
2013-10-08 14:47:24 -04:00
|
|
|
|
$input->{emailresponsible} = $emailresponsible;
|
2013-10-07 10:17:22 -04:00
|
|
|
|
}
|
2011-12-05 17:13:20 +01:00
|
|
|
|
|
|
|
|
|
return @inputs;
|
2009-10-26 15:39:14 +00:00
|
|
|
|
}
|
2009-10-26 17:01:23 +00:00
|
|
|
|
|
|
|
|
|
|
2012-08-16 19:07:04 +02:00
|
|
|
|
sub booleanToString {
|
|
|
|
|
my ($exprType, $value) = @_;
|
|
|
|
|
my $result;
|
|
|
|
|
if ($exprType eq "guile") {
|
2013-01-22 14:09:37 +01:00
|
|
|
|
if ($value eq "true") {
|
|
|
|
|
$result = "#t";
|
|
|
|
|
} else {
|
|
|
|
|
$result = "#f";
|
|
|
|
|
}
|
|
|
|
|
$result = $value;
|
2012-08-16 19:07:04 +02:00
|
|
|
|
} else {
|
2013-01-22 14:09:37 +01:00
|
|
|
|
$result = $value;
|
2012-08-16 19:07:04 +02:00
|
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-25 15:36:58 -04:00
|
|
|
|
|
2012-08-16 19:07:04 +02:00
|
|
|
|
sub buildInputToString {
|
|
|
|
|
my ($exprType, $input) = @_;
|
|
|
|
|
my $result;
|
|
|
|
|
if ($exprType eq "guile") {
|
2013-01-22 14:09:37 +01:00
|
|
|
|
$result = "'((file-name . \"" . ${input}->{storePath} . "\")" .
|
|
|
|
|
(defined $input->{revision} ? "(revision . \"" . $input->{revision} . "\")" : "") .
|
|
|
|
|
(defined $input->{revCount} ? "(revision-count . " . $input->{revCount} . ")" : "") .
|
|
|
|
|
(defined $input->{gitTag} ? "(git-tag . \"" . $input->{gitTag} . "\")" : "") .
|
|
|
|
|
(defined $input->{shortRev} ? "(short-revision . \"" . $input->{shortRev} . "\")" : "") .
|
|
|
|
|
(defined $input->{version} ? "(version . \"" . $input->{version} . "\")" : "") .
|
|
|
|
|
")";
|
2012-08-16 19:07:04 +02:00
|
|
|
|
} else {
|
2013-01-22 14:09:37 +01:00
|
|
|
|
$result = "{ outPath = builtins.storePath " . $input->{storePath} . "" .
|
2015-08-04 06:50:04 -04:00
|
|
|
|
"; inputType = \"" . $input->{type} . "\"" .
|
2015-07-31 09:47:44 -04:00
|
|
|
|
(defined $input->{uri} ? "; uri = \"" . $input->{uri} . "\"" : "") .
|
2013-05-25 15:36:58 -04:00
|
|
|
|
(defined $input->{revNumber} ? "; rev = " . $input->{revNumber} . "" : "") .
|
2013-01-22 14:09:37 +01:00
|
|
|
|
(defined $input->{revision} ? "; rev = \"" . $input->{revision} . "\"" : "") .
|
|
|
|
|
(defined $input->{revCount} ? "; revCount = " . $input->{revCount} . "" : "") .
|
|
|
|
|
(defined $input->{gitTag} ? "; gitTag = \"" . $input->{gitTag} . "\"" : "") .
|
|
|
|
|
(defined $input->{shortRev} ? "; shortRev = \"" . $input->{shortRev} . "\"" : "") .
|
|
|
|
|
(defined $input->{version} ? "; version = \"" . $input->{version} . "\"" : "") .
|
2015-08-10 08:02:10 -04:00
|
|
|
|
(defined $input->{outputName} ? "; outputName = \"" . $input->{outputName} . "\"" : "") .
|
2015-08-10 13:48:09 -04:00
|
|
|
|
(defined $input->{drvPath} ? "; drvPath = builtins.storePath " . $input->{drvPath} . "" : "") .
|
2013-01-22 14:09:37 +01:00
|
|
|
|
";}";
|
2012-08-16 19:07:04 +02:00
|
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-13 16:49:28 +00:00
|
|
|
|
|
2009-10-26 17:01:23 +00:00
|
|
|
|
sub inputsToArgs {
|
2012-08-16 19:07:04 +02:00
|
|
|
|
my ($inputInfo, $exprType) = @_;
|
2009-10-26 17:01:23 +00:00
|
|
|
|
my @res = ();
|
|
|
|
|
|
2015-07-10 16:44:06 +02:00
|
|
|
|
foreach my $input (sort keys %{$inputInfo}) {
|
2011-12-05 13:08:43 +01:00
|
|
|
|
push @res, "-I", "$input=$inputInfo->{$input}->[0]->{storePath}"
|
2012-06-26 08:04:35 +02:00
|
|
|
|
if scalar @{$inputInfo->{$input}} == 1
|
2011-12-05 13:08:43 +01:00
|
|
|
|
&& defined $inputInfo->{$input}->[0]->{storePath};
|
2009-10-26 17:01:23 +00:00
|
|
|
|
foreach my $alt (@{$inputInfo->{$input}}) {
|
2015-04-09 17:22:10 +02:00
|
|
|
|
if ($alt->{type} eq "string") {
|
|
|
|
|
push @res, "--argstr", $input, $alt->{value};
|
|
|
|
|
}
|
|
|
|
|
elsif ($alt->{type} eq "boolean") {
|
|
|
|
|
push @res, "--arg", $input, booleanToString($exprType, $alt->{value});
|
|
|
|
|
}
|
2014-12-12 11:27:17 +01:00
|
|
|
|
elsif ($alt->{type} eq "nix") {
|
2015-04-09 17:22:10 +02:00
|
|
|
|
die "input type ‘nix’ only supported for Nix-based jobsets\n" unless $exprType eq "nix";
|
|
|
|
|
push @res, "--arg", $input, $alt->{value};
|
|
|
|
|
}
|
2014-12-12 11:27:17 +01:00
|
|
|
|
elsif ($alt->{type} eq "eval") {
|
2015-04-09 17:22:10 +02:00
|
|
|
|
die "input type ‘eval’ only supported for Nix-based jobsets\n" unless $exprType eq "nix";
|
|
|
|
|
my $s = "{ ";
|
|
|
|
|
# FIXME: escape $_. But dots should not be escaped.
|
|
|
|
|
$s .= "$_ = builtins.storePath ${\$alt->{jobs}->{$_}}; "
|
|
|
|
|
foreach keys %{$alt->{jobs}};
|
|
|
|
|
$s .= "}";
|
|
|
|
|
push @res, "--arg", $input, $s;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
push @res, "--arg", $input, buildInputToString($exprType, $alt);
|
|
|
|
|
}
|
2009-10-26 17:01:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return @res;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-29 15:57:47 +01:00
|
|
|
|
|
2009-10-26 17:01:23 +00:00
|
|
|
|
sub evalJobs {
|
2012-08-16 19:07:04 +02:00
|
|
|
|
my ($inputInfo, $exprType, $nixExprInputName, $nixExprPath) = @_;
|
2009-10-26 17:01:23 +00:00
|
|
|
|
|
|
|
|
|
my $nixExprInput = $inputInfo->{$nixExprInputName}->[0]
|
2013-01-23 15:56:28 +01:00
|
|
|
|
or die "cannot find the input containing the job expression.\n";
|
|
|
|
|
die "multiple alternatives for the input containing the Nix expression are not supported.\n"
|
2009-10-26 17:01:23 +00:00
|
|
|
|
if scalar @{$inputInfo->{$nixExprInputName}} != 1;
|
|
|
|
|
my $nixExprFullPath = $nixExprInput->{storePath} . "/" . $nixExprPath;
|
2012-06-26 08:04:35 +02:00
|
|
|
|
|
2012-08-16 19:07:04 +02:00
|
|
|
|
my $evaluator = ($exprType eq "guile") ? "hydra-eval-guile-jobs" : "hydra-eval-jobs";
|
|
|
|
|
|
2015-04-09 17:35:04 +02:00
|
|
|
|
my @cmd = ($evaluator, $nixExprFullPath, "--gc-roots-dir", getGCRootsDir, "-j", 1, inputsToArgs($inputInfo, $exprType));
|
|
|
|
|
|
|
|
|
|
if (defined $ENV{'HYDRA_DEBUG'}) {
|
|
|
|
|
sub escape {
|
|
|
|
|
my $s = $_;
|
|
|
|
|
$s =~ s/'/'\\''/g;
|
|
|
|
|
return "'" . $s . "'";
|
|
|
|
|
}
|
|
|
|
|
my @escaped = map escape, @cmd;
|
|
|
|
|
print STDERR "evaluator: @escaped\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(my $res, my $jobsJSON, my $stderr) = captureStdoutStderr(10800, @cmd);
|
2014-09-30 00:20:54 +02:00
|
|
|
|
die "$evaluator returned " . ($res & 127 ? "signal $res" : "exit code " . ($res >> 8))
|
2015-04-14 15:20:56 +02:00
|
|
|
|
. ":\n" . ($stderr ? decode("utf-8", $stderr) : "(no output)\n")
|
2014-09-30 00:20:54 +02:00
|
|
|
|
if $res;
|
2009-10-26 17:01:23 +00:00
|
|
|
|
|
|
|
|
|
print STDERR "$stderr";
|
|
|
|
|
|
2014-09-30 00:20:54 +02:00
|
|
|
|
return (decode_json($jobsJSON), $nixExprInput);
|
2009-10-26 17:01:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-29 15:57:47 +01:00
|
|
|
|
|
2012-03-12 20:28:44 +01:00
|
|
|
|
# Return the most recent evaluation of the given jobset (that
|
|
|
|
|
# optionally had new builds), or undefined if no such evaluation
|
|
|
|
|
# exists.
|
2012-03-07 18:48:10 +01:00
|
|
|
|
sub getPrevJobsetEval {
|
2012-03-12 20:28:44 +01:00
|
|
|
|
my ($db, $jobset, $hasNewBuilds) = @_;
|
|
|
|
|
my ($prevEval) = $jobset->jobsetevals(
|
2012-06-26 08:04:35 +02:00
|
|
|
|
($hasNewBuilds ? { hasnewbuilds => 1 } : { }),
|
2012-03-12 20:28:44 +01:00
|
|
|
|
{ order_by => "id DESC", rows => 1 });
|
2012-03-07 18:48:10 +01:00
|
|
|
|
return $prevEval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-10-26 17:01:23 +00:00
|
|
|
|
# Check whether to add the build described by $buildInfo.
|
|
|
|
|
sub checkBuild {
|
2013-08-14 01:59:29 +02:00
|
|
|
|
my ($db, $jobset, $inputInfo, $nixExprInput, $buildInfo, $buildMap, $prevEval, $jobOutPathMap, $plugins) = @_;
|
2009-10-26 17:01:23 +00:00
|
|
|
|
|
2014-09-30 00:20:54 +02:00
|
|
|
|
my @outputNames = sort keys %{$buildInfo->{outputs}};
|
2013-02-13 16:49:28 +00:00
|
|
|
|
die unless scalar @outputNames;
|
|
|
|
|
|
|
|
|
|
# In various checks we can use an arbitrary output (the first)
|
|
|
|
|
# rather than all outputs, since if one output is the same, the
|
|
|
|
|
# others will be as well.
|
|
|
|
|
my $firstOutputName = $outputNames[0];
|
2014-09-30 00:20:54 +02:00
|
|
|
|
my $firstOutputPath = $buildInfo->{outputs}->{$firstOutputName};
|
2013-02-13 16:49:28 +00:00
|
|
|
|
|
|
|
|
|
my $jobName = $buildInfo->{jobName} or die;
|
|
|
|
|
my $drvPath = $buildInfo->{drvPath} or die;
|
2009-10-26 17:01:23 +00:00
|
|
|
|
|
|
|
|
|
my $build;
|
|
|
|
|
|
|
|
|
|
txn_do($db, sub {
|
2013-08-14 01:59:29 +02:00
|
|
|
|
my $job = $jobset->jobs->update_or_create({ name => $jobName });
|
2009-10-26 17:01:23 +00:00
|
|
|
|
|
|
|
|
|
# Don't add a build that has already been scheduled for this
|
|
|
|
|
# job, or has been built but is still a "current" build for
|
|
|
|
|
# this job. Note that this means that if the sources of a job
|
|
|
|
|
# are changed from A to B and then reverted to A, three builds
|
|
|
|
|
# will be performed (though the last one will probably use the
|
|
|
|
|
# cached result from the first). This ensures that the builds
|
|
|
|
|
# with the highest ID will always be the ones that we want in
|
2013-02-13 16:49:28 +00:00
|
|
|
|
# the channels. FIXME: Checking the output paths doesn't take
|
|
|
|
|
# meta-attributes into account. For instance, do we want a
|
|
|
|
|
# new build to be scheduled if the meta.maintainers field is
|
|
|
|
|
# changed?
|
2012-03-07 18:48:10 +01:00
|
|
|
|
if (defined $prevEval) {
|
2013-02-13 16:49:28 +00:00
|
|
|
|
# Only check one output: if it's the same, the other will be as well.
|
|
|
|
|
my $firstOutput = $outputNames[0];
|
2012-04-04 17:29:03 +02:00
|
|
|
|
my ($prevBuild) = $prevEval->builds->search(
|
2013-01-22 14:09:37 +01:00
|
|
|
|
# The "project" and "jobset" constraints are
|
|
|
|
|
# semantically unnecessary (because they're implied by
|
|
|
|
|
# the eval), but they give a factor 1000 speedup on
|
|
|
|
|
# the Nixpkgs jobset with PostgreSQL.
|
2013-08-14 01:59:29 +02:00
|
|
|
|
{ project => $jobset->project->name, jobset => $jobset->name, job => $jobName,
|
2013-02-13 16:49:28 +00:00
|
|
|
|
name => $firstOutputName, path => $firstOutputPath },
|
|
|
|
|
{ rows => 1, columns => ['id'], join => ['buildoutputs'] });
|
2012-03-07 18:48:10 +01:00
|
|
|
|
if (defined $prevBuild) {
|
2014-09-30 00:29:36 +02:00
|
|
|
|
#print STDERR " already scheduled/built as build ", $prevBuild->id, "\n";
|
2013-08-27 11:48:02 +02:00
|
|
|
|
$buildMap->{$prevBuild->id} = { id => $prevBuild->id, jobName => $jobName, new => 0, drvPath => $drvPath };
|
2012-03-07 18:48:10 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2009-10-26 17:01:23 +00:00
|
|
|
|
}
|
2012-04-02 15:56:29 +00:00
|
|
|
|
|
|
|
|
|
# Prevent multiple builds with the same (job, outPath) from
|
|
|
|
|
# being added.
|
2013-08-14 01:59:29 +02:00
|
|
|
|
my $prev = $$jobOutPathMap{$jobName . "\t" . $firstOutputPath};
|
2012-04-02 15:56:29 +00:00
|
|
|
|
if (defined $prev) {
|
2014-09-30 00:29:36 +02:00
|
|
|
|
#print STDERR " already scheduled as build ", $prev, "\n";
|
2012-04-02 15:56:29 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2012-06-26 08:04:35 +02:00
|
|
|
|
|
2010-09-01 10:50:57 +00:00
|
|
|
|
my $time = time();
|
2012-06-26 08:04:35 +02:00
|
|
|
|
|
2013-02-13 16:49:28 +00:00
|
|
|
|
# Add the build to the database.
|
2009-10-26 17:01:23 +00:00
|
|
|
|
$build = $job->builds->create(
|
2012-06-26 08:04:35 +02:00
|
|
|
|
{ timestamp => $time
|
2009-10-26 17:01:23 +00:00
|
|
|
|
, description => $buildInfo->{description}
|
|
|
|
|
, license => $buildInfo->{license}
|
|
|
|
|
, homepage => $buildInfo->{homepage}
|
|
|
|
|
, maintainers => $buildInfo->{maintainers}
|
2010-05-26 08:03:59 +00:00
|
|
|
|
, maxsilent => $buildInfo->{maxSilent}
|
|
|
|
|
, timeout => $buildInfo->{timeout}
|
2009-10-26 17:01:23 +00:00
|
|
|
|
, nixname => $buildInfo->{nixName}
|
|
|
|
|
, drvpath => $drvPath
|
|
|
|
|
, system => $buildInfo->{system}
|
|
|
|
|
, nixexprinput => $jobset->nixexprinput
|
|
|
|
|
, nixexprpath => $jobset->nixexprpath
|
2014-09-30 00:20:54 +02:00
|
|
|
|
, priority => $buildInfo->{schedulingPriority}
|
2015-05-28 17:39:29 +02:00
|
|
|
|
, finished => 0
|
2013-01-22 14:09:37 +01:00
|
|
|
|
, busy => 0
|
|
|
|
|
, locker => ""
|
2014-09-30 13:48:54 +02:00
|
|
|
|
, iscurrent => 1
|
2015-04-21 07:45:50 +02:00
|
|
|
|
, ischannel => $buildInfo->{isChannel}
|
2009-10-26 17:01:23 +00:00
|
|
|
|
});
|
|
|
|
|
|
2014-09-30 00:20:54 +02:00
|
|
|
|
$build->buildoutputs->create({ name => $_, path => $buildInfo->{outputs}->{$_} })
|
2013-02-13 16:49:28 +00:00
|
|
|
|
foreach @outputNames;
|
|
|
|
|
|
2013-08-27 11:48:02 +02:00
|
|
|
|
$buildMap->{$build->id} = { id => $build->id, jobName => $jobName, new => 1, drvPath => $drvPath };
|
2013-08-14 01:59:29 +02:00
|
|
|
|
$$jobOutPathMap{$jobName . "\t" . $firstOutputPath} = $build->id;
|
2012-06-26 08:04:35 +02:00
|
|
|
|
|
2015-05-28 17:39:29 +02:00
|
|
|
|
print STDERR "added build ${\$build->id} (${\$jobset->project->name}:${\$jobset->name}:$jobName)\n";
|
2009-10-26 17:01:23 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return $build;
|
|
|
|
|
};
|
2010-12-03 08:40:34 +00:00
|
|
|
|
|
|
|
|
|
|
2013-10-04 17:01:47 +02:00
|
|
|
|
1;
|