mirror of
https://github.com/NixOS/nix.git
synced 2025-11-21 09:49:36 +01:00
Put builds/substitutes under the right progress bar
This commit is contained in:
parent
83f47e7fb1
commit
256d6427fa
1 changed files with 40 additions and 119 deletions
|
|
@ -51,7 +51,8 @@ private:
|
||||||
|
|
||||||
struct ActInfo
|
struct ActInfo
|
||||||
{
|
{
|
||||||
std::string s, lastLine, phase;
|
std::string s, lastLine;
|
||||||
|
std::optional<std::string> phase;
|
||||||
ActivityType type = actUnknown;
|
ActivityType type = actUnknown;
|
||||||
uint64_t done = 0;
|
uint64_t done = 0;
|
||||||
uint64_t expected = 0;
|
uint64_t expected = 0;
|
||||||
|
|
@ -354,7 +355,7 @@ public:
|
||||||
std::string name(storePathToName(getS(fields, 0)));
|
std::string name(storePathToName(getS(fields, 0)));
|
||||||
if (hasSuffix(name, ".drv"))
|
if (hasSuffix(name, ".drv"))
|
||||||
name = name.substr(0, name.size() - 4);
|
name = name.substr(0, name.size() - 4);
|
||||||
i->s = fmt("building " ANSI_BOLD "%s" ANSI_NORMAL, name);
|
i->s = fmt(ANSI_BOLD "%s" ANSI_NORMAL, name);
|
||||||
auto machineName = getS(fields, 1);
|
auto machineName = getS(fields, 1);
|
||||||
if (machineName != "")
|
if (machineName != "")
|
||||||
i->s += fmt(" on " ANSI_BOLD "%s" ANSI_NORMAL, machineName);
|
i->s += fmt(" on " ANSI_BOLD "%s" ANSI_NORMAL, machineName);
|
||||||
|
|
@ -370,8 +371,8 @@ public:
|
||||||
auto sub = getS(fields, 1);
|
auto sub = getS(fields, 1);
|
||||||
i->s = fmt(
|
i->s = fmt(
|
||||||
hasPrefix(sub, "local")
|
hasPrefix(sub, "local")
|
||||||
? "copying " ANSI_BOLD "%s" ANSI_NORMAL " from %s"
|
? ANSI_BOLD "%s" ANSI_NORMAL " from %s"
|
||||||
: "fetching " ANSI_BOLD "%s" ANSI_NORMAL " from %s",
|
: ANSI_BOLD "%s" ANSI_NORMAL " from %s",
|
||||||
name, sub);
|
name, sub);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -390,7 +391,9 @@ public:
|
||||||
|
|
||||||
if ((type == actFileTransfer && hasAncestor(*state, actCopyPath, parent))
|
if ((type == actFileTransfer && hasAncestor(*state, actCopyPath, parent))
|
||||||
|| (type == actFileTransfer && hasAncestor(*state, actQueryPathInfo, parent))
|
|| (type == actFileTransfer && hasAncestor(*state, actQueryPathInfo, parent))
|
||||||
|| (type == actCopyPath && hasAncestor(*state, actSubstitute, parent)))
|
|| (type == actCopyPath && hasAncestor(*state, actSubstitute, parent))
|
||||||
|
|| type == actBuild
|
||||||
|
|| type == actSubstitute)
|
||||||
i->visible = false;
|
i->visible = false;
|
||||||
|
|
||||||
update(*state);
|
update(*state);
|
||||||
|
|
@ -446,19 +449,14 @@ public:
|
||||||
if (!lastLine.empty()) {
|
if (!lastLine.empty()) {
|
||||||
auto i = state->its.find(act);
|
auto i = state->its.find(act);
|
||||||
assert(i != state->its.end());
|
assert(i != state->its.end());
|
||||||
ActInfo info = *i->second;
|
i->second->lastLine = lastLine;
|
||||||
if (state->printBuildLogs) {
|
if (state->printBuildLogs) {
|
||||||
auto suffix = "> ";
|
auto suffix = "> ";
|
||||||
if (type == resPostBuildLogLine) {
|
if (type == resPostBuildLogLine) {
|
||||||
suffix = " (post)> ";
|
suffix = " (post)> ";
|
||||||
}
|
}
|
||||||
log(*state, lvlInfo, ANSI_FAINT + info.name.value_or("unnamed") + suffix + ANSI_NORMAL + lastLine);
|
log(*state, lvlInfo, ANSI_FAINT + i->second->name.value_or("unnamed") + suffix + ANSI_NORMAL + lastLine);
|
||||||
}
|
} else
|
||||||
state->activities.erase(i->second);
|
|
||||||
info.lastLine = lastLine;
|
|
||||||
state->activities.emplace_back(info);
|
|
||||||
i->second = std::prev(state->activities.end());
|
|
||||||
if (!state->printBuildLogs)
|
|
||||||
update(*state);
|
update(*state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -514,32 +512,14 @@ public:
|
||||||
{
|
{
|
||||||
std::string line;
|
std::string line;
|
||||||
|
|
||||||
std::string status = getStatus(state);
|
|
||||||
if (!status.empty()) {
|
|
||||||
line += '[';
|
|
||||||
line += status;
|
|
||||||
line += "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!state.activities.empty()) {
|
if (!state.activities.empty()) {
|
||||||
if (!status.empty()) line += " ";
|
|
||||||
auto i = state.activities.rbegin();
|
auto i = state.activities.rbegin();
|
||||||
|
|
||||||
while (i != state.activities.rend() && (!i->visible || (i->s.empty() && i->lastLine.empty())))
|
while (i != state.activities.rend() && (!i->visible || (i->s.empty() && i->lastLine.empty())))
|
||||||
++i;
|
++i;
|
||||||
|
|
||||||
if (i != state.activities.rend()) {
|
if (i != state.activities.rend())
|
||||||
line += i->s;
|
line += i->s;
|
||||||
if (!i->phase.empty()) {
|
|
||||||
line += " (";
|
|
||||||
line += i->phase;
|
|
||||||
line += ")";
|
|
||||||
}
|
|
||||||
if (!state.printBuildLogs && !i->lastLine.empty()) {
|
|
||||||
if (!i->s.empty()) line += ": ";
|
|
||||||
line += i->lastLine;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeStatusLines(state, idStatus);
|
removeStatusLines(state, idStatus);
|
||||||
|
|
@ -580,23 +560,36 @@ public:
|
||||||
|
|
||||||
if (copyPath.done || copyPath.expected) {
|
if (copyPath.done || copyPath.expected) {
|
||||||
// FIXME: handle failures
|
// FIXME: handle failures
|
||||||
state.statusLines.insert_or_assign({idCopyPaths, 0},
|
|
||||||
|
removeStatusLines(state, idCopyPaths);
|
||||||
|
|
||||||
|
size_t n = 0;
|
||||||
|
state.statusLines.insert_or_assign({idCopyPaths, n++},
|
||||||
fmt("%s Fetched %d / %d paths, %.1f / %.1f MiB",
|
fmt("%s Fetched %d / %d paths, %.1f / %.1f MiB",
|
||||||
copyPaths.running || copyPaths.done < copyPaths.expected
|
copyPaths.running || copyPaths.done < copyPaths.expected
|
||||||
? ANSI_BOLD "•"
|
? ANSI_BOLD "•"
|
||||||
: ANSI_GREEN "✓",
|
: ANSI_GREEN "✓",
|
||||||
copyPaths.done, copyPaths.expected,
|
copyPaths.done, copyPaths.expected,
|
||||||
copyPath.done / MiB, copyPath.expected / MiB));
|
copyPath.done / MiB, copyPath.expected / MiB));
|
||||||
state.statusLines.insert_or_assign({idCopyPaths, 1},
|
state.statusLines.insert_or_assign({idCopyPaths, n++},
|
||||||
fmt(" %s", renderBar(copyPath.done, 0, copyPath.left, copyPath.expected)));
|
fmt(" %s", renderBar(copyPath.done, 0, copyPath.left, copyPath.expected)));
|
||||||
state.statusLines.insert_or_assign({idCopyPaths, 2}, "");
|
|
||||||
|
for (auto & build : state.activitiesByType[actSubstitute].its) {
|
||||||
|
state.statusLines.insert_or_assign({idCopyPaths, n++},
|
||||||
|
fmt(ANSI_BOLD " ‣ %s", build.second->s));
|
||||||
|
}
|
||||||
|
|
||||||
|
state.statusLines.insert_or_assign({idCopyPaths, n++}, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto builds = getActivityStats(state.activitiesByType[actBuilds]);
|
auto builds = getActivityStats(state.activitiesByType[actBuilds]);
|
||||||
|
|
||||||
if (builds.done || builds.expected) {
|
if (builds.done || builds.expected) {
|
||||||
|
removeStatusLines(state, idBuilds);
|
||||||
|
|
||||||
|
size_t n = 0;
|
||||||
state.statusLines.insert_or_assign(
|
state.statusLines.insert_or_assign(
|
||||||
{idBuilds, 0},
|
{idBuilds, n++},
|
||||||
fmt("%s Built %d / %d derivations",
|
fmt("%s Built %d / %d derivations",
|
||||||
builds.failed
|
builds.failed
|
||||||
? ANSI_RED "✗"
|
? ANSI_RED "✗"
|
||||||
|
|
@ -606,10 +599,19 @@ public:
|
||||||
builds.done, builds.expected)
|
builds.done, builds.expected)
|
||||||
+ (builds.running ? fmt(", %d running", builds.running) : "")
|
+ (builds.running ? fmt(", %d running", builds.running) : "")
|
||||||
+ (builds.failed ? fmt(", %d failed", builds.failed) : ""));
|
+ (builds.failed ? fmt(", %d failed", builds.failed) : ""));
|
||||||
state.statusLines.insert_or_assign({idBuilds, 1},
|
state.statusLines.insert_or_assign({idBuilds, n++},
|
||||||
fmt(" %s",
|
fmt(" %s",
|
||||||
renderBar(builds.done, builds.failed, builds.running, builds.expected)));
|
renderBar(builds.done, builds.failed, builds.running, builds.expected)));
|
||||||
state.statusLines.insert_or_assign({idBuilds, 2}, "");
|
|
||||||
|
for (auto & build : state.activitiesByType[actBuild].its) {
|
||||||
|
state.statusLines.insert_or_assign({idBuilds, n++},
|
||||||
|
fmt(ANSI_BOLD " ‣ %s%s: %s",
|
||||||
|
build.second->s,
|
||||||
|
build.second->phase ? fmt(" (%s)", *build.second->phase) : "",
|
||||||
|
build.second->lastLine));
|
||||||
|
}
|
||||||
|
|
||||||
|
state.statusLines.insert_or_assign({idBuilds, n++}, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -643,87 +645,6 @@ public:
|
||||||
state.prevStatusLines = state.statusLines.size();
|
state.prevStatusLines = state.statusLines.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getStatus(State & state)
|
|
||||||
{
|
|
||||||
std::string res;
|
|
||||||
|
|
||||||
auto renderActivity = [&](ActivityType type, const std::string & itemFmt, const std::string & numberFmt = "%d", double unit = 1) {
|
|
||||||
auto stats = getActivityStats(state.activitiesByType[type]);
|
|
||||||
|
|
||||||
std::string s;
|
|
||||||
|
|
||||||
if (stats.running || stats.done || stats.expected || stats.failed) {
|
|
||||||
if (stats.running)
|
|
||||||
if (stats.expected != 0)
|
|
||||||
s = fmt(ANSI_BLUE + numberFmt + ANSI_NORMAL "/" ANSI_GREEN + numberFmt + ANSI_NORMAL "/" + numberFmt,
|
|
||||||
stats.running / unit, stats.done / unit, stats.expected / unit);
|
|
||||||
else
|
|
||||||
s = fmt(ANSI_BLUE + numberFmt + ANSI_NORMAL "/" ANSI_GREEN + numberFmt + ANSI_NORMAL,
|
|
||||||
stats.running / unit, stats.done / unit);
|
|
||||||
else if (stats.expected != stats.done)
|
|
||||||
if (stats.expected != 0)
|
|
||||||
s = fmt(ANSI_GREEN + numberFmt + ANSI_NORMAL "/" + numberFmt,
|
|
||||||
stats.done / unit, stats.expected / unit);
|
|
||||||
else
|
|
||||||
s = fmt(ANSI_GREEN + numberFmt + ANSI_NORMAL, stats.done / unit);
|
|
||||||
else
|
|
||||||
s = fmt(stats.done ? ANSI_GREEN + numberFmt + ANSI_NORMAL : numberFmt, stats.done / unit);
|
|
||||||
s = fmt(itemFmt, s);
|
|
||||||
|
|
||||||
if (stats.failed)
|
|
||||||
s += fmt(" (" ANSI_RED "%d failed" ANSI_NORMAL ")", stats.failed / unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
return s;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto showActivity = [&](ActivityType type, const std::string & itemFmt, const std::string & numberFmt = "%d", double unit = 1) {
|
|
||||||
auto s = renderActivity(type, itemFmt, numberFmt, unit);
|
|
||||||
if (s.empty()) return;
|
|
||||||
if (!res.empty()) res += ", ";
|
|
||||||
res += s;
|
|
||||||
};
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
showActivity(actBuilds, "%s built");
|
|
||||||
|
|
||||||
auto s1 = renderActivity(actCopyPaths, "%s copied");
|
|
||||||
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 += ')'; }
|
|
||||||
}
|
|
||||||
|
|
||||||
showActivity(actFileTransfer, "%s MiB DL", "%.1f", MiB);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
void writeToStdout(std::string_view s) override
|
void writeToStdout(std::string_view s) override
|
||||||
{
|
{
|
||||||
auto state(state_.lock());
|
auto state(state_.lock());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue