2013-05-25 15:36:58 -04:00
|
|
|
package Hydra::Plugin::BazaarInput;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use parent 'Hydra::Plugin';
|
|
|
|
use Digest::SHA qw(sha256_hex);
|
|
|
|
use File::Path;
|
|
|
|
use Hydra::Helper::Nix;
|
|
|
|
use Nix::Store;
|
|
|
|
|
|
|
|
sub supportedInputTypes {
|
|
|
|
my ($self, $inputTypes) = @_;
|
|
|
|
$inputTypes->{'bzr'} = 'Bazaar export';
|
|
|
|
$inputTypes->{'bzr-checkout'} = 'Bazaar checkout';
|
|
|
|
}
|
|
|
|
|
|
|
|
sub fetchInput {
|
|
|
|
my ($self, $type, $name, $value) = @_;
|
|
|
|
|
|
|
|
return undef if $type ne "bzr" && $type ne "bzr-checkout";
|
|
|
|
|
|
|
|
my $uri = $value;
|
|
|
|
|
|
|
|
my $sha256;
|
|
|
|
my $storePath;
|
|
|
|
|
|
|
|
my $stdout; my $stderr;
|
|
|
|
|
|
|
|
# First figure out the last-modified revision of the URI.
|
2013-07-22 20:42:17 +02:00
|
|
|
my @cmd = (["bzr", "revno", $uri], "|", ["sed", 's/^ *\([0-9]*\).*/\1/']);
|
2013-05-25 15:36:58 -04:00
|
|
|
|
|
|
|
IPC::Run::run(@cmd, \$stdout, \$stderr);
|
|
|
|
die "cannot get head revision of Bazaar branch at `$uri':\n$stderr" if $?;
|
|
|
|
my $revision = $stdout; chomp $revision;
|
|
|
|
die unless $revision =~ /^\d+$/;
|
|
|
|
|
|
|
|
(my $cachedInput) = $self->{db}->resultset('CachedBazaarInputs')->search(
|
|
|
|
{uri => $uri, revision => $revision});
|
|
|
|
|
2015-10-09 12:50:23 +02:00
|
|
|
addTempRoot($cachedInput->storepath) if defined $cachedInput;
|
|
|
|
|
2013-05-25 15:36:58 -04:00
|
|
|
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"} = $type eq "bzr-checkout" ? "1" : "0";
|
|
|
|
|
2013-12-11 17:34:30 +01:00
|
|
|
(my $res, $stdout, $stderr) = captureStdoutStderr(1200,
|
2013-07-22 20:42:17 +02:00
|
|
|
"nix-prefetch-bzr", $uri, $revision);
|
2013-05-25 15:36:58 -04:00
|
|
|
die "cannot check out Bazaar branch `$uri':\n$stderr" if $res;
|
|
|
|
|
|
|
|
($sha256, $storePath) = split ' ', $stdout;
|
|
|
|
|
2015-10-09 12:50:23 +02:00
|
|
|
# FIXME: time window between nix-prefetch-bzr and addTempRoot.
|
|
|
|
addTempRoot($storePath);
|
|
|
|
|
2020-04-10 18:13:36 +02:00
|
|
|
$self->{db}->txn_do(sub {
|
2013-05-25 15:36:58 -04:00
|
|
|
$self->{db}->resultset('CachedBazaarInputs')->create(
|
|
|
|
{ uri => $uri
|
|
|
|
, revision => $revision
|
|
|
|
, sha256hash => $sha256
|
|
|
|
, storepath => $storePath
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
{ uri => $uri
|
|
|
|
, storePath => $storePath
|
|
|
|
, sha256hash => $sha256
|
|
|
|
, revision => $revision
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|