ninja-build / ninja

a small build system with a focus on speed
https://ninja-build.org/
Apache License 2.0
11.32k stars 1.61k forks source link

Ninja does not update elapsed time in status for long build commands #2515

Open digit-google opened 1 month ago

digit-google commented 1 month ago

NINJA_STATUS now supports new formatters, such as %e or %w, which print the elapsed time in seconds.

Their usefulness is however severely limited, because Ninja, still only updates its status when a command completes. This results in poor user experience in smart terminals when long commands dominate a build (e.g. Rust link operations). Consider this example build plan:

rule sleep_then_print
  command = sleep 10 && echo done

build all: sleep_then_print

Running the command NINJA_STATUS="[%w] " ninja in a terminal results in the line:

[00:00] sleep 10 && echo done

Being printed for 10 seconds, without the time being updated. Then on completion, it is overwritten into:

[00:10] sleep 10 && echo done
done

The root of the problem is that SubprocessSet::DoWork() is used to wait for events during the build, and only returns when it detects that a process completed, or in the case of a user interruption.

To fix this issue the following changes are proposed:

Note that doing this opens the door to other improvements that could appear later, such as:

jhasse commented 1 month ago

Also see #111.