Skip to content

Commit

Permalink
Make --keep-going work with drv that don't have a system
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed Jan 10, 2025
1 parent 2d9b213 commit 3d26e2f
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/libstore/build-result.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct BuildResult
NotDeterministic,
ResolvesToAlreadyValid,
NoSubstituters,
NoBuilders,
} status = MiscFailure;

/**
Expand Down Expand Up @@ -64,6 +65,7 @@ struct BuildResult
case NotDeterministic: return "NotDeterministic";
case ResolvesToAlreadyValid: return "ResolvesToAlreadyValid";
case NoSubstituters: return "NoSubstituters";
case NoBuilders: return "NoBuilders";
default: return "Unknown";
};
}();
Expand Down
1 change: 1 addition & 0 deletions src/libstore/store-api.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ MakeError(InvalidPath, Error);
MakeError(Unsupported, Error);
MakeError(SubstituteGone, Error);
MakeError(SubstituterDisabled, Error);
MakeError(BadSystem, Error);

MakeError(InvalidStoreReference, Error);

Expand Down
6 changes: 5 additions & 1 deletion src/libstore/unix/build/local-derivation-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ Goal::Co LocalDerivationGoal::tryLocalBuild()
buildUser.reset();
worker.permanentFailure = true;
co_return done(BuildResult::InputRejected, {}, std::move(e));
} catch (BadSystem & e) {
outputLocks.unlock();
buildUser.reset();
co_return done(BuildResult::NoBuilders, {}, std::move(e));
}

started();
Expand Down Expand Up @@ -532,7 +536,7 @@ void LocalDerivationGoal::startBuilder()

/* Right platform? */
if (!parsedDrv->canBuildLocally(worker.store))
throw Error("a '%s' with features {%s} is required to build '%s', but I am a '%s' with features {%s}",
throw BadSystem("a '%s' with features {%s} is required to build '%s', but I am a '%s' with features {%s}",
drv->platform,
concatStringsSep(", ", parsedDrv->getRequiredSystemFeatures()),
worker.store.printStorePath(drvPath),
Expand Down
33 changes: 33 additions & 0 deletions tests/functional/keep-going.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
with import ./config.nix;

rec {

# Hack to get the scheduler to do what we want: The `good` derivation can
# only be built after `delay_good` (which takes a long time to build) while
# the others don't have any dependency.
# This means that if we build this with parallelism (`-j2`), then we can be
# reasonably sure that the failing derivations will be scheduled _before_ the
# `good` one (and so we can check that `--keep-going` works fine)
delay_good = mkDerivation {
name = "delay-good";
buildCommand = "sleep 3; touch $out";
};

good = mkDerivation {
name = "good";
buildCommand = "mkdir $out; echo foo > $out/bar";
delay = delay_good;
};

failing = mkDerivation {
name = "failing";
buildCommand = false;
};

requiresFooSystemFeature = mkDerivation {
name = "requires-foo-system-feature";
buildCommand = "mkdir $out; echo foo > $out/bar";
requiredSystemFeatures = [ "foo" ];
};

}
14 changes: 14 additions & 0 deletions tests/functional/keep-going.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
source common.sh

clearStore

# XXX: These invocations of nix-build should always return 100 according to the manpage, but often return 1
(! nix-build ./keep-going.nix -j2)
(! nix-build ./keep-going.nix -A good -j0) || \
fail "Hello shouldn't have been built because of earlier errors"

clearStore

(! nix-build ./keep-going.nix --keep-going -j2)
nix-build ./keep-going.nix -A good -j0 || \
fail "Hello should have been built despite the errors because of '--keep-going'"
1 change: 1 addition & 0 deletions tests/functional/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ suites = [
'debugger.sh',
'extra-sandbox-profile.sh',
'help.sh',
'keep-going.sh',
],
'workdir': meson.current_source_dir(),
},
Expand Down

0 comments on commit 3d26e2f

Please sign in to comment.