summaryrefslogtreecommitdiffstats
path: root/src/build.cc
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2011-12-09 15:26:38 (GMT)
committerPeter Collingbourne <peter@pcc.me.uk>2012-02-04 20:50:23 (GMT)
commitb07e183e0eb6225e34a3d592e3dff63bcf00df81 (patch)
treeb743978c2c589044fe1abb50848ceaa203842c91 /src/build.cc
parent06315b1e2e2db9ba5dbb1d4ecf91344846c0de3a (diff)
downloadNinja-b07e183e0eb6225e34a3d592e3dff63bcf00df81.zip
Ninja-b07e183e0eb6225e34a3d592e3dff63bcf00df81.tar.gz
Ninja-b07e183e0eb6225e34a3d592e3dff63bcf00df81.tar.bz2
Clean up how the build line is managed at the end of the build
Diffstat (limited to 'src/build.cc')
-rw-r--r--src/build.cc26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/build.cc b/src/build.cc
index cc877e5..8c9981c 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -39,6 +39,7 @@ struct BuildStatus {
void BuildEdgeStarted(Edge* edge);
void BuildEdgeFinished(Edge* edge, bool success, const string& output,
int* start_time, int* end_time);
+ void BuildFinished();
private:
void PrintStatus(Edge* edge);
@@ -52,6 +53,8 @@ struct BuildStatus {
int started_edges_, finished_edges_, total_edges_;
+ bool have_blank_line_;
+
/// Map of running edge to time the edge started running.
typedef map<Edge*, int> RunningEdgeMap;
RunningEdgeMap running_edges_;
@@ -64,7 +67,8 @@ BuildStatus::BuildStatus(const BuildConfig& config)
: config_(config),
start_time_millis_(GetTimeMillis()),
last_update_millis_(start_time_millis_),
- started_edges_(0), finished_edges_(0), total_edges_(0) {
+ started_edges_(0), finished_edges_(0), total_edges_(0),
+ have_blank_line_(true) {
#ifndef _WIN32
const char* term = getenv("TERM");
smart_terminal_ = isatty(1) && term && string(term) != "dumb";
@@ -115,10 +119,7 @@ void BuildStatus::BuildEdgeFinished(Edge* edge,
PrintStatus(edge);
if (success && output.empty()) {
- if (smart_terminal_) {
- if (finished_edges_ == total_edges_)
- printf("\n");
- } else {
+ if (!smart_terminal_) {
if (total_time > 5*1000) {
printf("%.1f%% %d/%d\n", finished_edges_ * 100 / (float)total_edges_,
finished_edges_, total_edges_);
@@ -153,9 +154,16 @@ void BuildStatus::BuildEdgeFinished(Edge* edge,
if (!final_output.empty())
printf("%s", final_output.c_str());
+
+ have_blank_line_ = true;
}
}
+void BuildStatus::BuildFinished() {
+ if (smart_terminal_ && !have_blank_line_)
+ printf("\n");
+}
+
void BuildStatus::PrintStatus(Edge* edge) {
if (config_.verbosity == BuildConfig::QUIET)
return;
@@ -195,6 +203,7 @@ void BuildStatus::PrintStatus(Edge* edge) {
if (smart_terminal_ && !force_full_command) {
printf("\x1B[K"); // Clear to end of line.
fflush(stdout);
+ have_blank_line_ = false;
} else {
printf("\n");
}
@@ -507,8 +516,10 @@ bool Builder::Build(string* err) {
// See if we can start any more commands.
if (command_runner_->CanRunMore()) {
if (Edge* edge = plan_.FindWork()) {
- if (!StartEdge(edge, err))
+ if (!StartEdge(edge, err)) {
+ status_->BuildFinished();
return false;
+ }
if (edge->is_phony())
FinishEdge(edge, true, "");
@@ -545,11 +556,13 @@ bool Builder::Build(string* err) {
// If we get here, we can neither enqueue new commands nor are any running.
if (pending_commands) {
+ status_->BuildFinished();
*err = "stuck: pending commands but none to wait for? [this is a bug]";
return false;
}
// If we get here, we cannot make any more progress.
+ status_->BuildFinished();
if (failures_allowed < config_.swallow_failures) {
*err = "cannot make progress due to previous errors";
return false;
@@ -559,6 +572,7 @@ bool Builder::Build(string* err) {
}
}
+ status_->BuildFinished();
return true;
}