Skip to content

Commit 973cb64

Browse files
authored
Merge pull request #1359 from Ma27/nix-perl-bindings
Update perl bindings for nix#9863
2 parents 878c0f2 + e499509 commit 973cb64

File tree

18 files changed

+50
-58
lines changed

18 files changed

+50
-58
lines changed

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/hydra-eval-jobs/hydra-eval-jobs.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ static void worker(
185185
!experimentalFeatureSettings.isEnabled(Xp::CaDerivations));
186186

187187
if (drv->querySystem() == "unknown")
188-
throw EvalError("derivation must have a 'system' attribute");
188+
state.error<EvalError>("derivation must have a 'system' attribute").debugThrow();
189189

190190
auto drvPath = state.store->printStorePath(drv->requireDrvPath());
191191

@@ -208,7 +208,7 @@ static void worker(
208208
if (a && state.forceBool(*a->value, a->pos, "while evaluating the `_hydraAggregate` attribute")) {
209209
auto a = v->attrs->get(state.symbols.create("constituents"));
210210
if (!a)
211-
throw EvalError("derivation must have a ‘constituents’ attribute");
211+
state.error<EvalError>("derivation must have a ‘constituents’ attribute").debugThrow();
212212

213213
NixStringContext context;
214214
state.coerceToString(a->pos, *a->value, context, "while evaluating the `constituents` attribute", true, false);
@@ -274,7 +274,7 @@ static void worker(
274274
else if (v->type() == nNull)
275275
;
276276

277-
else throw TypeError("attribute '%s' is %s, which is not supported", attrPath, showType(*v));
277+
else state.error<TypeError>("attribute '%s' is %s, which is not supported", attrPath, showType(*v)).debugThrow();
278278

279279
} catch (EvalError & e) {
280280
auto msg = e.msg();

src/hydra-evaluator/hydra-evaluator.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class JobsetId {
3838
friend bool operator!= (const JobsetId & lhs, const JobsetName & rhs);
3939

4040
std::string display() const {
41-
return str(format("%1%:%2% (jobset#%3%)") % project % jobset % id);
41+
return boost::str(boost::format("%1%:%2% (jobset#%3%)") % project % jobset % id);
4242
}
4343
};
4444
bool operator==(const JobsetId & lhs, const JobsetId & rhs)

src/hydra-queue-runner/queue-monitor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ bool State::getQueuedBuilds(Connection & conn,
294294
try {
295295
createBuild(build);
296296
} catch (Error & e) {
297-
e.addTrace({}, hintfmt("while loading build %d: ", build->id));
297+
e.addTrace({}, HintFmt("while loading build %d: ", build->id));
298298
throw;
299299
}
300300

src/lib/Hydra/Base/Controller/NixChannel.pm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use strict;
44
use warnings;
55
use base 'Hydra::Base::Controller::REST';
66
use List::SomeUtils qw(any);
7-
use Nix::Store;
87
use Hydra::Helper::Nix;
98
use Hydra::Helper::CatalystUtils;
109

@@ -30,7 +29,7 @@ sub getChannelData {
3029
my $outputs = {};
3130
foreach my $output (@outputs) {
3231
my $outPath = $output->get_column("outpath");
33-
next if $checkValidity && !isValidPath($outPath);
32+
next if $checkValidity && !$MACHINE_LOCAL_STORE->isValidPath($outPath);
3433
$outputs->{$output->get_column("outname")} = $outPath;
3534
push @storePaths, $outPath;
3635
# Put the system type in the manifest (for top-level

src/lib/Hydra/Controller/Build.pm

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ use File::Basename;
1010
use File::LibMagic;
1111
use File::stat;
1212
use Data::Dump qw(dump);
13-
use Nix::Store;
14-
use Nix::Config;
1513
use List::SomeUtils qw(all);
1614
use Encode;
1715
use JSON::PP;
@@ -82,9 +80,9 @@ sub build_GET {
8280
# false because `$_->path` will be empty
8381
$c->stash->{available} =
8482
$c->stash->{isLocalStore}
85-
? all { $_->path && isValidPath($_->path) } $build->buildoutputs->all
83+
? all { $_->path && $MACHINE_LOCAL_STORE->isValidPath($_->path) } $build->buildoutputs->all
8684
: 1;
87-
$c->stash->{drvAvailable} = isValidPath $build->drvpath;
85+
$c->stash->{drvAvailable} = $MACHINE_LOCAL_STORE->isValidPath($build->drvpath);
8886

8987
if ($build->finished && $build->iscachedbuild) {
9088
my $path = ($build->buildoutputs)[0]->path or undef;
@@ -308,7 +306,7 @@ sub output : Chained('buildChain') PathPart Args(1) {
308306
error($c, "This build is not finished yet.") unless $build->finished;
309307
my $output = $build->buildoutputs->find({name => $outputName});
310308
notFound($c, "This build has no output named ‘$outputName") unless defined $output;
311-
gone($c, "Output is no longer available.") unless isValidPath $output->path;
309+
gone($c, "Output is no longer available.") unless $MACHINE_LOCAL_STORE->isValidPath($output->path);
312310

313311
$c->response->header('Content-Disposition', "attachment; filename=\"build-${\$build->id}-${\$outputName}.nar.bz2\"");
314312
$c->stash->{current_view} = 'NixNAR';
@@ -425,15 +423,15 @@ sub getDependencyGraph {
425423
};
426424
$$done{$path} = $node;
427425
my @refs;
428-
foreach my $ref (queryReferences($path)) {
426+
foreach my $ref ($MACHINE_LOCAL_STORE->queryReferences($path)) {
429427
next if $ref eq $path;
430428
next unless $runtime || $ref =~ /\.drv$/;
431429
getDependencyGraph($self, $c, $runtime, $done, $ref);
432430
push @refs, $ref;
433431
}
434432
# Show in reverse topological order to flatten the graph.
435433
# Should probably do a proper BFS.
436-
my @sorted = reverse topoSortPaths(@refs);
434+
my @sorted = reverse $MACHINE_LOCAL_STORE->topoSortPaths(@refs);
437435
$node->{refs} = [map { $$done{$_} } @sorted];
438436
}
439437

@@ -446,7 +444,7 @@ sub build_deps : Chained('buildChain') PathPart('build-deps') {
446444
my $build = $c->stash->{build};
447445
my $drvPath = $build->drvpath;
448446

449-
error($c, "Derivation no longer available.") unless isValidPath $drvPath;
447+
error($c, "Derivation no longer available.") unless $MACHINE_LOCAL_STORE->isValidPath($drvPath);
450448

451449
$c->stash->{buildTimeGraph} = getDependencyGraph($self, $c, 0, {}, $drvPath);
452450

@@ -461,7 +459,7 @@ sub runtime_deps : Chained('buildChain') PathPart('runtime-deps') {
461459

462460
requireLocalStore($c);
463461

464-
error($c, "Build outputs no longer available.") unless all { isValidPath($_) } @outPaths;
462+
error($c, "Build outputs no longer available.") unless all { $MACHINE_LOCAL_STORE->isValidPath($_) } @outPaths;
465463

466464
my $done = {};
467465
$c->stash->{runtimeGraph} = [ map { getDependencyGraph($self, $c, 1, $done, $_) } @outPaths ];
@@ -481,7 +479,7 @@ sub nix : Chained('buildChain') PathPart('nix') CaptureArgs(0) {
481479
if (isLocalStore) {
482480
foreach my $out ($build->buildoutputs) {
483481
notFound($c, "Path " . $out->path . " is no longer available.")
484-
unless isValidPath($out->path);
482+
unless $MACHINE_LOCAL_STORE->isValidPath($out->path);
485483
}
486484
}
487485

src/lib/Hydra/Controller/Root.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ sub narinfo :Path :Args(StrMatch[NARINFO_REGEX]) {
395395
my ($hash) = $narinfo =~ NARINFO_REGEX;
396396

397397
die("Hash length was not 32") if length($hash) != 32;
398-
my $path = queryPathFromHashPart($hash);
398+
my $path = $MACHINE_LOCAL_STORE->queryPathFromHashPart($hash);
399399

400400
if (!$path) {
401401
$c->response->status(404);

src/lib/Hydra/Helper/Nix.pm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ our @EXPORT = qw(
4040
registerRoot
4141
restartBuilds
4242
run
43+
$MACHINE_LOCAL_STORE
4344
);
4445

46+
our $MACHINE_LOCAL_STORE = Nix::Store->new();
47+
4548

4649
sub getHydraHome {
4750
my $dir = $ENV{"HYDRA_HOME"} or die "The HYDRA_HOME directory does not exist!\n";
@@ -494,7 +497,7 @@ sub restartBuilds {
494497
$builds = $builds->search({ finished => 1 });
495498

496499
foreach my $build ($builds->search({}, { columns => ["drvpath"] })) {
497-
next if !isValidPath($build->drvpath);
500+
next if !$MACHINE_LOCAL_STORE->isValidPath($build->drvpath);
498501
registerRoot $build->drvpath;
499502
}
500503

src/lib/Hydra/Plugin/BazaarInput.pm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use Digest::SHA qw(sha256_hex);
77
use File::Path;
88
use Hydra::Helper::Exec;
99
use Hydra::Helper::Nix;
10-
use Nix::Store;
1110

1211
sub supportedInputTypes {
1312
my ($self, $inputTypes) = @_;
@@ -38,9 +37,9 @@ sub fetchInput {
3837
(my $cachedInput) = $self->{db}->resultset('CachedBazaarInputs')->search(
3938
{uri => $uri, revision => $revision});
4039

41-
addTempRoot($cachedInput->storepath) if defined $cachedInput;
40+
$MACHINE_LOCAL_STORE->addTempRoot($cachedInput->storepath) if defined $cachedInput;
4241

43-
if (defined $cachedInput && isValidPath($cachedInput->storepath)) {
42+
if (defined $cachedInput && $MACHINE_LOCAL_STORE->isValidPath($cachedInput->storepath)) {
4443
$storePath = $cachedInput->storepath;
4544
$sha256 = $cachedInput->sha256hash;
4645
} else {
@@ -58,7 +57,7 @@ sub fetchInput {
5857
($sha256, $storePath) = split ' ', $stdout;
5958

6059
# FIXME: time window between nix-prefetch-bzr and addTempRoot.
61-
addTempRoot($storePath);
60+
$MACHINE_LOCAL_STORE->addTempRoot($storePath);
6261

6362
$self->{db}->txn_do(sub {
6463
$self->{db}->resultset('CachedBazaarInputs')->create(

src/lib/Hydra/Plugin/DarcsInput.pm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use Digest::SHA qw(sha256_hex);
77
use File::Path;
88
use Hydra::Helper::Exec;
99
use Hydra::Helper::Nix;
10-
use Nix::Store;
1110

1211
sub supportedInputTypes {
1312
my ($self, $inputTypes) = @_;
@@ -58,7 +57,7 @@ sub fetchInput {
5857
{uri => $uri, revision => $revision},
5958
{rows => 1});
6059

61-
if (defined $cachedInput && isValidPath($cachedInput->storepath)) {
60+
if (defined $cachedInput && $MACHINE_LOCAL_STORE->isValidPath($cachedInput->storepath)) {
6261
$storePath = $cachedInput->storepath;
6362
$sha256 = $cachedInput->sha256hash;
6463
$revision = $cachedInput->revision;
@@ -75,8 +74,8 @@ sub fetchInput {
7574
die "darcs changes --count failed" if $? != 0;
7675

7776
system "rm", "-rf", "$tmpDir/export/_darcs";
78-
$storePath = addToStore("$tmpDir/export", 1, "sha256");
79-
$sha256 = queryPathHash($storePath);
77+
$storePath = $MACHINE_LOCAL_STORE->addToStore("$tmpDir/export", 1, "sha256");
78+
$sha256 = $MACHINE_LOCAL_STORE->queryPathHash($storePath);
8079
$sha256 =~ s/sha256://;
8180

8281
$self->{db}->txn_do(sub {

0 commit comments

Comments
 (0)