1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-08 06:53:54 +02:00

Log BuildResult

This commit is contained in:
Eelco Dolstra 2025-03-13 19:42:52 +01:00
parent c515bc66f1
commit 762114b7c4
5 changed files with 75 additions and 21 deletions

View file

@ -1,8 +1,33 @@
#include "build-result.hh" #include "build-result.hh"
#include <nlohmann/json.hpp>
namespace nix { namespace nix {
bool BuildResult::operator==(const BuildResult &) const noexcept = default; bool BuildResult::operator==(const BuildResult &) const noexcept = default;
std::strong_ordering 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;
}
} }

View file

@ -8,6 +8,8 @@
#include <chrono> #include <chrono>
#include <optional> #include <optional>
#include <nlohmann/json_fwd.hpp>
namespace nix { namespace nix {
struct BuildResult struct BuildResult
@ -46,28 +48,32 @@ struct BuildResult
*/ */
std::string errorMsg; 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 { std::string toString() const {
auto strStatus = [&]() { return
switch (status) { std::string(statusToString(status))
case Built: return "Built"; + ((errorMsg == "") ? "" : " : " + errorMsg);
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);
} }
/** /**
@ -128,6 +134,10 @@ struct KeyedBuildResult : BuildResult
KeyedBuildResult(BuildResult res, DerivedPath path) KeyedBuildResult(BuildResult res, DerivedPath path)
: BuildResult(std::move(res)), path(std::move(path)) : BuildResult(std::move(res)), path(std::move(path))
{ } { }
nlohmann::json toJSON(Store & store) const;
}; };
void to_json(nlohmann::json & json, const BuildResult & buildResult);
} }

View file

@ -1563,6 +1563,13 @@ Goal::Done DerivationGoal::done(
fs << worker.store.printStorePath(drvPath) << "\t" << buildResult.toString() << std::endl; 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)); return amDone(buildResult.success() ? ecSuccess : ecFailed, std::move(ex));
} }

View file

@ -3,8 +3,11 @@
#include "nar-info.hh" #include "nar-info.hh"
#include "finally.hh" #include "finally.hh"
#include "signals.hh" #include "signals.hh"
#include <coroutine> #include <coroutine>
#include <nlohmann/json.hpp>
namespace nix { namespace nix {
PathSubstitutionGoal::PathSubstitutionGoal(const StorePath & storePath, Worker & worker, RepairFlag repair, std::optional<ContentAddress> ca) PathSubstitutionGoal::PathSubstitutionGoal(const StorePath & storePath, Worker & worker, RepairFlag repair, std::optional<ContentAddress> ca)
@ -35,6 +38,14 @@ Goal::Done PathSubstitutionGoal::done(
debug(*errorMsg); debug(*errorMsg);
buildResult.errorMsg = *errorMsg; buildResult.errorMsg = *errorMsg;
} }
logger->result(
getCurActivity(),
resBuildResult,
KeyedBuildResult(
buildResult,
DerivedPath::Opaque{storePath}).toJSON(worker.store));
return amDone(result); return amDone(result);
} }

View file

@ -39,6 +39,7 @@ typedef enum {
resPostBuildLogLine = 107, resPostBuildLogLine = 107,
resFetchStatus = 108, resFetchStatus = 108,
resHashMismatch = 109, resHashMismatch = 109,
resBuildResult = 110,
} ResultType; } ResultType;
typedef uint64_t ActivityId; typedef uint64_t ActivityId;