From 38d50806b959856cd64e112e3708151d90e1210a Mon Sep 17 00:00:00 2001 From: Rob Vermaas Date: Tue, 7 Sep 2010 11:29:52 +0000 Subject: [PATCH] hydra: if evaluator sees cached build, also add the buildproducts --- src/lib/Hydra/Helper/AddBuilds.pm | 63 +++++++++++++++++++++++++++ src/lib/Hydra/Helper/CatalystUtils.pm | 4 +- src/script/hydra_build.pl | 59 +------------------------ 3 files changed, 66 insertions(+), 60 deletions(-) diff --git a/src/lib/Hydra/Helper/AddBuilds.pm b/src/lib/Hydra/Helper/AddBuilds.pm index 6e4eeaaa..5f861d2e 100644 --- a/src/lib/Hydra/Helper/AddBuilds.pm +++ b/src/lib/Hydra/Helper/AddBuilds.pm @@ -586,6 +586,68 @@ sub evalJobs { return ($jobs, $nixExprInput); } +sub addBuildProducts { + my ($db, $build) = @_; + + my $outPath = $build->outpath; + my $productnr = 1; + + if (-e "$outPath/nix-support/hydra-build-products") { + open LIST, "$outPath/nix-support/hydra-build-products" or die; + while () { + /^([\w\-]+)\s+([\w\-]+)\s+(\S+)(\s+(\S+))?$/ or next; + my $type = $1; + my $subtype = $2 eq "none" ? "" : $2; + my $path = $3; + my $defaultPath = $5; + next unless -e $path; + + my $fileSize, my $sha1, my $sha256; + + # !!! validate $path, $defaultPath + + if (-f $path) { + my $st = stat($path) or die "cannot stat $path: $!"; + $fileSize = $st->size; + + $sha1 = `nix-hash --flat --type sha1 $path` + or die "cannot hash $path: $?";; + chomp $sha1; + + $sha256 = `nix-hash --flat --type sha256 $path` + or die "cannot hash $path: $?";; + chomp $sha256; + } + + my $name = $path eq $outPath ? "" : basename $path; + + $db->resultset('BuildProducts')->create( + { build => $build->id + , productnr => $productnr++ + , type => $type + , subtype => $subtype + , path => $path + , filesize => $fileSize + , sha1hash => $sha1 + , sha256hash => $sha256 + , name => $name + , defaultpath => $defaultPath + }); + } + close LIST; + } + + else { + $db->resultset('BuildProducts')->create( + { build => $build->id + , productnr => $productnr++ + , type => "nix-build" + , subtype => "" + , path => $outPath + , name => $build->nixname + }); + } +} # Check whether to add the build described by $buildInfo. sub checkBuild { @@ -666,6 +728,7 @@ sub checkBuild { , errormsg => "" , releasename => getReleaseName($outPath) }); + addBuildProducts($build); } else { print STDERR "added to queue as build ", $build->id, "\n"; $build->create_related('buildschedulinginfo', diff --git a/src/lib/Hydra/Helper/CatalystUtils.pm b/src/lib/Hydra/Helper/CatalystUtils.pm index 68c870a8..d36dd706 100644 --- a/src/lib/Hydra/Helper/CatalystUtils.pm +++ b/src/lib/Hydra/Helper/CatalystUtils.pm @@ -117,8 +117,8 @@ sub getChannelData { my @storePaths = (); foreach my $build (@builds2) { - next unless isValidPath($build->outpath); - if (isValidPath($build->drvpath)) { + next unless Hydra::Helper::Nix::isValidPath($build->outpath); + if (Hydra::Helper::Nix::isValidPath($build->drvpath)) { # Adding `drvpath' implies adding `outpath' because of the # `--include-outputs' flag passed to `nix-store'. push @storePaths, $build->drvpath; diff --git a/src/script/hydra_build.pl b/src/script/hydra_build.pl index c89c72b3..66281c26 100755 --- a/src/script/hydra_build.pl +++ b/src/script/hydra_build.pl @@ -383,64 +383,7 @@ sub doBuild { }); if ($buildStatus == 0) { - - my $productnr = 1; - - if (-e "$outPath/nix-support/hydra-build-products") { - open LIST, "$outPath/nix-support/hydra-build-products" or die; - while () { - /^([\w\-]+)\s+([\w\-]+)\s+(\S+)(\s+(\S+))?$/ or next; - my $type = $1; - my $subtype = $2 eq "none" ? "" : $2; - my $path = $3; - my $defaultPath = $5; - next unless -e $path; - - my $fileSize, my $sha1, my $sha256; - - # !!! validate $path, $defaultPath - - if (-f $path) { - my $st = stat($path) or die "cannot stat $path: $!"; - $fileSize = $st->size; - - $sha1 = `nix-hash --flat --type sha1 $path` - or die "cannot hash $path: $?";; - chomp $sha1; - - $sha256 = `nix-hash --flat --type sha256 $path` - or die "cannot hash $path: $?";; - chomp $sha256; - } - - my $name = $path eq $outPath ? "" : basename $path; - - $db->resultset('BuildProducts')->create( - { build => $build->id - , productnr => $productnr++ - , type => $type - , subtype => $subtype - , path => $path - , filesize => $fileSize - , sha1hash => $sha1 - , sha256hash => $sha256 - , name => $name - , defaultpath => $defaultPath - }); - } - close LIST; - } - - else { - $db->resultset('BuildProducts')->create( - { build => $build->id - , productnr => $productnr++ - , type => "nix-build" - , subtype => "" - , path => $outPath - , name => $build->nixname - }); - } + addBuildProducts($db, $build); } $build->schedulingInfo->delete;