From 6943f0537299e0d572b38b7d1e0562f0c13cb68e Mon Sep 17 00:00:00 2001 From: yannicklm Date: Fri, 14 Dec 2012 22:25:51 +0100 Subject: NINJA_STATUS: add support of `%p` for percentage --- doc/manual.asciidoc | 1 + src/build.cc | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/doc/manual.asciidoc b/doc/manual.asciidoc index 666f0a5..42e5452 100644 --- a/doc/manual.asciidoc +++ b/doc/manual.asciidoc @@ -215,6 +215,7 @@ Ninja supports one environment variable to control its behavior. Several placeholders are available: * `%s`: The number of started edges. * `%t`: The total number of edges that must be run to complete the build. +* `%p`: The percentage of started edges. * `%r`: The number of currently running edges. * `%u`: The number of remaining edges to start. * `%f`: The number of finished edges. diff --git a/src/build.cc b/src/build.cc index 93ab10d..e5429cf 100644 --- a/src/build.cc +++ b/src/build.cc @@ -179,6 +179,7 @@ string BuildStatus::FormatProgressStatus( const char* progress_status_format) const { string out; char buf[32]; + int percent; for (const char* s = progress_status_format; *s != '\0'; ++s) { if (*s == '%') { ++s; @@ -231,6 +232,13 @@ string BuildStatus::FormatProgressStatus( out += buf; break; + // Percentage + case 'p': + percent = (100 * started_edges_) / total_edges_; + snprintf(buf, sizeof(buf), "%3i%%", percent); + out += buf; + break; + default: Fatal("unknown placeholder '%%%c' in $NINJA_STATUS", *s); return ""; -- cgit v0.12