From f0fa2763b66b6e65262921edce7131e1758b35d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Wed, 28 Oct 2015 23:17:20 +0100 Subject: [PATCH] Allow to change also order of description in NINJA_STATUS This commit adds new format string %d for printing description. When %d is not specified in NINJA_STATUS, then description is automatically printed at the end of line. This allows to add additional strings after description, for example changing colors on ANSI terminals via NINJA_STATUS variable. --- src/build.cc | 15 +++++++++++++-- src/build.h | 2 +- src/build_test.cc | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/build.cc b/src/build.cc index 57da61f921..6d2b888d18 100644 --- a/src/build.cc +++ b/src/build.cc @@ -156,10 +156,12 @@ void BuildStatus::BuildFinished() { } string BuildStatus::FormatProgressStatus( - const char* progress_status_format) const { + const char* progress_status_format, + const string to_print) const { string out; char buf[32]; int percent; + bool has_desc = false; char total_edges_str[32]; snprintf(total_edges_str, sizeof(total_edges_str), "%d", total_edges_); int total_edges_len = strlen(total_edges_str); @@ -228,6 +230,12 @@ string BuildStatus::FormatProgressStatus( break; } + // Description (to_print) + case 'd': + out += to_print; + has_desc = true; + break; + default: Fatal("unknown placeholder '%%%c' in $NINJA_STATUS", *s); return ""; @@ -237,6 +245,9 @@ string BuildStatus::FormatProgressStatus( } } + if (!has_desc) + out += to_print; + return out; } @@ -254,7 +265,7 @@ void BuildStatus::PrintStatus(Edge* edge) { overall_rate_.Restart(); current_rate_.Restart(); } - to_print = FormatProgressStatus(progress_status_format_) + to_print; + to_print = FormatProgressStatus(progress_status_format_, to_print); printer_.Print(to_print, force_full_command ? LinePrinter::FULL : LinePrinter::ELIDE); diff --git a/src/build.h b/src/build.h index 8106faaa54..59e553f7fb 100644 --- a/src/build.h +++ b/src/build.h @@ -202,7 +202,7 @@ struct BuildStatus { /// See the user manual for more information about the available /// placeholders. /// @param progress_status_format The format of the progress status. - string FormatProgressStatus(const char* progress_status_format) const; + string FormatProgressStatus(const char* progress_status_format, const string to_print) const; private: void PrintStatus(Edge* edge); diff --git a/src/build_test.cc b/src/build_test.cc index 52a17c9cfd..70e2e7688d 100644 --- a/src/build_test.cc +++ b/src/build_test.cc @@ -1181,7 +1181,7 @@ TEST_F(BuildWithLogTest, RestatTest) { ASSERT_EQ("", err); EXPECT_TRUE(builder_.Build(&err)); ASSERT_EQ("", err); - EXPECT_EQ("[3/3]", builder_.status_->FormatProgressStatus("[%s/%t]")); + EXPECT_EQ("[3/3]", builder_.status_->FormatProgressStatus("[%s/%t]", "")); command_runner_.commands_ran_.clear(); state_.Reset(); @@ -1621,7 +1621,7 @@ TEST_F(BuildTest, DepsGccWithEmptyDepfileErrorsOut) { TEST_F(BuildTest, StatusFormatReplacePlaceholder) { EXPECT_EQ("[%/s0/t0/r0/u0/f0]", - status_.FormatProgressStatus("[%%/s%s/t%t/r%r/u%u/f%f]")); + status_.FormatProgressStatus("[%%/s%s/t%t/r%r/u%u/f%f]", "")); } TEST_F(BuildTest, FailedDepsParse) {