summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2016-04-28 19:36:49 (GMT)
committerColin Cross <ccross@android.com>2016-04-29 19:21:46 (GMT)
commitaf4973d2251bf9bc616ceb5f9d9d64dd948ed569 (patch)
tree9da4c4ac38b96a3dcb998c53002233398dbe1aeb
parentf1b5d2bf37ba6cd10bf7ab4b51877d68eae97cbc (diff)
downloadNinja-af4973d2251bf9bc616ceb5f9d9d64dd948ed569.zip
Ninja-af4973d2251bf9bc616ceb5f9d9d64dd948ed569.tar.gz
Ninja-af4973d2251bf9bc616ceb5f9d9d64dd948ed569.tar.bz2
Fix NINJA_STATUS %r on dumb terminals
PR #999 made dumb terminals only output when edges finish. PrintStatus is called after finished_edges_ is incremented, which means the calculation for running edges will always return 1 less than the real number of running processes. This happens on smart terminals too, but ninja will immediately print the status for the next edge with starting_edges_ incremented, so the incorrect value is never visible. Pass a boolean specifying whether the status is being printed on an edge finishing, and if so count the edge that just finished as being running.
-rw-r--r--src/build.cc19
-rw-r--r--src/build.h11
-rw-r--r--src/build_test.cc6
3 files changed, 25 insertions, 11 deletions
diff --git a/src/build.cc b/src/build.cc
index 2c39636..7792016 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -97,7 +97,7 @@ void BuildStatus::BuildEdgeStarted(Edge* edge) {
++started_edges_;
if (edge->use_console() || printer_.is_smart_terminal())
- PrintStatus(edge);
+ PrintStatus(edge, kEdgeStarted);
if (edge->use_console())
printer_.SetConsoleLocked(true);
@@ -129,7 +129,7 @@ void BuildStatus::BuildEdgeFinished(Edge* edge,
return;
if (!edge->use_console())
- PrintStatus(edge);
+ PrintStatus(edge, kEdgeFinished);
// Print the command that is spewing before printing its output.
if (!success) {
@@ -170,7 +170,7 @@ void BuildStatus::BuildFinished() {
}
string BuildStatus::FormatProgressStatus(
- const char* progress_status_format) const {
+ const char* progress_status_format, EdgeStatus status) const {
string out;
char buf[32];
int percent;
@@ -195,10 +195,15 @@ string BuildStatus::FormatProgressStatus(
break;
// Running edges.
- case 'r':
- snprintf(buf, sizeof(buf), "%d", started_edges_ - finished_edges_);
+ case 'r': {
+ int running_edges = started_edges_ - finished_edges_;
+ // count the edge that just finished as a running edge
+ if (status == kEdgeFinished)
+ running_edges++;
+ snprintf(buf, sizeof(buf), "%d", running_edges);
out += buf;
break;
+ }
// Unstarted edges.
case 'u':
@@ -252,7 +257,7 @@ string BuildStatus::FormatProgressStatus(
return out;
}
-void BuildStatus::PrintStatus(Edge* edge) {
+void BuildStatus::PrintStatus(Edge* edge, EdgeStatus status) {
if (config_.verbosity == BuildConfig::QUIET)
return;
@@ -262,7 +267,7 @@ void BuildStatus::PrintStatus(Edge* edge) {
if (to_print.empty() || force_full_command)
to_print = edge->GetBinding("command");
- to_print = FormatProgressStatus(progress_status_format_) + to_print;
+ to_print = FormatProgressStatus(progress_status_format_, status) + to_print;
printer_.Print(to_print,
force_full_command ? LinePrinter::FULL : LinePrinter::ELIDE);
diff --git a/src/build.h b/src/build.h
index 51589ef..819d832 100644
--- a/src/build.h
+++ b/src/build.h
@@ -202,14 +202,21 @@ struct BuildStatus {
int* start_time, int* end_time);
void BuildFinished();
+ enum EdgeStatus {
+ kEdgeStarted,
+ kEdgeFinished,
+ };
+
/// Format the progress status string by replacing the placeholders.
/// 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;
+ /// @param finished True if the edge being printed just finished
+ string FormatProgressStatus(const char* progress_status_format,
+ EdgeStatus kEdgeFinished) const;
private:
- void PrintStatus(Edge* edge);
+ void PrintStatus(Edge* edge, EdgeStatus status);
const BuildConfig& config_;
diff --git a/src/build_test.cc b/src/build_test.cc
index 55d093e..06871d2 100644
--- a/src/build_test.cc
+++ b/src/build_test.cc
@@ -1286,7 +1286,8 @@ 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]",
+ BuildStatus::kEdgeStarted));
command_runner_.commands_ran_.clear();
state_.Reset();
@@ -1726,7 +1727,8 @@ 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]",
+ BuildStatus::kEdgeStarted));
}
TEST_F(BuildTest, FailedDepsParse) {