From c645fa55ff26400e90c9936a5dfe80d31c6b7840 Mon Sep 17 00:00:00 2001 From: Rob Vermaas Date: Tue, 8 Feb 2011 13:11:08 +0000 Subject: [PATCH] initial bzr support --- src/lib/Hydra/Controller/Admin.pm | 3 ++ src/lib/Hydra/Helper/AddBuilds.pm | 84 +++++++++++++++++++++++++++++-- src/root/common.tt | 2 + src/sql/hydra.sql | 9 ++++ 4 files changed, 93 insertions(+), 5 deletions(-) diff --git a/src/lib/Hydra/Controller/Admin.pm b/src/lib/Hydra/Controller/Admin.pm index 29b0d9f9..eb1c35fa 100644 --- a/src/lib/Hydra/Controller/Admin.pm +++ b/src/lib/Hydra/Controller/Admin.pm @@ -314,6 +314,9 @@ sub clearvcscache : Chained('admin') Path('clear-vcs-cache') Args(0) { print "Clearing subversion cache\n"; $c->model('DB::CachedSubversionInputs')->delete_all; + print "Clearing bazaar cache\n"; + $c->model('DB::CachedBazaarInputs')->delete_all; + $c->res->redirect("/admin"); } diff --git a/src/lib/Hydra/Helper/AddBuilds.pm b/src/lib/Hydra/Helper/AddBuilds.pm index 791ae17f..c6a016e2 100644 --- a/src/lib/Hydra/Helper/AddBuilds.pm +++ b/src/lib/Hydra/Helper/AddBuilds.pm @@ -381,6 +381,77 @@ sub fetchInputGit { }; } +sub fetchInputBazaar { + my ($db, $project, $jobset, $name, $type, $value, $checkout) = @_; + + my $uri = $value; + + my $sha256; + my $storePath; + + my $stdout; my $stderr; + my $clonePath; + mkpath(scmPath); + $clonePath = scmPath . "/" . sha256_hex($uri); + + if (! -d $clonePath) { + (my $res, $stdout, $stderr) = captureStdoutStderr(600, + ("bzr", "branch", $uri, $clonePath)); + die "Error cloning bazaar branch at `$uri':\n$stderr" unless $res; + } + + chdir $clonePath or die $!; + (my $res, $stdout, $stderr) = captureStdoutStderr(600, + ("bzr", "pull")); + die "Error pulling latest change bazaar branch at `$uri':\n$stderr" unless $res; + + # First figure out the last-modified revision of the URI. + my @cmd = (["bzr", "revno"], + "|", ["sed", 's/^ *\([0-9]*\).*/\1/']); + + die "Cannot get head revision of Bazaar branch at `$uri':\n$stderr" + unless IPC::Run::run(@cmd, \$stdout, \$stderr); + my $revision = $stdout; chomp $revision; + die unless $revision =~ /^\d+$/; + + (my $cachedInput) = $db->resultset('CachedBazaarInputs')->search( + {uri => $uri, revision => $revision}); + + if (defined $cachedInput && isValidPath($cachedInput->storepath)) { + $storePath = $cachedInput->storepath; + $sha256 = $cachedInput->sha256hash; + } else { + + # Then download this revision into the store. + print STDERR "checking out Bazaar input ", $name, " from $uri revision $revision\n"; + $ENV{"NIX_HASH_ALGO"} = "sha256"; + $ENV{"PRINT_PATH"} = "1"; + $ENV{"NIX_PREFETCH_BZR_LEAVE_DOT_BZR"} = "$checkout"; + + (my $res, $stdout, $stderr) = captureStdoutStderr(600, + ("nix-prefetch-bzr", $clonePath, $revision)); + die "Cannot check out Bazaar branch `$uri':\n$stderr" unless $res; + + ($sha256, $storePath) = split ' ', $stdout; + + txn_do($db, sub { + $db->resultset('CachedBazaarInputs')->create( + { uri => $uri + , revision => $revision + , sha256hash => $sha256 + , storepath => $storePath + }); + }); + } + + return + { type => $type + , uri => $uri + , storePath => $storePath + , sha256hash => $sha256 + , revision => $revision + };} + sub fetchInputHg { my ($db, $project, $jobset, $name, $type, $value) = @_; @@ -480,17 +551,20 @@ sub fetchInput { elsif ($type eq "hg") { return fetchInputHg($db, $project, $jobset, $name, $type, $value); } - + elsif ($type eq "bzr") { + return fetchInputBazaar($db, $project, $jobset, $name, $type, $value, 0); + } + elsif ($type eq "bzr-checkout") { + return fetchInputBazaar($db, $project, $jobset, $name, $type, $value, 1); + } elsif ($type eq "string") { die unless defined $value; return {type => $type, value => $value}; - } - + } elsif ($type eq "boolean") { die unless defined $value && ($value eq "true" || $value eq "false"); return {type => $type, value => $value}; - } - + } else { die "Input `" . $name . "' has unknown type `$type'."; } diff --git a/src/root/common.tt b/src/root/common.tt index e2eba001..5672d782 100644 --- a/src/root/common.tt +++ b/src/root/common.tt @@ -6,6 +6,8 @@ [% inputTypes = { "svn" = "Subversion export" , "svn-checkout" = "Subversion checkout" + , "bzr" = "Bazaar export" + , "bzr-checkout" = "Bazaar checkout" , "git" = "Git checkout" , "tarball" = "Download of a tarball" , "hg" = "Mercurial checkout" diff --git a/src/sql/hydra.sql b/src/sql/hydra.sql index c8de1997..c78081b3 100644 --- a/src/sql/hydra.sql +++ b/src/sql/hydra.sql @@ -315,6 +315,14 @@ create table CachedSubversionInputs ( primary key (uri, revision) ); +create table CachedBazaarInputs ( + uri text not null, + revision integer not null, + sha256hash text not null, + storePath text not null, + primary key (uri, revision) +); + create table CachedGitInputs ( uri text not null, branch text not null, @@ -530,6 +538,7 @@ create index IndexBuildsOnDrvPath on Builds(drvPath); create index IndexCachedHgInputsOnHash on CachedHgInputs(uri, branch, sha256hash); create index IndexCachedGitInputsOnHash on CachedGitInputs(uri, branch, sha256hash); create index IndexCachedSubversionInputsOnUriRevision on CachedSubversionInputs(uri, revision); +create index IndexCachedBazaarInputsOnUriRevision on CachedBazaarInputs(uri, revision); create index IndexJobsetEvalMembersOnBuild on JobsetEvalMembers(build); create index IndexJobsetInputAltsOnInput on JobsetInputAlts(project, jobset, input); create index IndexJobsetInputAltsOnJobset on JobsetInputAlts(project, jobset);