Skip to content

Commit d534b27

Browse files
Make --keep-going work with drv that don't have a system
1 parent 2d9b213 commit d534b27

File tree

7 files changed

+59
-2
lines changed

7 files changed

+59
-2
lines changed

src/libstore/build-result.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct BuildResult
3636
NotDeterministic,
3737
ResolvesToAlreadyValid,
3838
NoSubstituters,
39+
NoBuilders,
3940
} status = MiscFailure;
4041

4142
/**
@@ -64,6 +65,7 @@ struct BuildResult
6465
case NotDeterministic: return "NotDeterministic";
6566
case ResolvesToAlreadyValid: return "ResolvesToAlreadyValid";
6667
case NoSubstituters: return "NoSubstituters";
68+
case NoBuilders: return "NoBuilders";
6769
default: return "Unknown";
6870
};
6971
}();

src/libstore/build/worker.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ void Worker::run(const Goals & _topGoals)
339339
waitForInput();
340340
else if (awake.empty() && 0U == settings.maxBuildJobs) {
341341
if (getMachines().empty())
342-
throw Error(
342+
throw BadSystem(
343343
R"(
344344
Unable to start any build;
345345
either increase '--max-jobs' or enable remote builds.

src/libstore/store-api.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ MakeError(InvalidPath, Error);
6161
MakeError(Unsupported, Error);
6262
MakeError(SubstituteGone, Error);
6363
MakeError(SubstituterDisabled, Error);
64+
MakeError(BadSystem, Error);
6465

6566
MakeError(InvalidStoreReference, Error);
6667

src/libstore/unix/build/local-derivation-goal.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ Goal::Co LocalDerivationGoal::tryLocalBuild()
264264
buildUser.reset();
265265
worker.permanentFailure = true;
266266
co_return done(BuildResult::InputRejected, {}, std::move(e));
267+
} catch (BadSystem & e) {
268+
outputLocks.unlock();
269+
buildUser.reset();
270+
co_return done(BuildResult::NoBuilders, {}, std::move(e));
267271
}
268272

269273
started();
@@ -532,7 +536,7 @@ void LocalDerivationGoal::startBuilder()
532536

533537
/* Right platform? */
534538
if (!parsedDrv->canBuildLocally(worker.store))
535-
throw Error("a '%s' with features {%s} is required to build '%s', but I am a '%s' with features {%s}",
539+
throw BadSystem("a '%s' with features {%s} is required to build '%s', but I am a '%s' with features {%s}",
536540
drv->platform,
537541
concatStringsSep(", ", parsedDrv->getRequiredSystemFeatures()),
538542
worker.store.printStorePath(drvPath),

tests/functional/keep-going.nix

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
with import ./config.nix;
2+
3+
rec {
4+
5+
# Hack to get the scheduler to do what we want: The `good` derivation can
6+
# only be built after `delay_good` (which takes a long time to build) while
7+
# the others don't have any dependency.
8+
# This means that if we build this with parallelism (`-j2`), then we can be
9+
# reasonably sure that the failing derivations will be scheduled _before_ the
10+
# `good` one (and so we can check that `--keep-going` works fine)
11+
delay_good = mkDerivation {
12+
name = "delay-good";
13+
buildCommand = "sleep 3; touch $out";
14+
};
15+
16+
good = mkDerivation {
17+
name = "good";
18+
buildCommand = "mkdir $out; echo foo > $out/bar";
19+
delay = delay_good;
20+
};
21+
22+
failing = mkDerivation {
23+
name = "failing";
24+
buildCommand = false;
25+
};
26+
27+
requiresFooSystemFeature = mkDerivation {
28+
name = "requires-foo-system-feature";
29+
buildCommand = "mkdir $out; echo foo > $out/bar";
30+
requiredSystemFeatures = [ "foo" ];
31+
};
32+
33+
}

tests/functional/keep-going.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
source common.sh
4+
5+
clearStore
6+
7+
# XXX: These invocations of nix-build should always return 100 according to the manpage, but often return 1
8+
(! nix-build ./keep-going.nix -j2)
9+
(! nix-build ./keep-going.nix -A good -j0) || \
10+
fail "Hello shouldn't have been built because of earlier errors"
11+
12+
clearStore
13+
14+
(! nix-build ./keep-going.nix --keep-going -j2)
15+
nix-build ./keep-going.nix -A good -j0 || \
16+
fail "Hello should have been built despite the errors because of '--keep-going'"

tests/functional/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ suites = [
164164
'debugger.sh',
165165
'extra-sandbox-profile.sh',
166166
'help.sh',
167+
'keep-going.sh',
167168
],
168169
'workdir': meson.current_source_dir(),
169170
},

0 commit comments

Comments
 (0)