2016-03-29 12:29:50 +00:00
|
|
|
#include "progress-bar.hh"
|
2016-04-25 13:26:07 +00:00
|
|
|
#include "util.hh"
|
|
|
|
#include "sync.hh"
|
2017-05-16 14:09:57 +00:00
|
|
|
#include "store-api.hh"
|
2019-05-15 15:33:56 +00:00
|
|
|
#include "names.hh"
|
2016-03-29 12:29:50 +00:00
|
|
|
|
2017-05-16 14:09:57 +00:00
|
|
|
#include <atomic>
|
2018-02-06 19:51:37 +00:00
|
|
|
#include <map>
|
|
|
|
#include <thread>
|
2020-04-16 11:12:58 +00:00
|
|
|
#include <iostream>
|
2017-05-16 14:09:57 +00:00
|
|
|
|
2016-03-29 12:29:50 +00:00
|
|
|
namespace nix {
|
|
|
|
|
2021-11-18 22:54:50 +00:00
|
|
|
static std::string_view getS(const std::vector<Logger::Field> & fields, size_t n)
|
2017-08-16 15:32:18 +00:00
|
|
|
{
|
|
|
|
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 18:11:09 +00: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 13:26:07 +00:00
|
|
|
class ProgressBar : public Logger
|
2016-03-29 12:29:50 +00:00
|
|
|
{
|
2016-04-25 13:26:07 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
struct ActInfo
|
|
|
|
{
|
2017-08-25 16:04:05 +00:00
|
|
|
std::string s, lastLine, phase;
|
2017-08-14 17:00:03 +00:00
|
|
|
ActivityType type = actUnknown;
|
|
|
|
uint64_t done = 0;
|
|
|
|
uint64_t expected = 0;
|
2017-08-14 20:42:17 +00:00
|
|
|
uint64_t running = 0;
|
2017-08-15 13:31:59 +00:00
|
|
|
uint64_t failed = 0;
|
2017-08-14 17:00:03 +00:00
|
|
|
std::map<ActivityType, uint64_t> expectedByType;
|
2017-08-25 15:49:40 +00:00
|
|
|
bool visible = true;
|
|
|
|
ActivityId parent;
|
2019-05-15 15:33:56 +00:00
|
|
|
std::optional<std::string> name;
|
2016-03-29 12:29:50 +00:00
|
|
|
};
|
|
|
|
|
2017-08-14 17:00:03 +00:00
|
|
|
struct ActivitiesByType
|
|
|
|
{
|
2017-08-16 14:38:23 +00:00
|
|
|
std::map<ActivityId, std::list<ActInfo>::iterator> its;
|
2017-08-14 17:00:03 +00:00
|
|
|
uint64_t done = 0;
|
|
|
|
uint64_t expected = 0;
|
2017-08-15 13:31:59 +00:00
|
|
|
uint64_t failed = 0;
|
2017-08-14 17:00:03 +00:00
|
|
|
};
|
|
|
|
|
2016-04-25 13:26:07 +00:00
|
|
|
struct State
|
|
|
|
{
|
|
|
|
std::list<ActInfo> activities;
|
2017-08-16 14:38:23 +00:00
|
|
|
std::map<ActivityId, std::list<ActInfo>::iterator> its;
|
2017-08-14 17:00:03 +00:00
|
|
|
|
|
|
|
std::map<ActivityType, ActivitiesByType> activitiesByType;
|
2017-08-16 15:32:18 +00:00
|
|
|
|
|
|
|
uint64_t filesLinked = 0, bytesLinked = 0;
|
2017-08-16 17:23:46 +00:00
|
|
|
|
|
|
|
uint64_t corruptedPaths = 0, untrustedPaths = 0;
|
2017-08-29 13:13:30 +00:00
|
|
|
|
|
|
|
bool active = true;
|
2019-06-25 19:57:18 +00:00
|
|
|
bool haveUpdate = true;
|
2016-04-25 13:26:07 +00:00
|
|
|
};
|
2016-03-29 12:29:50 +00:00
|
|
|
|
2016-04-25 13:26:07 +00:00
|
|
|
Sync<State> state_;
|
2016-03-29 12:29:50 +00:00
|
|
|
|
2018-02-06 19:51:37 +00:00
|
|
|
std::thread updateThread;
|
|
|
|
|
|
|
|
std::condition_variable quitCV, updateCV;
|
|
|
|
|
2019-05-15 15:33:56 +00:00
|
|
|
bool printBuildLogs;
|
|
|
|
bool isTTY;
|
|
|
|
|
2016-04-25 13:26:07 +00:00
|
|
|
public:
|
|
|
|
|
2019-05-15 15:33:56 +00:00
|
|
|
ProgressBar(bool printBuildLogs, bool isTTY)
|
|
|
|
: printBuildLogs(printBuildLogs)
|
|
|
|
, isTTY(isTTY)
|
2017-05-16 14:09:57 +00:00
|
|
|
{
|
2019-05-15 15:33:56 +00:00
|
|
|
state_.lock()->active = isTTY;
|
2018-02-06 19:51:37 +00:00
|
|
|
updateThread = std::thread([&]() {
|
|
|
|
auto state(state_.lock());
|
|
|
|
while (state->active) {
|
2019-06-25 19:57:18 +00:00
|
|
|
if (!state->haveUpdate)
|
|
|
|
state.wait(updateCV);
|
2018-02-06 19:51:37 +00:00
|
|
|
draw(*state);
|
2018-07-19 15:29:31 +00:00
|
|
|
state.wait_for(quitCV, std::chrono::milliseconds(50));
|
2018-02-06 19:51:37 +00:00
|
|
|
}
|
|
|
|
});
|
2017-05-16 14:09:57 +00:00
|
|
|
}
|
|
|
|
|
2016-04-25 13:26:07 +00:00
|
|
|
~ProgressBar()
|
2017-08-29 13:13:30 +00:00
|
|
|
{
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
2020-06-05 15:01:02 +00:00
|
|
|
void stop() override
|
2016-04-25 13:26:07 +00:00
|
|
|
{
|
2021-11-08 21:00:45 +00:00
|
|
|
{
|
|
|
|
auto state(state_.lock());
|
|
|
|
if (!state->active) return;
|
|
|
|
state->active = false;
|
|
|
|
writeToStderr("\r\e[K");
|
|
|
|
updateCV.notify_one();
|
|
|
|
quitCV.notify_one();
|
|
|
|
}
|
|
|
|
updateThread.join();
|
2016-03-29 12:29:50 +00:00
|
|
|
}
|
|
|
|
|
2020-06-05 16:20:11 +00:00
|
|
|
bool isVerbose() override {
|
|
|
|
return printBuildLogs;
|
|
|
|
}
|
|
|
|
|
2016-04-25 13:26:07 +00:00
|
|
|
void log(Verbosity lvl, const FormatOrString & fs) override
|
|
|
|
{
|
2021-03-19 16:56:39 +00:00
|
|
|
if (lvl > verbosity) return;
|
2016-04-25 13:26:07 +00:00
|
|
|
auto state(state_.lock());
|
|
|
|
log(*state, lvl, fs.s);
|
|
|
|
}
|
2016-03-29 12:29:50 +00:00
|
|
|
|
2020-04-17 21:07:44 +00:00
|
|
|
void logEI(const ErrorInfo &ei) override
|
|
|
|
{
|
|
|
|
auto state(state_.lock());
|
2020-04-19 23:16:51 +00:00
|
|
|
|
2020-06-15 12:12:39 +00:00
|
|
|
std::stringstream oss;
|
2020-07-02 15:04:31 +00:00
|
|
|
showErrorInfo(oss, ei, loggerSettings.showTrace.get());
|
2020-04-19 23:16:51 +00:00
|
|
|
|
|
|
|
log(*state, ei.level, oss.str());
|
2020-04-17 21:07:44 +00:00
|
|
|
}
|
|
|
|
|
2016-04-25 13:26:07 +00:00
|
|
|
void log(State & state, Verbosity lvl, const std::string & s)
|
|
|
|
{
|
2019-05-15 15:33:56 +00:00
|
|
|
if (state.active) {
|
2019-10-09 21:25:06 +00:00
|
|
|
writeToStderr("\r\e[K" + filterANSIEscapes(s, !isTTY) + ANSI_NORMAL "\n");
|
2019-05-15 15:33:56 +00:00
|
|
|
draw(state);
|
|
|
|
} else {
|
|
|
|
auto s2 = s + ANSI_NORMAL "\n";
|
|
|
|
if (!isTTY) s2 = filterANSIEscapes(s2, true);
|
|
|
|
writeToStderr(s2);
|
|
|
|
}
|
2016-04-25 13:26:07 +00:00
|
|
|
}
|
|
|
|
|
2017-08-28 17:13:24 +00:00
|
|
|
void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
|
|
|
|
const std::string & s, const Fields & fields, ActivityId parent) override
|
2017-08-16 14:38:23 +00:00
|
|
|
{
|
|
|
|
auto state(state_.lock());
|
2017-08-16 15:32:18 +00:00
|
|
|
|
2020-06-15 14:03:29 +00:00
|
|
|
if (lvl <= verbosity && !s.empty() && type != actBuildWaiting)
|
2017-08-31 13:25:58 +00:00
|
|
|
log(*state, lvl, s + "...");
|
|
|
|
|
2017-08-25 14:11:18 +00:00
|
|
|
state->activities.emplace_back(ActInfo());
|
2017-08-16 15:32:18 +00:00
|
|
|
auto i = std::prev(state->activities.end());
|
2017-08-25 14:11:18 +00:00
|
|
|
i->s = s;
|
|
|
|
i->type = type;
|
2017-08-25 15:49:40 +00:00
|
|
|
i->parent = parent;
|
2017-08-16 15:32:18 +00:00
|
|
|
state->its.emplace(act, i);
|
|
|
|
state->activitiesByType[type].its.emplace(act, i);
|
|
|
|
|
2017-08-25 12:53:50 +00:00
|
|
|
if (type == actBuild) {
|
2020-06-05 08:45:05 +00:00
|
|
|
std::string name(storePathToName(getS(fields, 0)));
|
2017-08-25 12:53:50 +00:00
|
|
|
if (hasSuffix(name, ".drv"))
|
2019-12-14 22:19:04 +00:00
|
|
|
name = name.substr(0, name.size() - 4);
|
2017-08-25 12:53:50 +00:00
|
|
|
i->s = fmt("building " ANSI_BOLD "%s" ANSI_NORMAL, name);
|
2017-10-24 12:24:57 +00:00
|
|
|
auto machineName = getS(fields, 1);
|
|
|
|
if (machineName != "")
|
|
|
|
i->s += fmt(" on " ANSI_BOLD "%s" ANSI_NORMAL, machineName);
|
2017-10-24 13:05:21 +00: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 15:33:56 +00:00
|
|
|
i->name = DrvName(name).name;
|
2017-08-25 12:53:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-25 15:49:40 +00:00
|
|
|
if (type == actSubstitute) {
|
|
|
|
auto name = storePathToName(getS(fields, 0));
|
2018-02-05 17:32:23 +00: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 15:49:40 +00:00
|
|
|
}
|
|
|
|
|
2019-07-11 18:23:03 +00:00
|
|
|
if (type == actPostBuildHook) {
|
|
|
|
auto name = storePathToName(getS(fields, 0));
|
|
|
|
if (hasSuffix(name, ".drv"))
|
2019-12-14 22:19:04 +00:00
|
|
|
name = name.substr(0, name.size() - 4);
|
2019-07-11 18:23:03 +00:00
|
|
|
i->s = fmt("post-build " ANSI_BOLD "%s" ANSI_NORMAL, name);
|
|
|
|
i->name = DrvName(name).name;
|
|
|
|
}
|
|
|
|
|
2017-08-31 13:25:58 +00:00
|
|
|
if (type == actQueryPathInfo) {
|
|
|
|
auto name = storePathToName(getS(fields, 0));
|
2017-09-27 11:21:08 +00:00
|
|
|
i->s = fmt("querying " ANSI_BOLD "%s" ANSI_NORMAL " on %s", name, getS(fields, 1));
|
2017-08-31 13:25:58 +00:00
|
|
|
}
|
|
|
|
|
2020-04-06 21:43:43 +00:00
|
|
|
if ((type == actFileTransfer && hasAncestor(*state, actCopyPath, parent))
|
|
|
|
|| (type == actFileTransfer && hasAncestor(*state, actQueryPathInfo, parent))
|
2017-08-25 15:49:40 +00:00
|
|
|
|| (type == actCopyPath && hasAncestor(*state, actSubstitute, parent)))
|
|
|
|
i->visible = false;
|
|
|
|
|
2019-06-25 19:57:18 +00:00
|
|
|
update(*state);
|
2017-08-16 14:38:23 +00:00
|
|
|
}
|
|
|
|
|
2017-08-25 15:49:40 +00: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 18:52:34 +00:00
|
|
|
act = i->second->parent;
|
2017-08-25 15:49:40 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-16 14:38:23 +00:00
|
|
|
void stopActivity(ActivityId act) override
|
|
|
|
{
|
|
|
|
auto state(state_.lock());
|
2017-08-16 15:32:18 +00:00
|
|
|
|
|
|
|
auto i = state->its.find(act);
|
|
|
|
if (i != state->its.end()) {
|
2017-08-31 13:25:58 +00:00
|
|
|
|
2017-08-16 15:32:18 +00: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 19:57:18 +00:00
|
|
|
update(*state);
|
2017-08-16 14:38:23 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 15:32:18 +00:00
|
|
|
void result(ActivityId act, ResultType type, const std::vector<Field> & fields) override
|
2016-04-25 13:26:07 +00:00
|
|
|
{
|
2017-08-16 15:32:18 +00:00
|
|
|
auto state(state_.lock());
|
2017-08-14 17:00:03 +00:00
|
|
|
|
2017-08-16 15:32:18 +00:00
|
|
|
if (type == resFileLinked) {
|
|
|
|
state->filesLinked++;
|
|
|
|
state->bytesLinked += getI(fields, 0);
|
2019-06-25 19:57:18 +00:00
|
|
|
update(*state);
|
2017-05-16 14:09:57 +00:00
|
|
|
}
|
2016-04-25 13:26:07 +00:00
|
|
|
|
2019-07-11 18:23:03 +00:00
|
|
|
else if (type == resBuildLogLine || type == resPostBuildLogLine) {
|
2020-09-26 15:38:11 +00:00
|
|
|
auto lastLine = chomp(getS(fields, 0));
|
2017-08-25 16:04:05 +00:00
|
|
|
if (!lastLine.empty()) {
|
2017-08-16 15:32:18 +00:00
|
|
|
auto i = state->its.find(act);
|
|
|
|
assert(i != state->its.end());
|
|
|
|
ActInfo info = *i->second;
|
2019-05-15 15:33:56 +00:00
|
|
|
if (printBuildLogs) {
|
2019-07-11 18:23:03 +00: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 15:33:56 +00: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 19:57:18 +00:00
|
|
|
update(*state);
|
2019-05-15 15:33:56 +00:00
|
|
|
}
|
2017-08-16 15:32:18 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-16 17:23:46 +00:00
|
|
|
|
|
|
|
else if (type == resUntrustedPath) {
|
|
|
|
state->untrustedPaths++;
|
2019-06-25 19:57:18 +00:00
|
|
|
update(*state);
|
2017-08-16 17:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (type == resCorruptedPath) {
|
|
|
|
state->corruptedPaths++;
|
2019-06-25 19:57:18 +00:00
|
|
|
update(*state);
|
2017-08-16 17:23:46 +00:00
|
|
|
}
|
2017-08-25 16:04:05 +00: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 19:57:18 +00:00
|
|
|
update(*state);
|
2017-08-25 19:26:37 +00: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 19:57:18 +00:00
|
|
|
update(*state);
|
2017-08-25 16:04:05 +00:00
|
|
|
}
|
2017-08-28 12:30:35 +00: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 19:57:18 +00:00
|
|
|
update(*state);
|
2017-08-28 12:30:35 +00:00
|
|
|
}
|
2016-04-25 13:26:07 +00:00
|
|
|
}
|
|
|
|
|
2019-06-25 19:57:18 +00:00
|
|
|
void update(State & state)
|
2016-04-25 13:26:07 +00:00
|
|
|
{
|
2019-06-25 19:57:18 +00:00
|
|
|
state.haveUpdate = true;
|
2018-02-06 19:51:37 +00:00
|
|
|
updateCV.notify_one();
|
2016-04-25 13:26:07 +00:00
|
|
|
}
|
|
|
|
|
2018-02-06 19:51:37 +00:00
|
|
|
void draw(State & state)
|
2016-04-25 13:26:07 +00:00
|
|
|
{
|
2019-06-25 19:57:18 +00:00
|
|
|
state.haveUpdate = false;
|
2017-08-29 13:13:30 +00:00
|
|
|
if (!state.active) return;
|
|
|
|
|
2017-08-25 13:44:36 +00:00
|
|
|
std::string line;
|
2016-04-25 13:26:07 +00:00
|
|
|
|
|
|
|
std::string status = getStatus(state);
|
|
|
|
if (!status.empty()) {
|
|
|
|
line += '[';
|
|
|
|
line += status;
|
|
|
|
line += "]";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!state.activities.empty()) {
|
|
|
|
if (!status.empty()) line += " ";
|
2017-05-16 14:09:57 +00:00
|
|
|
auto i = state.activities.rbegin();
|
2017-08-14 18:14:55 +00:00
|
|
|
|
2017-08-25 16:04:05 +00:00
|
|
|
while (i != state.activities.rend() && (!i->visible || (i->s.empty() && i->lastLine.empty())))
|
2017-08-14 18:14:55 +00:00
|
|
|
++i;
|
|
|
|
|
|
|
|
if (i != state.activities.rend()) {
|
|
|
|
line += i->s;
|
2017-08-25 16:04:05 +00:00
|
|
|
if (!i->phase.empty()) {
|
|
|
|
line += " (";
|
|
|
|
line += i->phase;
|
|
|
|
line += ")";
|
|
|
|
}
|
|
|
|
if (!i->lastLine.empty()) {
|
2017-08-15 13:31:59 +00:00
|
|
|
if (!i->s.empty()) line += ": ";
|
2017-08-25 16:04:05 +00:00
|
|
|
line += i->lastLine;
|
2017-08-14 18:14:55 +00:00
|
|
|
}
|
2017-05-16 14:09:57 +00:00
|
|
|
}
|
2016-04-25 13:26:07 +00:00
|
|
|
}
|
|
|
|
|
2018-02-07 14:19:10 +00:00
|
|
|
auto width = getWindowSize().second;
|
2019-11-03 21:46:59 +00:00
|
|
|
if (width <= 0) width = std::numeric_limits<decltype(width)>::max();
|
2018-02-07 14:19:10 +00:00
|
|
|
|
2020-08-10 15:44:17 +00:00
|
|
|
writeToStderr("\r" + filterANSIEscapes(line, false, width) + ANSI_NORMAL + "\e[K");
|
2016-04-25 13:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string getStatus(State & state)
|
|
|
|
{
|
2017-08-14 17:00:03 +00:00
|
|
|
auto MiB = 1024.0 * 1024.0;
|
|
|
|
|
2016-04-25 13:26:07 +00:00
|
|
|
std::string res;
|
2017-05-16 14:09:57 +00:00
|
|
|
|
2017-08-16 15:00:24 +00:00
|
|
|
auto renderActivity = [&](ActivityType type, const std::string & itemFmt, const std::string & numberFmt = "%d", double unit = 1) {
|
2017-08-14 18:14:55 +00:00
|
|
|
auto & act = state.activitiesByType[type];
|
2017-08-15 13:31:59 +00:00
|
|
|
uint64_t done = act.done, expected = act.done, running = 0, failed = act.failed;
|
2017-08-14 18:14:55 +00:00
|
|
|
for (auto & j : act.its) {
|
|
|
|
done += j.second->done;
|
|
|
|
expected += j.second->expected;
|
2017-08-14 20:42:17 +00:00
|
|
|
running += j.second->running;
|
2017-08-15 13:31:59 +00:00
|
|
|
failed += j.second->failed;
|
2017-08-14 18:14:55 +00:00
|
|
|
}
|
2017-08-14 17:00:03 +00:00
|
|
|
|
2017-08-14 18:14:55 +00:00
|
|
|
expected = std::max(expected, act.expected);
|
2017-08-14 17:00:03 +00:00
|
|
|
|
2017-08-15 13:31:59 +00:00
|
|
|
std::string s;
|
|
|
|
|
|
|
|
if (running || done || expected || failed) {
|
|
|
|
if (running)
|
2019-05-06 20:23:15 +00: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 13:31:59 +00:00
|
|
|
else if (expected != done)
|
2019-05-06 20:23:15 +00: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 13:31:59 +00: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 15:00:24 +00:00
|
|
|
auto showActivity = [&](ActivityType type, const std::string & itemFmt, const std::string & numberFmt = "%d", double unit = 1) {
|
2017-08-15 13:31:59 +00:00
|
|
|
auto s = renderActivity(type, itemFmt, numberFmt, unit);
|
|
|
|
if (s.empty()) return;
|
|
|
|
if (!res.empty()) res += ", ";
|
|
|
|
res += s;
|
2017-08-14 18:14:55 +00:00
|
|
|
};
|
|
|
|
|
2017-08-16 15:00:24 +00:00
|
|
|
showActivity(actBuilds, "%s built");
|
2017-08-15 13:31:59 +00:00
|
|
|
|
2017-08-16 15:00:24 +00:00
|
|
|
auto s1 = renderActivity(actCopyPaths, "%s copied");
|
2017-08-15 13:31:59 +00: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-06 21:43:43 +00:00
|
|
|
showActivity(actFileTransfer, "%s MiB DL", "%.1f", MiB);
|
2017-08-14 17:00:03 +00:00
|
|
|
|
2017-08-16 15:32:18 +00: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 15:00:24 +00:00
|
|
|
|
2017-08-16 17:23:46 +00: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 13:26:07 +00:00
|
|
|
return res;
|
|
|
|
}
|
2020-04-16 11:12:58 +00: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);
|
|
|
|
}
|
|
|
|
}
|
2020-11-26 11:34:43 +00:00
|
|
|
|
|
|
|
std::optional<char> ask(std::string_view msg) override
|
|
|
|
{
|
|
|
|
auto state(state_.lock());
|
|
|
|
if (!state->active || !isatty(STDIN_FILENO)) return {};
|
|
|
|
std::cerr << fmt("\r\e[K%s ", msg);
|
|
|
|
auto s = trim(readLine(STDIN_FILENO));
|
|
|
|
if (s.size() != 1) return {};
|
|
|
|
draw(*state);
|
|
|
|
return s[0];
|
|
|
|
}
|
2016-04-25 13:26:07 +00:00
|
|
|
};
|
2016-03-29 12:29:50 +00:00
|
|
|
|
2020-06-11 13:39:08 +00:00
|
|
|
Logger * makeProgressBar(bool printBuildLogs)
|
2016-03-29 12:29:50 +00:00
|
|
|
{
|
2020-06-05 15:01:02 +00:00
|
|
|
return new ProgressBar(
|
2020-02-18 16:47:53 +00:00
|
|
|
printBuildLogs,
|
2021-07-02 00:19:01 +00:00
|
|
|
shouldANSI()
|
2020-06-05 15:01:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void startProgressBar(bool printBuildLogs)
|
|
|
|
{
|
|
|
|
logger = makeProgressBar(printBuildLogs);
|
2016-03-29 12:29:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-29 13:13:30 +00:00
|
|
|
void stopProgressBar()
|
2016-03-29 12:29:50 +00:00
|
|
|
{
|
2017-08-29 13:13:30 +00:00
|
|
|
auto progressBar = dynamic_cast<ProgressBar *>(logger);
|
|
|
|
if (progressBar) progressBar->stop();
|
|
|
|
|
2016-03-29 12:29:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|