Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update status on edge finished #2312

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions misc/output_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ def test_issue_1418(self):
build c: echo
delay = 1
''', '-j3'),
'''[1/3] echo c\x1b[K
'''[1*3/3] echo c\x1b[K
c
[2/3] echo b\x1b[K
[2*2/3] echo b\x1b[K
b
[3/3] echo a\x1b[K
[3*1/3] echo a\x1b[K
a
''')

Expand All @@ -87,7 +87,7 @@ def test_issue_1214(self):
'''
# Only strip color when ninja's output is piped.
self.assertEqual(run(print_red),
'''[1/1] echo a\x1b[K
'''[1*1/1] echo a\x1b[K
\x1b[31mred\x1b[0m
''')
self.assertEqual(run(print_red, pipe=True),
Expand Down Expand Up @@ -121,7 +121,7 @@ def test_issue_1966(self):

build a: cat
''', '-j3'),
'''[1/1] cat cat.rsp cat.rsp > a\x1b[K
'''[0*1/1] cat cat.rsp cat.rsp > a\x1b[K
''')


Expand All @@ -136,7 +136,7 @@ def test_status(self):

def test_ninja_status_default(self):
'Do we show the default status by default?'
self.assertEqual(run(Output.BUILD_SIMPLE_ECHO), '[1/1] echo a\x1b[K\ndo thing\n')
self.assertEqual(run(Output.BUILD_SIMPLE_ECHO), '[1*1/1] echo a\x1b[K\ndo thing\n')

def test_ninja_status_quiet(self):
'Do we suppress the status information when --quiet is specified?'
Expand Down
22 changes: 19 additions & 3 deletions src/status.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ StatusPrinter::StatusPrinter(const BuildConfig& config)
printer_.set_smart_terminal(false);

progress_status_format_ = getenv("NINJA_STATUS");
if (!progress_status_format_)
progress_status_format_ = "[%f/%t] ";
if (!progress_status_format_) {
if (printer_.is_smart_terminal())
progress_status_format_ = "[%f*%r/%t] ";
else
progress_status_format_ = "[%f/%t] ";
}
}

void StatusPrinter::PlanHasTotalEdges(int total) {
Expand All @@ -50,6 +54,8 @@ void StatusPrinter::BuildEdgeStarted(const Edge* edge,
++started_edges_;
++running_edges_;
time_millis_ = start_time_millis;
if (printer_.is_smart_terminal())
edges_.push_back(edge);

if (edge->use_console() || printer_.is_smart_terminal())
PrintStatus(edge, start_time_millis);
Expand All @@ -63,13 +69,20 @@ void StatusPrinter::BuildEdgeFinished(Edge* edge, int64_t end_time_millis,
time_millis_ = end_time_millis;
++finished_edges_;

if (printer_.is_smart_terminal()) {
*std::find(edges_.begin(), edges_.end(), edge) = NULL;
while (!edges_.empty() && edges_.front() == NULL)
edges_.pop_front();
}

if (edge->use_console())
printer_.SetConsoleLocked(false);

if (config_.verbosity == BuildConfig::QUIET)
return;

if (!edge->use_console())
if (!edge->use_console()
&& (!printer_.is_smart_terminal() || !success || !output.empty()))
PrintStatus(edge, end_time_millis);

--running_edges_;
Expand Down Expand Up @@ -118,6 +131,9 @@ void StatusPrinter::BuildEdgeFinished(Edge* edge, int64_t end_time_millis,
_setmode(_fileno(stdout), _O_TEXT); // End Windows extra CR fix
#endif
}

if (printer_.is_smart_terminal() && !edges_.empty())
PrintStatus(edges_.front(), end_time_millis);
}

void StatusPrinter::BuildLoadDyndeps() {
Expand Down
3 changes: 3 additions & 0 deletions src/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#ifndef NINJA_STATUS_H_
#define NINJA_STATUS_H_

#include <deque>
#include <map>
#include <queue>
#include <string>

#include "build.h"
Expand Down Expand Up @@ -72,6 +74,7 @@ struct StatusPrinter : Status {

int started_edges_, finished_edges_, total_edges_, running_edges_;
int64_t time_millis_;
std::deque<const Edge*> edges_;

/// Prints progress output.
LinePrinter printer_;
Expand Down