2016-03-29 15:29:50 +03:00
|
|
|
#include "progress-bar.hh"
|
2016-04-25 16:26:07 +03:00
|
|
|
#include "util.hh"
|
|
|
|
#include "sync.hh"
|
2017-05-16 17:09:57 +03:00
|
|
|
#include "store-api.hh"
|
2019-05-15 18:33:56 +03:00
|
|
|
#include "names.hh"
|
2016-03-29 15:29:50 +03:00
|
|
|
|
2017-05-16 17:09:57 +03:00
|
|
|
#include <atomic>
|
2018-02-06 21:51:37 +02:00
|
|
|
#include <map>
|
|
|
|
#include <thread>
|
2020-04-16 14:12:58 +03:00
|
|
|
#include <iostream>
|
2017-05-16 17:09:57 +03:00
|
|
|
|
2016-03-29 15:29:50 +03:00
|
|
|
namespace nix {
|
|
|
|
|
2017-08-16 18:32:18 +03:00
|
|
|
static std::string getS(const std::vector<Logger::Field> & fields, size_t n)
|
|
|
|
{
|
|
|
|
assert(n < fields.size());
|
|
|
|
assert(fields[n].type == Logger::Field::tString);
|
|
|
|
return fields[n].s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t getI(const std::vector<Logger::Field> & fields, size_t n)
|
|
|
|
{
|
|
|
|
assert(n < fields.size());
|
|
|
|
assert(fields[n].type == Logger::Field::tInt);
|
|
|
|
return fields[n].i;
|
|
|
|
}
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
static std::string_view storePathToName(std::string_view path)
|
|
|
|
{
|
|
|
|
auto base = baseNameOf(path);
|
|
|
|
auto i = base.find('-');
|
|
|
|
return i == std::string::npos ? base.substr(0, 0) : base.substr(i + 1);
|
|
|
|
}
|
|
|
|
|
2016-04-25 16:26:07 +03:00
|
|
|
class ProgressBar : public Logger
|
2016-03-29 15:29:50 +03:00
|
|
|
{
|
2016-04-25 16:26:07 +03:00
|
|
|
private:
|
|
|
|
|
|
|
|
struct ActInfo
|
|
|
|
{
|
2017-08-25 19:04:05 +03:00
|
|
|
std::string s, lastLine, phase;
|
2017-08-14 20:00:03 +03:00
|
|
|
ActivityType type = actUnknown;
|
|
|
|
uint64_t done = 0;
|
|
|
|
uint64_t expected = 0;
|
2017-08-14 23:42:17 +03:00
|
|
|
uint64_t running = 0;
|
2017-08-15 16:31:59 +03:00
|
|
|
uint64_t failed = 0;
|
2017-08-14 20:00:03 +03:00
|
|
|
std::map<ActivityType, uint64_t> expectedByType;
|
2017-08-25 18:49:40 +03:00
|
|
|
bool visible = true;
|
|
|
|
ActivityId parent;
|
2019-05-15 18:33:56 +03:00
|
|
|
std::optional<std::string> name;
|
2016-03-29 15:29:50 +03:00
|
|
|
};
|
|
|
|
|
2017-08-14 20:00:03 +03:00
|
|
|
struct ActivitiesByType
|
|
|
|
{
|
2017-08-16 17:38:23 +03:00
|
|
|
std::map<ActivityId, std::list<ActInfo>::iterator> its;
|
2017-08-14 20:00:03 +03:00
|
|
|
uint64_t done = 0;
|
|
|
|
uint64_t expected = 0;
|
2017-08-15 16:31:59 +03:00
|
|
|
uint64_t failed = 0;
|
2017-08-14 20:00:03 +03:00
|
|
|
};
|
|
|
|
|
2016-04-25 16:26:07 +03:00
|
|
|
struct State
|
|
|
|
{
|
|
|
|
std::list<ActInfo> activities;
|
2017-08-16 17:38:23 +03:00
|
|
|
std::map<ActivityId, std::list<ActInfo>::iterator> its;
|
2017-08-14 20:00:03 +03:00
|
|
|
|
|
|
|
std::map<ActivityType, ActivitiesByType> activitiesByType;
|
2017-08-16 18:32:18 +03:00
|
|
|
|
|
|
|
uint64_t filesLinked = 0, bytesLinked = 0;
|
2017-08-16 20:23:46 +03:00
|
|
|
|
|
|
|
uint64_t corruptedPaths = 0, untrustedPaths = 0;
|
2017-08-29 16:13:30 +03:00
|
|
|
|
|
|
|
bool active = true;
|
2019-06-25 22:57:18 +03:00
|
|
|
bool haveUpdate = true;
|
2016-04-25 16:26:07 +03:00
|
|
|
};
|
2016-03-29 15:29:50 +03:00
|
|
|
|
2016-04-25 16:26:07 +03:00
|
|
|
Sync<State> state_;
|
2016-03-29 15:29:50 +03:00
|
|
|
|
2018-02-06 21:51:37 +02:00
|
|
|
std::thread updateThread;
|
|
|
|
|
|
|
|
std::condition_variable quitCV, updateCV;
|
|
|
|
|
2019-05-15 18:33:56 +03:00
|
|
|
bool printBuildLogs;
|
|
|
|
bool isTTY;
|
|
|
|
|
2016-04-25 16:26:07 +03:00
|
|
|
public:
|
|
|
|
|
2019-05-15 18:33:56 +03:00
|
|
|
ProgressBar(bool printBuildLogs, bool isTTY)
|
|
|
|
: printBuildLogs(printBuildLogs)
|
|
|
|
, isTTY(isTTY)
|
2017-05-16 17:09:57 +03:00
|
|
|
{
|
2019-05-15 18:33:56 +03:00
|
|
|
state_.lock()->active = isTTY;
|
2018-02-06 21:51:37 +02:00
|
|
|
updateThread = std::thread([&]() {
|
|
|
|
auto state(state_.lock());
|
|
|
|
while (state->active) {
|
2019-06-25 22:57:18 +03:00
|
|
|
if (!state->haveUpdate)
|
|
|
|
state.wait(updateCV);
|
2018-02-06 21:51:37 +02:00
|
|
|
draw(*state);
|
2018-07-19 18:29:31 +03:00
|
|
|
state.wait_for(quitCV, std::chrono::milliseconds(50));
|
2018-02-06 21:51:37 +02:00
|
|
|
}
|
|
|
|
});
|
2017-05-16 17:09:57 +03:00
|
|
|
}
|
|
|
|
|
2016-04-25 16:26:07 +03:00
|
|
|
~ProgressBar()
|
2017-08-29 16:13:30 +03:00
|
|
|
{
|
|
|
|
stop();
|
2018-02-06 21:51:37 +02:00
|
|
|
updateThread.join();
|
2017-08-29 16:13:30 +03:00
|
|
|
}
|
|
|
|
|
2020-06-05 18:01:02 +03:00
|
|
|
void stop() override
|
2016-04-25 16:26:07 +03:00
|
|
|
{
|
|
|
|
auto state(state_.lock());
|
2017-08-29 16:13:30 +03:00
|
|
|
if (!state->active) return;
|
2017-08-29 17:18:00 +03:00
|
|
|
state->active = false;
|
2017-08-15 16:31:59 +03:00
|
|
|
std::string status = getStatus(*state);
|
2016-04-25 16:26:07 +03:00
|
|
|
writeToStderr("\r\e[K");
|
2017-08-15 16:31:59 +03:00
|
|
|
if (status != "")
|
|
|
|
writeToStderr("[" + status + "]\n");
|
2018-02-06 21:51:37 +02:00
|
|
|
updateCV.notify_one();
|
|
|
|
quitCV.notify_one();
|
2016-03-29 15:29:50 +03:00
|
|
|
}
|
|
|
|
|
2016-04-25 16:26:07 +03:00
|
|
|
void log(Verbosity lvl, const FormatOrString & fs) override
|
|
|
|
{
|
|
|
|
auto state(state_.lock());
|
|
|
|
log(*state, lvl, fs.s);
|
|
|
|
}
|
2016-03-29 15:29:50 +03:00
|
|
|
|
2016-04-25 16:26:07 +03:00
|
|
|
void log(State & state, Verbosity lvl, const std::string & s)
|
|
|
|
{
|
2019-05-15 18:33:56 +03:00
|
|
|
if (state.active) {
|
2019-10-10 00:25:06 +03:00
|
|
|
writeToStderr("\r\e[K" + filterANSIEscapes(s, !isTTY) + ANSI_NORMAL "\n");
|
2019-05-15 18:33:56 +03:00
|
|
|
draw(state);
|
|
|
|
} else {
|
|
|
|
auto s2 = s + ANSI_NORMAL "\n";
|
|
|
|
if (!isTTY) s2 = filterANSIEscapes(s2, true);
|
|
|
|
writeToStderr(s2);
|
|
|
|
}
|
2016-04-25 16:26:07 +03:00
|
|
|
}
|
|
|
|
|
2017-08-28 20:13:24 +03:00
|
|
|
void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
|
|
|
|
const std::string & s, const Fields & fields, ActivityId parent) override
|
2017-08-16 17:38:23 +03:00
|
|
|
{
|
|
|
|
auto state(state_.lock());
|
2017-08-16 18:32:18 +03:00
|
|
|
|
2017-08-31 16:25:58 +03:00
|
|
|
if (lvl <= verbosity && !s.empty())
|
|
|
|
log(*state, lvl, s + "...");
|
|
|
|
|
2017-08-25 17:11:18 +03:00
|
|
|
state->activities.emplace_back(ActInfo());
|
2017-08-16 18:32:18 +03:00
|
|
|
auto i = std::prev(state->activities.end());
|
2017-08-25 17:11:18 +03:00
|
|
|
i->s = s;
|
|
|
|
i->type = type;
|
2017-08-25 18:49:40 +03:00
|
|
|
i->parent = parent;
|
2017-08-16 18:32:18 +03:00
|
|
|
state->its.emplace(act, i);
|
|
|
|
state->activitiesByType[type].its.emplace(act, i);
|
|
|
|
|
2017-08-25 15:53:50 +03:00
|
|
|
if (type == actBuild) {
|
2020-06-05 11:45:05 +03:00
|
|
|
std::string name(storePathToName(getS(fields, 0)));
|
2017-08-25 15:53:50 +03:00
|
|
|
if (hasSuffix(name, ".drv"))
|
2019-12-15 00:19:04 +02:00
|
|
|
name = name.substr(0, name.size() - 4);
|
2017-08-25 15:53:50 +03:00
|
|
|
i->s = fmt("building " ANSI_BOLD "%s" ANSI_NORMAL, name);
|
2017-10-24 15:24:57 +03:00
|
|
|
auto machineName = getS(fields, 1);
|
|
|
|
if (machineName != "")
|
|
|
|
i->s += fmt(" on " ANSI_BOLD "%s" ANSI_NORMAL, machineName);
|
2017-10-24 16:05:21 +03:00
|
|
|
auto curRound = getI(fields, 2);
|
|
|
|
auto nrRounds = getI(fields, 3);
|
|
|
|
if (nrRounds != 1)
|
|
|
|
i->s += fmt(" (round %d/%d)", curRound, nrRounds);
|
2019-05-15 18:33:56 +03:00
|
|
|
i->name = DrvName(name).name;
|
2017-08-25 15:53:50 +03:00
|
|
|
}
|
|
|
|
|
2017-08-25 18:49:40 +03:00
|
|
|
if (type == actSubstitute) {
|
|
|
|
auto name = storePathToName(getS(fields, 0));
|
2018-02-05 19:32:23 +02:00
|
|
|
auto sub = getS(fields, 1);
|
|
|
|
i->s = fmt(
|
|
|
|
hasPrefix(sub, "local")
|
|
|
|
? "copying " ANSI_BOLD "%s" ANSI_NORMAL " from %s"
|
|
|
|
: "fetching " ANSI_BOLD "%s" ANSI_NORMAL " from %s",
|
|
|
|
name, sub);
|
2017-08-25 18:49:40 +03:00
|
|
|
}
|
|
|
|
|
2019-07-11 21:23:03 +03:00
|
|
|
if (type == actPostBuildHook) {
|
|
|
|
auto name = storePathToName(getS(fields, 0));
|
|
|
|
if (hasSuffix(name, ".drv"))
|
2019-12-15 00:19:04 +02:00
|
|
|
name = name.substr(0, name.size() - 4);
|
2019-07-11 21:23:03 +03:00
|
|
|
i->s = fmt("post-build " ANSI_BOLD "%s" ANSI_NORMAL, name);
|
|
|
|
i->name = DrvName(name).name;
|
|
|
|
}
|
|
|
|
|
2017-08-31 16:25:58 +03:00
|
|
|
if (type == actQueryPathInfo) {
|
|
|
|
auto name = storePathToName(getS(fields, 0));
|
2017-09-27 14:21:08 +03:00
|
|
|
i->s = fmt("querying " ANSI_BOLD "%s" ANSI_NORMAL " on %s", name, getS(fields, 1));
|
2017-08-31 16:25:58 +03:00
|
|
|
}
|
|
|
|
|
2020-04-07 00:43:43 +03:00
|
|
|
if ((type == actFileTransfer && hasAncestor(*state, actCopyPath, parent))
|
|
|
|
|| (type == actFileTransfer && hasAncestor(*state, actQueryPathInfo, parent))
|
2017-08-25 18:49:40 +03:00
|
|
|
|| (type == actCopyPath && hasAncestor(*state, actSubstitute, parent)))
|
|
|
|
i->visible = false;
|
|
|
|
|
2019-06-25 22:57:18 +03:00
|
|
|
update(*state);
|
2017-08-16 17:38:23 +03:00
|
|
|
}
|
|
|
|
|
2017-08-25 18:49:40 +03:00
|
|
|
/* Check whether an activity has an ancestore with the specified
|
|
|
|
type. */
|
|
|
|
bool hasAncestor(State & state, ActivityType type, ActivityId act)
|
|
|
|
{
|
|
|
|
while (act != 0) {
|
|
|
|
auto i = state.its.find(act);
|
|
|
|
if (i == state.its.end()) break;
|
|
|
|
if (i->second->type == type) return true;
|
2017-08-25 21:52:34 +03:00
|
|
|
act = i->second->parent;
|
2017-08-25 18:49:40 +03:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-16 17:38:23 +03:00
|
|
|
void stopActivity(ActivityId act) override
|
|
|
|
{
|
|
|
|
auto state(state_.lock());
|
2017-08-16 18:32:18 +03:00
|
|
|
|
|
|
|
auto i = state->its.find(act);
|
|
|
|
if (i != state->its.end()) {
|
2017-08-31 16:25:58 +03:00
|
|
|
|
2017-08-16 18:32:18 +03:00
|
|
|
auto & actByType = state->activitiesByType[i->second->type];
|
|
|
|
actByType.done += i->second->done;
|
|
|
|
actByType.failed += i->second->failed;
|
|
|
|
|
|
|
|
for (auto & j : i->second->expectedByType)
|
|
|
|
state->activitiesByType[j.first].expected -= j.second;
|
|
|
|
|
|
|
|
actByType.its.erase(act);
|
|
|
|
state->activities.erase(i->second);
|
|
|
|
state->its.erase(i);
|
|
|
|
}
|
|
|
|
|
2019-06-25 22:57:18 +03:00
|
|
|
update(*state);
|
2017-08-16 17:38:23 +03:00
|
|
|
}
|
|
|
|
|
2017-08-16 18:32:18 +03:00
|
|
|
void result(ActivityId act, ResultType type, const std::vector<Field> & fields) override
|
2016-04-25 16:26:07 +03:00
|
|
|
{
|
2017-08-16 18:32:18 +03:00
|
|
|
auto state(state_.lock());
|
2017-08-14 20:00:03 +03:00
|
|
|
|
2017-08-16 18:32:18 +03:00
|
|
|
if (type == resFileLinked) {
|
|
|
|
state->filesLinked++;
|
|
|
|
state->bytesLinked += getI(fields, 0);
|
2019-06-25 22:57:18 +03:00
|
|
|
update(*state);
|
2017-05-16 17:09:57 +03:00
|
|
|
}
|
2016-04-25 16:26:07 +03:00
|
|
|
|
2019-07-11 21:23:03 +03:00
|
|
|
else if (type == resBuildLogLine || type == resPostBuildLogLine) {
|
2017-08-25 19:04:05 +03:00
|
|
|
auto lastLine = trim(getS(fields, 0));
|
|
|
|
if (!lastLine.empty()) {
|
2017-08-16 18:32:18 +03:00
|
|
|
auto i = state->its.find(act);
|
|
|
|
assert(i != state->its.end());
|
|
|
|
ActInfo info = *i->second;
|
2019-05-15 18:33:56 +03:00
|
|
|
if (printBuildLogs) {
|
2019-07-11 21:23:03 +03:00
|
|
|
auto suffix = "> ";
|
|
|
|
if (type == resPostBuildLogLine) {
|
|
|
|
suffix = " (post)> ";
|
|
|
|
}
|
|
|
|
log(*state, lvlInfo, ANSI_FAINT + info.name.value_or("unnamed") + suffix + ANSI_NORMAL + lastLine);
|
2019-05-15 18:33:56 +03:00
|
|
|
} else {
|
|
|
|
state->activities.erase(i->second);
|
|
|
|
info.lastLine = lastLine;
|
|
|
|
state->activities.emplace_back(info);
|
|
|
|
i->second = std::prev(state->activities.end());
|
2019-06-25 22:57:18 +03:00
|
|
|
update(*state);
|
2019-05-15 18:33:56 +03:00
|
|
|
}
|
2017-08-16 18:32:18 +03:00
|
|
|
}
|
|
|
|
}
|
2017-08-16 20:23:46 +03:00
|
|
|
|
|
|
|
else if (type == resUntrustedPath) {
|
|
|
|
state->untrustedPaths++;
|
2019-06-25 22:57:18 +03:00
|
|
|
update(*state);
|
2017-08-16 20:23:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == resCorruptedPath) {
|
|
|
|
state->corruptedPaths++;
|
2019-06-25 22:57:18 +03:00
|
|
|
update(*state);
|
2017-08-16 20:23:46 +03:00
|
|
|
}
|
2017-08-25 19:04:05 +03:00
|
|
|
|
|
|
|
else if (type == resSetPhase) {
|
|
|
|
auto i = state->its.find(act);
|
|
|
|
assert(i != state->its.end());
|
|
|
|
i->second->phase = getS(fields, 0);
|
2019-06-25 22:57:18 +03:00
|
|
|
update(*state);
|
2017-08-25 22:26:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == resProgress) {
|
|
|
|
auto i = state->its.find(act);
|
|
|
|
assert(i != state->its.end());
|
|
|
|
ActInfo & actInfo = *i->second;
|
|
|
|
actInfo.done = getI(fields, 0);
|
|
|
|
actInfo.expected = getI(fields, 1);
|
|
|
|
actInfo.running = getI(fields, 2);
|
|
|
|
actInfo.failed = getI(fields, 3);
|
2019-06-25 22:57:18 +03:00
|
|
|
update(*state);
|
2017-08-25 19:04:05 +03:00
|
|
|
}
|
2017-08-28 15:30:35 +03:00
|
|
|
|
|
|
|
else if (type == resSetExpected) {
|
|
|
|
auto i = state->its.find(act);
|
|
|
|
assert(i != state->its.end());
|
|
|
|
ActInfo & actInfo = *i->second;
|
|
|
|
auto type = (ActivityType) getI(fields, 0);
|
|
|
|
auto & j = actInfo.expectedByType[type];
|
|
|
|
state->activitiesByType[type].expected -= j;
|
|
|
|
j = getI(fields, 1);
|
|
|
|
state->activitiesByType[type].expected += j;
|
2019-06-25 22:57:18 +03:00
|
|
|
update(*state);
|
2017-08-28 15:30:35 +03:00
|
|
|
}
|
2016-04-25 16:26:07 +03:00
|
|
|
}
|
|
|
|
|
2019-06-25 22:57:18 +03:00
|
|
|
void update(State & state)
|
2016-04-25 16:26:07 +03:00
|
|
|
{
|
2019-06-25 22:57:18 +03:00
|
|
|
state.haveUpdate = true;
|
2018-02-06 21:51:37 +02:00
|
|
|
updateCV.notify_one();
|
2016-04-25 16:26:07 +03:00
|
|
|
}
|
|
|
|
|
2018-02-06 21:51:37 +02:00
|
|
|
void draw(State & state)
|
2016-04-25 16:26:07 +03:00
|
|
|
{
|
2019-06-25 22:57:18 +03:00
|
|
|
state.haveUpdate = false;
|
2017-08-29 16:13:30 +03:00
|
|
|
if (!state.active) return;
|
|
|
|
|
2017-08-25 16:44:36 +03:00
|
|
|
std::string line;
|
2016-04-25 16:26:07 +03:00
|
|
|
|
|
|
|
std::string status = getStatus(state);
|
|
|
|
if (!status.empty()) {
|
|
|
|
line += '[';
|
|
|
|
line += status;
|
|
|
|
line += "]";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!state.activities.empty()) {
|
|
|
|
if (!status.empty()) line += " ";
|
2017-05-16 17:09:57 +03:00
|
|
|
auto i = state.activities.rbegin();
|
2017-08-14 21:14:55 +03:00
|
|
|
|
2017-08-25 19:04:05 +03:00
|
|
|
while (i != state.activities.rend() && (!i->visible || (i->s.empty() && i->lastLine.empty())))
|
2017-08-14 21:14:55 +03:00
|
|
|
++i;
|
|
|
|
|
|
|
|
if (i != state.activities.rend()) {
|
|
|
|
line += i->s;
|
2017-08-25 19:04:05 +03:00
|
|
|
if (!i->phase.empty()) {
|
|
|
|
line += " (";
|
|
|
|
line += i->phase;
|
|
|
|
line += ")";
|
|
|
|
}
|
|
|
|
if (!i->lastLine.empty()) {
|
2017-08-15 16:31:59 +03:00
|
|
|
if (!i->s.empty()) line += ": ";
|
2017-08-25 19:04:05 +03:00
|
|
|
line += i->lastLine;
|
2017-08-14 21:14:55 +03:00
|
|
|
}
|
2017-05-16 17:09:57 +03:00
|
|
|
}
|
2016-04-25 16:26:07 +03:00
|
|
|
}
|
|
|
|
|
2018-02-07 16:19:10 +02:00
|
|
|
auto width = getWindowSize().second;
|
2019-11-03 23:46:59 +02:00
|
|
|
if (width <= 0) width = std::numeric_limits<decltype(width)>::max();
|
2018-02-07 16:19:10 +02:00
|
|
|
|
2018-03-15 17:08:07 +02:00
|
|
|
writeToStderr("\r" + filterANSIEscapes(line, false, width) + "\e[K");
|
2016-04-25 16:26:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string getStatus(State & state)
|
|
|
|
{
|
2017-08-14 20:00:03 +03:00
|
|
|
auto MiB = 1024.0 * 1024.0;
|
|
|
|
|
2016-04-25 16:26:07 +03:00
|
|
|
std::string res;
|
2017-05-16 17:09:57 +03:00
|
|
|
|
2017-08-16 18:00:24 +03:00
|
|
|
auto renderActivity = [&](ActivityType type, const std::string & itemFmt, const std::string & numberFmt = "%d", double unit = 1) {
|
2017-08-14 21:14:55 +03:00
|
|
|
auto & act = state.activitiesByType[type];
|
2017-08-15 16:31:59 +03:00
|
|
|
uint64_t done = act.done, expected = act.done, running = 0, failed = act.failed;
|
2017-08-14 21:14:55 +03:00
|
|
|
for (auto & j : act.its) {
|
|
|
|
done += j.second->done;
|
|
|
|
expected += j.second->expected;
|
2017-08-14 23:42:17 +03:00
|
|
|
running += j.second->running;
|
2017-08-15 16:31:59 +03:00
|
|
|
failed += j.second->failed;
|
2017-08-14 21:14:55 +03:00
|
|
|
}
|
2017-08-14 20:00:03 +03:00
|
|
|
|
2017-08-14 21:14:55 +03:00
|
|
|
expected = std::max(expected, act.expected);
|
2017-08-14 20:00:03 +03:00
|
|
|
|
2017-08-15 16:31:59 +03:00
|
|
|
std::string s;
|
|
|
|
|
|
|
|
if (running || done || expected || failed) {
|
|
|
|
if (running)
|
2019-05-06 23:23:15 +03:00
|
|
|
if (expected != 0)
|
|
|
|
s = fmt(ANSI_BLUE + numberFmt + ANSI_NORMAL "/" ANSI_GREEN + numberFmt + ANSI_NORMAL "/" + numberFmt,
|
|
|
|
running / unit, done / unit, expected / unit);
|
|
|
|
else
|
|
|
|
s = fmt(ANSI_BLUE + numberFmt + ANSI_NORMAL "/" ANSI_GREEN + numberFmt + ANSI_NORMAL,
|
|
|
|
running / unit, done / unit);
|
2017-08-15 16:31:59 +03:00
|
|
|
else if (expected != done)
|
2019-05-06 23:23:15 +03:00
|
|
|
if (expected != 0)
|
|
|
|
s = fmt(ANSI_GREEN + numberFmt + ANSI_NORMAL "/" + numberFmt,
|
|
|
|
done / unit, expected / unit);
|
|
|
|
else
|
|
|
|
s = fmt(ANSI_GREEN + numberFmt + ANSI_NORMAL, done / unit);
|
2017-08-15 16:31:59 +03:00
|
|
|
else
|
|
|
|
s = fmt(done ? ANSI_GREEN + numberFmt + ANSI_NORMAL : numberFmt, done / unit);
|
|
|
|
s = fmt(itemFmt, s);
|
|
|
|
|
|
|
|
if (failed)
|
|
|
|
s += fmt(" (" ANSI_RED "%d failed" ANSI_NORMAL ")", failed / unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
};
|
|
|
|
|
2017-08-16 18:00:24 +03:00
|
|
|
auto showActivity = [&](ActivityType type, const std::string & itemFmt, const std::string & numberFmt = "%d", double unit = 1) {
|
2017-08-15 16:31:59 +03:00
|
|
|
auto s = renderActivity(type, itemFmt, numberFmt, unit);
|
|
|
|
if (s.empty()) return;
|
|
|
|
if (!res.empty()) res += ", ";
|
|
|
|
res += s;
|
2017-08-14 21:14:55 +03:00
|
|
|
};
|
|
|
|
|
2017-08-16 18:00:24 +03:00
|
|
|
showActivity(actBuilds, "%s built");
|
2017-08-15 16:31:59 +03:00
|
|
|
|
2017-08-16 18:00:24 +03:00
|
|
|
auto s1 = renderActivity(actCopyPaths, "%s copied");
|
2017-08-15 16:31:59 +03:00
|
|
|
auto s2 = renderActivity(actCopyPath, "%s MiB", "%.1f", MiB);
|
|
|
|
|
|
|
|
if (!s1.empty() || !s2.empty()) {
|
|
|
|
if (!res.empty()) res += ", ";
|
|
|
|
if (s1.empty()) res += "0 copied"; else res += s1;
|
|
|
|
if (!s2.empty()) { res += " ("; res += s2; res += ')'; }
|
|
|
|
}
|
|
|
|
|
2020-04-07 00:43:43 +03:00
|
|
|
showActivity(actFileTransfer, "%s MiB DL", "%.1f", MiB);
|
2017-08-14 20:00:03 +03:00
|
|
|
|
2017-08-16 18:32:18 +03:00
|
|
|
{
|
|
|
|
auto s = renderActivity(actOptimiseStore, "%s paths optimised");
|
|
|
|
if (s != "") {
|
|
|
|
s += fmt(", %.1f MiB / %d inodes freed", state.bytesLinked / MiB, state.filesLinked);
|
|
|
|
if (!res.empty()) res += ", ";
|
|
|
|
res += s;
|
|
|
|
}
|
|
|
|
}
|
2017-08-16 18:00:24 +03:00
|
|
|
|
2017-08-16 20:23:46 +03:00
|
|
|
// FIXME: don't show "done" paths in green.
|
|
|
|
showActivity(actVerifyPaths, "%s paths verified");
|
|
|
|
|
|
|
|
if (state.corruptedPaths) {
|
|
|
|
if (!res.empty()) res += ", ";
|
|
|
|
res += fmt(ANSI_RED "%d corrupted" ANSI_NORMAL, state.corruptedPaths);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state.untrustedPaths) {
|
|
|
|
if (!res.empty()) res += ", ";
|
|
|
|
res += fmt(ANSI_RED "%d untrusted" ANSI_NORMAL, state.untrustedPaths);
|
|
|
|
}
|
|
|
|
|
2016-04-25 16:26:07 +03:00
|
|
|
return res;
|
|
|
|
}
|
2020-04-16 14:12:58 +03:00
|
|
|
|
|
|
|
void writeToStdout(std::string_view s) override
|
|
|
|
{
|
|
|
|
auto state(state_.lock());
|
|
|
|
if (state->active) {
|
|
|
|
std::cerr << "\r\e[K";
|
|
|
|
Logger::writeToStdout(s);
|
|
|
|
draw(*state);
|
|
|
|
} else {
|
|
|
|
Logger::writeToStdout(s);
|
|
|
|
}
|
|
|
|
}
|
2016-04-25 16:26:07 +03:00
|
|
|
};
|
2016-03-29 15:29:50 +03:00
|
|
|
|
2020-06-05 18:01:02 +03:00
|
|
|
Logger *makeProgressBar(bool printBuildLogs)
|
2016-03-29 15:29:50 +03:00
|
|
|
{
|
2020-06-05 18:01:02 +03:00
|
|
|
return new ProgressBar(
|
2020-02-18 18:47:53 +02:00
|
|
|
printBuildLogs,
|
2020-06-05 18:01:02 +03:00
|
|
|
isatty(STDERR_FILENO) && getEnv("TERM").value_or("dumb") != "dumb"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void startProgressBar(bool printBuildLogs)
|
|
|
|
{
|
|
|
|
logger = makeProgressBar(printBuildLogs);
|
2016-03-29 15:29:50 +03:00
|
|
|
}
|
|
|
|
|
2017-08-29 16:13:30 +03:00
|
|
|
void stopProgressBar()
|
2016-03-29 15:29:50 +03:00
|
|
|
{
|
2017-08-29 16:13:30 +03:00
|
|
|
auto progressBar = dynamic_cast<ProgressBar *>(logger);
|
|
|
|
if (progressBar) progressBar->stop();
|
|
|
|
|
2016-03-29 15:29:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|