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 "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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,8 +48,8 @@ struct BuildResult
|
||||||
*/
|
*/
|
||||||
std::string errorMsg;
|
std::string errorMsg;
|
||||||
|
|
||||||
std::string toString() const {
|
static std::string_view statusToString(Status status)
|
||||||
auto strStatus = [&]() {
|
{
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case Built: return "Built";
|
case Built: return "Built";
|
||||||
case Substituted: return "Substituted";
|
case Substituted: return "Substituted";
|
||||||
|
@ -66,8 +68,12 @@ struct BuildResult
|
||||||
case NoSubstituters: return "NoSubstituters";
|
case NoSubstituters: return "NoSubstituters";
|
||||||
default: return "Unknown";
|
default: return "Unknown";
|
||||||
};
|
};
|
||||||
}();
|
}
|
||||||
return strStatus + ((errorMsg == "") ? "" : " : " + errorMsg);
|
|
||||||
|
std::string toString() const {
|
||||||
|
return
|
||||||
|
std::string(statusToString(status))
|
||||||
|
+ ((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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue