Handle builds with multiple outputs correctly in Hydra channels

This commit is contained in:
Eelco Dolstra 2013-10-07 17:06:17 +02:00
parent 5ccff14f6b
commit 0ec03aa0f4
5 changed files with 88 additions and 36 deletions

View file

@ -41,6 +41,7 @@ sub nix : Chained('get_builds') PathPart('channel') CaptureArgs(1) {
->search_literal("exists (select 1 from buildproducts where build = me.id and type = 'nix-build')")
->search({}, { columns => [@buildListColumns, 'drvpath', 'description', 'homepage']
, join => ["buildoutputs"]
, order_by => ["me.id", "buildoutputs.name"]
, '+select' => ['buildoutputs.path', 'buildoutputs.name'], '+as' => ['outpath', 'outname'] });
}
else {

View file

@ -14,20 +14,36 @@ sub getChannelData {
my @storePaths = ();
$c->stash->{nixPkgs} = [];
foreach my $build ($c->stash->{channelBuilds}->all) {
my $outPath = $build->get_column("outpath");
my $outName = $build->get_column("outname");
my @builds = $c->stash->{channelBuilds}->all;
for (my $n = 0; $n < scalar @builds; ) {
# Since channelData is a join of Builds and BuildOutputs, we
# need to gather the rows that belong to a single build.
my $build = $builds[$n++];
my @outputs = ($build);
push @outputs, $builds[$n++] while $n < scalar @builds && $builds[$n]->id == $build->id;
@outputs = grep { $_->get_column("outpath") } @outputs;
my $outputs = {};
foreach my $output (@outputs) {
my $outPath = $output->get_column("outpath");
next if $checkValidity && !isValidPath($outPath);
$outputs->{$output->get_column("outname")} = $outPath;
push @storePaths, $outPath;
my $pkgName = $build->nixname . "-" . $build->system . "-" . $build->id . ($outName ne "out" ? "-" . $outName : "");
push @{$c->stash->{nixPkgs}}, { build => $build, name => $pkgName, outPath => $outPath, outName => $outName };
# Put the system type in the manifest (for top-level paths) as
# a hint to the binary patch generator. (It shouldn't try to
# generate patches between builds for different systems.) It
# would be nice if Nix stored this info for every path but it
# doesn't.
# Put the system type in the manifest (for top-level
# paths) as a hint to the binary patch generator. (It
# shouldn't try to generate patches between builds for
# different systems.) It would be nice if Nix stored this
# info for every path but it doesn't.
$c->stash->{systemForPath}->{$outPath} = $build->system;
};
}
next if !%$outputs;
my $pkgName = $build->nixname . "-" . $build->system . "-" . $build->id;
push @{$c->stash->{nixPkgs}}, { build => $build, name => $pkgName, outputs => $outputs };
}
$c->stash->{storePaths} = [@storePaths];
}

View file

@ -182,6 +182,7 @@ sub nix : Chained('eval') PathPart('channel') CaptureArgs(0) {
->search({ finished => 1, buildstatus => 0 },
{ columns => [@buildListColumns, 'drvpath', 'description', 'homepage']
, join => ["buildoutputs"]
, order_by => ["build.id", "buildoutputs.name"]
, '+select' => ['buildoutputs.path', 'buildoutputs.name'], '+as' => ['outpath', 'outname'] });
}

View file

@ -23,34 +23,69 @@ sub process {
foreach my $pkg (@{$c->stash->{nixPkgs}}) {
my $build = $pkg->{build};
my $s = "";
$s .= " # $pkg->{name}\n";
$s .= " ${\escape $build->get_column('job')} = {\n";
$s .= " type = \"derivation\";\n";
$s .= " name = ${\escape ($build->get_column('releasename') or $build->nixname)};\n";
$s .= " system = ${\escape $build->system};\n";
$s .= " outPath = ${\escape $pkg->{outPath}};\n";
$s .= " meta = {\n";
$s .= " description = ${\escape $build->description};\n"
if $build->description;
$s .= " longDescription = ${\escape $build->longdescription};\n"
if $build->longdescription;
$s .= " license = ${\escape $build->license};\n"
if $build->license;
$s .= " maintainers = ${\escape $build->maintainers};\n"
if $build->maintainers;
$s .= " };\n";
$s .= " };\n\n";
$perSystem{$build->system} .= $s;
$perSystem{$build->system}->{$build->get_column('job')} = $pkg;
}
my $res = "{ system ? builtins.currentSystem }:\n\n";
my $res = <<EOF;
{ system ? builtins.currentSystem }:
let
mkFakeDerivation = attrs: outputs:
let
outputNames = builtins.attrNames outputs;
common = attrs // outputsSet //
{ type = "derivation";
outputs = outputNames;
all = outputsList;
};
outputToAttrListElement = outputName:
{ name = outputName;
value = common // {
inherit outputName;
outPath = builtins.getAttr outputName outputs;
};
};
outputsList = map outputToAttrListElement outputNames;
outputsSet = builtins.listToAttrs outputsList;
in outputsSet;
in
EOF
my $first = 1;
foreach my $system (keys %perSystem) {
$res .= "else " if !$first;
$res .= "if system == ${\escape $system} then {\n\n";
$res .= $perSystem{$system};
foreach my $job (keys $perSystem{$system}) {
my $pkg = $perSystem{$system}->{$job};
my $build = $pkg->{build};
$res .= " # Hydra build ${\$build->id}\n";
my $attr = $build->get_column('job');
$attr =~ s/\./-/g;
$res .= " ${\escape $attr} = (mkFakeDerivation {\n";
$res .= " type = \"derivation\";\n";
$res .= " name = ${\escape ($build->get_column('releasename') or $build->nixname)};\n";
$res .= " system = ${\escape $build->system};\n";
$res .= " meta = {\n";
$res .= " description = ${\escape $build->description};\n"
if $build->description;
$res .= " longDescription = ${\escape $build->longdescription};\n"
if $build->longdescription;
$res .= " license = ${\escape $build->license};\n"
if $build->license;
$res .= " maintainers = ${\escape $build->maintainers};\n"
if $build->maintainers;
$res .= " };\n";
$res .= " } {\n";
my @outputNames = sort (keys $pkg->{outputs});
$res .= " ${\escape $_} = ${\escape $pkg->{outputs}->{$_}};\n" foreach @outputNames;
my $out = defined $pkg->{outputs}->{"out"} ? "out" : $outputNames[0];
$res .= " }).$out;\n\n";
}
$res .= "}\n\n";
$first = 0;
}

View file

@ -60,7 +60,6 @@ install the package simply by clicking on the packages below.</p>
[% ELSE %]
[% HTML.escape(b.description) %]
[% END %]
[% IF pkg.outName != 'out' %] [[% pkg.outName %]][% END %]
</td>
</tr>