ninja: Add fail fast mode that immediately stops execution of running jobs after failures.

Currently there is option -k N which does not start new jobs when there were N errors. However sometimes users would like to immediately stop execution after failures, and free computing resources – this is especially useful for big projects (thousands of jobs, distributed using tools like distcc).

My proposal is to add fail fast option (e.g. -K), which would immediately stop further execution of all running jobs after reaching -k amount of failures.

Minimal example:

$ cat build.ninja
rule delay
  command = sleep 5

rule failure
  command = exit 1

build foo1: delay
build foo2: failure

$ time ninja
[1/2] exit 1
FAILED: foo2
exit 1
[2/2] sleep 5
ninja: build stopped: subcommand failed.

real    0m5.070s
user    0m0.000s
sys     0m0.078s

I have already been experimenting with source code, and easiest change to me was to send a SIGINT to itself in Builder::Build:

$ time ninja/build-cmake/ninja -K
[1/2] exit 1
FAILED: foo2
exit 1
Fail fast mode activated. No more failures allowed. SIGINT self...
: No such file or directory
ninja: build stopped: interrupted by user.

real    0m0.046s
user    0m0.000s
sys     0m0.031s

I am eager to create a PR for this, however please suggest if such feature can be accepted, and direction of the implementation.

edit: given ninja is the tool name – feature could be named seppuku.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 4
  • Comments: 17 (2 by maintainers)

Most upvoted comments

Hello! Is there anyone, who could test this feature on Windows/MacOS? I do not have those environments, unfortunately.

I’ll give it a shot

In the same way that Ctrl+C’ing ninja might not be safe: Jobs just might just not handle it correctly.

Now that I think of it, the frontend could just Ctrl+C ninja on the first failure. So I’m tagging this as a frontend bug.