Restore activity metadata
This allows the progress bar to display "building perl-5.22.3" instead of "building /nix/store/<hash>-perl-5.22.3.drv".
This commit is contained in:
parent
1f56235438
commit
0e9ddcc306
|
@ -1390,7 +1390,8 @@ void DerivationGoal::tryToBuild()
|
||||||
bool buildLocally = buildMode != bmNormal || drv->willBuildLocally();
|
bool buildLocally = buildMode != bmNormal || drv->willBuildLocally();
|
||||||
|
|
||||||
auto started = [&]() {
|
auto started = [&]() {
|
||||||
act = std::make_unique<Activity>(*logger, actBuild, fmt("building '%s'", drvPath));
|
act = std::make_unique<Activity>(*logger, actBuild,
|
||||||
|
fmt("building '%s'", drvPath), Logger::Fields{drvPath});
|
||||||
mcRunningBuilds = std::make_unique<MaintainCount<uint64_t>>(worker.runningBuilds);
|
mcRunningBuilds = std::make_unique<MaintainCount<uint64_t>>(worker.runningBuilds);
|
||||||
worker.updateProgress();
|
worker.updateProgress();
|
||||||
};
|
};
|
||||||
|
@ -2405,13 +2406,15 @@ struct BuilderLogger : Logger
|
||||||
prevLogger.log(lvl, fs);
|
prevLogger.log(lvl, fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void startActivity(ActivityId act, ActivityType type, const std::string & s) override
|
void startActivity(ActivityId act, ActivityType type,
|
||||||
|
const std::string & s, const Fields & fields) override
|
||||||
{
|
{
|
||||||
nlohmann::json json;
|
nlohmann::json json;
|
||||||
json["action"] = "start";
|
json["action"] = "start";
|
||||||
json["id"] = act;
|
json["id"] = act;
|
||||||
json["type"] = type;
|
json["type"] = type;
|
||||||
json["text"] = s;
|
json["text"] = s;
|
||||||
|
// FIXME: handle fields
|
||||||
log(lvlError, "@nix " + json.dump());
|
log(lvlError, "@nix " + json.dump());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,10 +74,11 @@ Logger * makeDefaultLogger()
|
||||||
|
|
||||||
std::atomic<uint64_t> nextId{(uint64_t) getpid() << 32};
|
std::atomic<uint64_t> nextId{(uint64_t) getpid() << 32};
|
||||||
|
|
||||||
Activity::Activity(Logger & logger, ActivityType type, const std::string & s)
|
Activity::Activity(Logger & logger, ActivityType type,
|
||||||
|
const std::string & s, const Logger::Fields & fields)
|
||||||
: logger(logger), id(nextId++)
|
: logger(logger), id(nextId++)
|
||||||
{
|
{
|
||||||
logger.startActivity(id, type, s);
|
logger.startActivity(id, type, s, fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,25 +40,6 @@ class Logger
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual ~Logger() { }
|
|
||||||
|
|
||||||
virtual void log(Verbosity lvl, const FormatOrString & fs) = 0;
|
|
||||||
|
|
||||||
void log(const FormatOrString & fs)
|
|
||||||
{
|
|
||||||
log(lvlInfo, fs);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void warn(const std::string & msg);
|
|
||||||
|
|
||||||
virtual void startActivity(ActivityId act, ActivityType type, const std::string & s) { };
|
|
||||||
|
|
||||||
virtual void stopActivity(ActivityId act) { };
|
|
||||||
|
|
||||||
virtual void progress(ActivityId act, uint64_t done = 0, uint64_t expected = 0, uint64_t running = 0, uint64_t failed = 0) { };
|
|
||||||
|
|
||||||
virtual void setExpected(ActivityId act, ActivityType type, uint64_t expected) { };
|
|
||||||
|
|
||||||
struct Field
|
struct Field
|
||||||
{
|
{
|
||||||
// FIXME: use std::variant.
|
// FIXME: use std::variant.
|
||||||
|
@ -70,7 +51,29 @@ public:
|
||||||
Field(const uint64_t & i) : type(tInt), i(i) { }
|
Field(const uint64_t & i) : type(tInt), i(i) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void result(ActivityId act, ResultType type, const std::vector<Field> & fields) { };
|
typedef std::vector<Field> Fields;
|
||||||
|
|
||||||
|
virtual ~Logger() { }
|
||||||
|
|
||||||
|
virtual void log(Verbosity lvl, const FormatOrString & fs) = 0;
|
||||||
|
|
||||||
|
void log(const FormatOrString & fs)
|
||||||
|
{
|
||||||
|
log(lvlInfo, fs);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void warn(const std::string & msg);
|
||||||
|
|
||||||
|
virtual void startActivity(ActivityId act, ActivityType type,
|
||||||
|
const std::string & s, const Fields & fields) { };
|
||||||
|
|
||||||
|
virtual void stopActivity(ActivityId act) { };
|
||||||
|
|
||||||
|
virtual void progress(ActivityId act, uint64_t done = 0, uint64_t expected = 0, uint64_t running = 0, uint64_t failed = 0) { };
|
||||||
|
|
||||||
|
virtual void setExpected(ActivityId act, ActivityType type, uint64_t expected) { };
|
||||||
|
|
||||||
|
virtual void result(ActivityId act, ResultType type, const Fields & fields) { };
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Activity
|
struct Activity
|
||||||
|
@ -79,7 +82,8 @@ struct Activity
|
||||||
|
|
||||||
const ActivityId id;
|
const ActivityId id;
|
||||||
|
|
||||||
Activity(Logger & logger, ActivityType type, const std::string & s = "");
|
Activity(Logger & logger, ActivityType type, const std::string & s = "",
|
||||||
|
const Logger::Fields & fields = {});
|
||||||
|
|
||||||
Activity(const Activity & act) = delete;
|
Activity(const Activity & act) = delete;
|
||||||
|
|
||||||
|
@ -95,7 +99,7 @@ struct Activity
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
void result(ResultType type, const Args & ... args)
|
void result(ResultType type, const Args & ... args)
|
||||||
{
|
{
|
||||||
std::vector<Logger::Field> fields;
|
Logger::Fields fields;
|
||||||
nop{(fields.emplace_back(Logger::Field(args)), 1)...};
|
nop{(fields.emplace_back(Logger::Field(args)), 1)...};
|
||||||
logger.result(id, type, fields);
|
logger.result(id, type, fields);
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,8 @@ public:
|
||||||
update(state);
|
update(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void startActivity(ActivityId act, ActivityType type, const std::string & s) override
|
void startActivity(ActivityId act, ActivityType type, const std::string & s,
|
||||||
|
const Fields & fields) override
|
||||||
{
|
{
|
||||||
auto state(state_.lock());
|
auto state(state_.lock());
|
||||||
|
|
||||||
|
@ -102,6 +103,13 @@ public:
|
||||||
state->its.emplace(act, i);
|
state->its.emplace(act, i);
|
||||||
state->activitiesByType[type].its.emplace(act, i);
|
state->activitiesByType[type].its.emplace(act, i);
|
||||||
|
|
||||||
|
if (type == actBuild) {
|
||||||
|
auto name = storePathToName(getS(fields, 0));
|
||||||
|
if (hasSuffix(name, ".drv"))
|
||||||
|
name.resize(name.size() - 4);
|
||||||
|
i->s = fmt("building " ANSI_BOLD "%s" ANSI_NORMAL, name);
|
||||||
|
}
|
||||||
|
|
||||||
update(*state);
|
update(*state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue