mirror of
https://github.com/NixOS/nix
synced 2025-07-08 06:53:54 +02:00
Log BuildResult
This commit is contained in:
parent
c515bc66f1
commit
762114b7c4
5 changed files with 75 additions and 21 deletions
|
@ -1,8 +1,33 @@
|
|||
#include "build-result.hh"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace nix {
|
||||
|
||||
bool BuildResult::operator==(const BuildResult &) const noexcept = default;
|
||||
std::strong_ordering BuildResult::operator<=>(const BuildResult &) const noexcept = default;
|
||||
|
||||
void to_json(nlohmann::json & json, const BuildResult & buildResult)
|
||||
{
|
||||
json = nlohmann::json::object();
|
||||
json["status"] = BuildResult::statusToString(buildResult.status);
|
||||
if (buildResult.errorMsg != "")
|
||||
json["errorMsg"] = buildResult.errorMsg;
|
||||
if (buildResult.timesBuilt)
|
||||
json["timesBuilt"] = buildResult.timesBuilt;
|
||||
if (buildResult.isNonDeterministic)
|
||||
json["isNonDeterministic"] = buildResult.isNonDeterministic;
|
||||
if (buildResult.startTime)
|
||||
json["startTime"] = buildResult.startTime;
|
||||
if (buildResult.stopTime)
|
||||
json["stopTime"] = buildResult.stopTime;
|
||||
}
|
||||
|
||||
nlohmann::json KeyedBuildResult::toJSON(Store & store) const
|
||||
{
|
||||
auto json = nlohmann::json((const BuildResult &) *this);
|
||||
json["path"] = path.toJSON(store);
|
||||
return json;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include <chrono>
|
||||
#include <optional>
|
||||
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
|
||||
namespace nix {
|
||||
|
||||
struct BuildResult
|
||||
|
@ -46,28 +48,32 @@ struct BuildResult
|
|||
*/
|
||||
std::string errorMsg;
|
||||
|
||||
static std::string_view statusToString(Status status)
|
||||
{
|
||||
switch (status) {
|
||||
case Built: return "Built";
|
||||
case Substituted: return "Substituted";
|
||||
case AlreadyValid: return "AlreadyValid";
|
||||
case PermanentFailure: return "PermanentFailure";
|
||||
case InputRejected: return "InputRejected";
|
||||
case OutputRejected: return "OutputRejected";
|
||||
case TransientFailure: return "TransientFailure";
|
||||
case CachedFailure: return "CachedFailure";
|
||||
case TimedOut: return "TimedOut";
|
||||
case MiscFailure: return "MiscFailure";
|
||||
case DependencyFailed: return "DependencyFailed";
|
||||
case LogLimitExceeded: return "LogLimitExceeded";
|
||||
case NotDeterministic: return "NotDeterministic";
|
||||
case ResolvesToAlreadyValid: return "ResolvesToAlreadyValid";
|
||||
case NoSubstituters: return "NoSubstituters";
|
||||
default: return "Unknown";
|
||||
};
|
||||
}
|
||||
|
||||
std::string toString() const {
|
||||
auto strStatus = [&]() {
|
||||
switch (status) {
|
||||
case Built: return "Built";
|
||||
case Substituted: return "Substituted";
|
||||
case AlreadyValid: return "AlreadyValid";
|
||||
case PermanentFailure: return "PermanentFailure";
|
||||
case InputRejected: return "InputRejected";
|
||||
case OutputRejected: return "OutputRejected";
|
||||
case TransientFailure: return "TransientFailure";
|
||||
case CachedFailure: return "CachedFailure";
|
||||
case TimedOut: return "TimedOut";
|
||||
case MiscFailure: return "MiscFailure";
|
||||
case DependencyFailed: return "DependencyFailed";
|
||||
case LogLimitExceeded: return "LogLimitExceeded";
|
||||
case NotDeterministic: return "NotDeterministic";
|
||||
case ResolvesToAlreadyValid: return "ResolvesToAlreadyValid";
|
||||
case NoSubstituters: return "NoSubstituters";
|
||||
default: return "Unknown";
|
||||
};
|
||||
}();
|
||||
return strStatus + ((errorMsg == "") ? "" : " : " + errorMsg);
|
||||
return
|
||||
std::string(statusToString(status))
|
||||
+ ((errorMsg == "") ? "" : " : " + errorMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,6 +134,10 @@ struct KeyedBuildResult : BuildResult
|
|||
KeyedBuildResult(BuildResult res, DerivedPath path)
|
||||
: BuildResult(std::move(res)), path(std::move(path))
|
||||
{ }
|
||||
|
||||
nlohmann::json toJSON(Store & store) const;
|
||||
};
|
||||
|
||||
void to_json(nlohmann::json & json, const BuildResult & buildResult);
|
||||
|
||||
}
|
||||
|
|
|
@ -1563,6 +1563,13 @@ Goal::Done DerivationGoal::done(
|
|||
fs << worker.store.printStorePath(drvPath) << "\t" << buildResult.toString() << std::endl;
|
||||
}
|
||||
|
||||
logger->result(
|
||||
act ? act->id : getCurActivity(),
|
||||
resBuildResult,
|
||||
KeyedBuildResult(
|
||||
buildResult,
|
||||
DerivedPath::Built{.drvPath = makeConstantStorePathRef(drvPath), .outputs = wantedOutputs}).toJSON(worker.store));
|
||||
|
||||
return amDone(buildResult.success() ? ecSuccess : ecFailed, std::move(ex));
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,11 @@
|
|||
#include "nar-info.hh"
|
||||
#include "finally.hh"
|
||||
#include "signals.hh"
|
||||
|
||||
#include <coroutine>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace nix {
|
||||
|
||||
PathSubstitutionGoal::PathSubstitutionGoal(const StorePath & storePath, Worker & worker, RepairFlag repair, std::optional<ContentAddress> ca)
|
||||
|
@ -35,6 +38,14 @@ Goal::Done PathSubstitutionGoal::done(
|
|||
debug(*errorMsg);
|
||||
buildResult.errorMsg = *errorMsg;
|
||||
}
|
||||
|
||||
logger->result(
|
||||
getCurActivity(),
|
||||
resBuildResult,
|
||||
KeyedBuildResult(
|
||||
buildResult,
|
||||
DerivedPath::Opaque{storePath}).toJSON(worker.store));
|
||||
|
||||
return amDone(result);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ typedef enum {
|
|||
resPostBuildLogLine = 107,
|
||||
resFetchStatus = 108,
|
||||
resHashMismatch = 109,
|
||||
resBuildResult = 110,
|
||||
} ResultType;
|
||||
|
||||
typedef uint64_t ActivityId;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue