forked from lix-project/lix
Merge pull request #2810 from NixOS/print-build-logs
nix: Add --print-build-logs flag
This commit is contained in:
commit
8f6c72faee
|
@ -408,6 +408,7 @@ void ignoreException();
|
||||||
/* Some ANSI escape sequences. */
|
/* Some ANSI escape sequences. */
|
||||||
#define ANSI_NORMAL "\e[0m"
|
#define ANSI_NORMAL "\e[0m"
|
||||||
#define ANSI_BOLD "\e[1m"
|
#define ANSI_BOLD "\e[1m"
|
||||||
|
#define ANSI_FAINT "\e[2m"
|
||||||
#define ANSI_RED "\e[31;1m"
|
#define ANSI_RED "\e[31;1m"
|
||||||
#define ANSI_GREEN "\e[32;1m"
|
#define ANSI_GREEN "\e[32;1m"
|
||||||
#define ANSI_BLUE "\e[34;1m"
|
#define ANSI_BLUE "\e[34;1m"
|
||||||
|
|
|
@ -20,6 +20,8 @@ std::string programPath;
|
||||||
|
|
||||||
struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
|
struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
|
||||||
{
|
{
|
||||||
|
bool printBuildLogs = false;
|
||||||
|
|
||||||
NixArgs() : MultiCommand(*RegisterCommand::commands), MixCommonArgs("nix")
|
NixArgs() : MultiCommand(*RegisterCommand::commands), MixCommonArgs("nix")
|
||||||
{
|
{
|
||||||
mkFlag()
|
mkFlag()
|
||||||
|
@ -41,6 +43,11 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
|
||||||
throw Exit();
|
throw Exit();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mkFlag()
|
||||||
|
.longName("print-build-logs")
|
||||||
|
.description("print full build logs on stderr")
|
||||||
|
.set(&printBuildLogs, true);
|
||||||
|
|
||||||
mkFlag()
|
mkFlag()
|
||||||
.longName("version")
|
.longName("version")
|
||||||
.description("show version information")
|
.description("show version information")
|
||||||
|
@ -98,8 +105,7 @@ void mainWrapped(int argc, char * * argv)
|
||||||
|
|
||||||
Finally f([]() { stopProgressBar(); });
|
Finally f([]() { stopProgressBar(); });
|
||||||
|
|
||||||
if (isatty(STDERR_FILENO))
|
startProgressBar(args.printBuildLogs);
|
||||||
startProgressBar();
|
|
||||||
|
|
||||||
args.command->prepare();
|
args.command->prepare();
|
||||||
args.command->run();
|
args.command->run();
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
#include "sync.hh"
|
#include "sync.hh"
|
||||||
#include "store-api.hh"
|
#include "store-api.hh"
|
||||||
|
#include "names.hh"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -38,6 +39,7 @@ private:
|
||||||
std::map<ActivityType, uint64_t> expectedByType;
|
std::map<ActivityType, uint64_t> expectedByType;
|
||||||
bool visible = true;
|
bool visible = true;
|
||||||
ActivityId parent;
|
ActivityId parent;
|
||||||
|
std::optional<std::string> name;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ActivitiesByType
|
struct ActivitiesByType
|
||||||
|
@ -68,10 +70,16 @@ private:
|
||||||
|
|
||||||
std::condition_variable quitCV, updateCV;
|
std::condition_variable quitCV, updateCV;
|
||||||
|
|
||||||
|
bool printBuildLogs;
|
||||||
|
bool isTTY;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ProgressBar()
|
ProgressBar(bool printBuildLogs, bool isTTY)
|
||||||
|
: printBuildLogs(printBuildLogs)
|
||||||
|
, isTTY(isTTY)
|
||||||
{
|
{
|
||||||
|
state_.lock()->active = isTTY;
|
||||||
updateThread = std::thread([&]() {
|
updateThread = std::thread([&]() {
|
||||||
auto state(state_.lock());
|
auto state(state_.lock());
|
||||||
while (state->active) {
|
while (state->active) {
|
||||||
|
@ -109,8 +117,14 @@ public:
|
||||||
|
|
||||||
void log(State & state, Verbosity lvl, const std::string & s)
|
void log(State & state, Verbosity lvl, const std::string & s)
|
||||||
{
|
{
|
||||||
|
if (state.active) {
|
||||||
writeToStderr("\r\e[K" + s + ANSI_NORMAL "\n");
|
writeToStderr("\r\e[K" + s + ANSI_NORMAL "\n");
|
||||||
draw(state);
|
draw(state);
|
||||||
|
} else {
|
||||||
|
auto s2 = s + ANSI_NORMAL "\n";
|
||||||
|
if (!isTTY) s2 = filterANSIEscapes(s2, true);
|
||||||
|
writeToStderr(s2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
|
void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
|
||||||
|
@ -141,6 +155,7 @@ public:
|
||||||
auto nrRounds = getI(fields, 3);
|
auto nrRounds = getI(fields, 3);
|
||||||
if (nrRounds != 1)
|
if (nrRounds != 1)
|
||||||
i->s += fmt(" (round %d/%d)", curRound, nrRounds);
|
i->s += fmt(" (round %d/%d)", curRound, nrRounds);
|
||||||
|
i->name = DrvName(name).name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == actSubstitute) {
|
if (type == actSubstitute) {
|
||||||
|
@ -217,6 +232,9 @@ public:
|
||||||
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;
|
ActInfo info = *i->second;
|
||||||
|
if (printBuildLogs) {
|
||||||
|
log(*state, lvlInfo, ANSI_FAINT + info.name.value_or("unnamed") + "> " + ANSI_NORMAL + lastLine);
|
||||||
|
} else {
|
||||||
state->activities.erase(i->second);
|
state->activities.erase(i->second);
|
||||||
info.lastLine = lastLine;
|
info.lastLine = lastLine;
|
||||||
state->activities.emplace_back(info);
|
state->activities.emplace_back(info);
|
||||||
|
@ -224,6 +242,7 @@ public:
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
else if (type == resUntrustedPath) {
|
else if (type == resUntrustedPath) {
|
||||||
state->untrustedPaths++;
|
state->untrustedPaths++;
|
||||||
|
@ -395,9 +414,9 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void startProgressBar()
|
void startProgressBar(bool printBuildLogs)
|
||||||
{
|
{
|
||||||
logger = new ProgressBar();
|
logger = new ProgressBar(printBuildLogs, isatty(STDERR_FILENO));
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopProgressBar()
|
void stopProgressBar()
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
void startProgressBar();
|
void startProgressBar(bool printBuildLogs = false);
|
||||||
|
|
||||||
void stopProgressBar();
|
void stopProgressBar();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue