Fix progress bar flicker with -L

This was caused by -L calling setLogFormat() again, which caused the
creation of a new progress bar without destroying the old one. So we
had two progress bars clobbering each other.

We should change 'logger' to be a smart pointer, but I'll do that in a
future PR.

Fixes #6931.
This commit is contained in:
Eelco Dolstra 2022-08-24 22:36:40 +02:00
parent 5b8a53fb49
commit bb411e4ae1
5 changed files with 23 additions and 16 deletions

View file

@ -30,8 +30,11 @@ Logger * makeDefaultLogger() {
return makeJSONLogger(*makeSimpleLogger(true)); return makeJSONLogger(*makeSimpleLogger(true));
case LogFormat::bar: case LogFormat::bar:
return makeProgressBar(); return makeProgressBar();
case LogFormat::barWithLogs: case LogFormat::barWithLogs: {
return makeProgressBar(true); auto logger = makeProgressBar();
logger->setPrintBuildLogs(true);
return logger;
}
default: default:
abort(); abort();
} }

View file

@ -81,14 +81,13 @@ private:
std::condition_variable quitCV, updateCV; std::condition_variable quitCV, updateCV;
bool printBuildLogs; bool printBuildLogs = false;
bool isTTY; bool isTTY;
public: public:
ProgressBar(bool printBuildLogs, bool isTTY) ProgressBar(bool isTTY)
: printBuildLogs(printBuildLogs) : isTTY(isTTY)
, isTTY(isTTY)
{ {
state_.lock()->active = isTTY; state_.lock()->active = isTTY;
updateThread = std::thread([&]() { updateThread = std::thread([&]() {
@ -503,19 +502,21 @@ public:
draw(*state); draw(*state);
return s[0]; return s[0];
} }
virtual void setPrintBuildLogs(bool printBuildLogs)
{
this->printBuildLogs = printBuildLogs;
}
}; };
Logger * makeProgressBar(bool printBuildLogs) Logger * makeProgressBar()
{ {
return new ProgressBar( return new ProgressBar(shouldANSI());
printBuildLogs,
shouldANSI()
);
} }
void startProgressBar(bool printBuildLogs) void startProgressBar()
{ {
logger = makeProgressBar(printBuildLogs); logger = makeProgressBar();
} }
void stopProgressBar() void stopProgressBar()

View file

@ -4,9 +4,9 @@
namespace nix { namespace nix {
Logger * makeProgressBar(bool printBuildLogs = false); Logger * makeProgressBar();
void startProgressBar(bool printBuildLogs = false); void startProgressBar();
void stopProgressBar(); void stopProgressBar();

View file

@ -111,6 +111,9 @@ public:
virtual std::optional<char> ask(std::string_view s) virtual std::optional<char> ask(std::string_view s)
{ return {}; } { return {}; }
virtual void setPrintBuildLogs(bool printBuildLogs)
{ }
}; };
ActivityId getCurActivity(); ActivityId getCurActivity();

View file

@ -82,7 +82,7 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
.shortName = 'L', .shortName = 'L',
.description = "Print full build logs on standard error.", .description = "Print full build logs on standard error.",
.category = loggingCategory, .category = loggingCategory,
.handler = {[&]() {setLogFormat(LogFormat::barWithLogs); }}, .handler = {[&]() { logger->setPrintBuildLogs(true); }},
}); });
addFlag({ addFlag({