forked from lix-project/lix
Include the name in the JSON for derivations
This is non-breaking change in the to-JSON direction. This *is* a breaking change in the from-JSON direction, but we don't care, as that is brand new in this PR. `nix show-derivation --help` currently has the sole public documentation of this format, it is updated accordingly.
This commit is contained in:
parent
fe9cbe838c
commit
b200784cec
|
@ -988,6 +988,8 @@ nlohmann::json Derivation::toJSON(const Store & store) const
|
||||||
{
|
{
|
||||||
nlohmann::json res = nlohmann::json::object();
|
nlohmann::json res = nlohmann::json::object();
|
||||||
|
|
||||||
|
res["name"] = name;
|
||||||
|
|
||||||
{
|
{
|
||||||
nlohmann::json & outputsObj = res["outputs"];
|
nlohmann::json & outputsObj = res["outputs"];
|
||||||
outputsObj = nlohmann::json::object();
|
outputsObj = nlohmann::json::object();
|
||||||
|
@ -1020,17 +1022,19 @@ nlohmann::json Derivation::toJSON(const Store & store) const
|
||||||
|
|
||||||
|
|
||||||
Derivation Derivation::fromJSON(
|
Derivation Derivation::fromJSON(
|
||||||
const Store & store, std::string_view drvName,
|
const Store & store,
|
||||||
const nlohmann::json & json)
|
const nlohmann::json & json)
|
||||||
{
|
{
|
||||||
Derivation res;
|
Derivation res;
|
||||||
|
|
||||||
|
res.name = json["name"];
|
||||||
|
|
||||||
{
|
{
|
||||||
auto & outputsObj = json["outputs"];
|
auto & outputsObj = json["outputs"];
|
||||||
for (auto & [outputName, output] : outputsObj.items()) {
|
for (auto & [outputName, output] : outputsObj.items()) {
|
||||||
res.outputs.insert_or_assign(
|
res.outputs.insert_or_assign(
|
||||||
outputName,
|
outputName,
|
||||||
DerivationOutput::fromJSON(store, drvName, outputName, output));
|
DerivationOutput::fromJSON(store, res.name, outputName, output));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -340,7 +340,6 @@ struct Derivation : BasicDerivation
|
||||||
nlohmann::json toJSON(const Store & store) const;
|
nlohmann::json toJSON(const Store & store) const;
|
||||||
static Derivation fromJSON(
|
static Derivation fromJSON(
|
||||||
const Store & store,
|
const Store & store,
|
||||||
std::string_view drvName,
|
|
||||||
const nlohmann::json & json);
|
const nlohmann::json & json);
|
||||||
|
|
||||||
GENERATE_CMP(Derivation,
|
GENERATE_CMP(Derivation,
|
||||||
|
|
|
@ -98,12 +98,12 @@ TEST_JSON(impure,
|
||||||
Derivation { VAL }, \
|
Derivation { VAL }, \
|
||||||
Derivation::fromJSON( \
|
Derivation::fromJSON( \
|
||||||
*store, \
|
*store, \
|
||||||
DRV_NAME, \
|
|
||||||
STR ## _json)); \
|
STR ## _json)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_JSON(simple,
|
TEST_JSON(simple,
|
||||||
R"({
|
R"({
|
||||||
|
"name": "my-derivation",
|
||||||
"inputSrcs": [
|
"inputSrcs": [
|
||||||
"/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"
|
"/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"
|
||||||
],
|
],
|
||||||
|
@ -126,6 +126,7 @@ TEST_JSON(simple,
|
||||||
})",
|
})",
|
||||||
({
|
({
|
||||||
Derivation drv;
|
Derivation drv;
|
||||||
|
drv.name = "my-derivation";
|
||||||
drv.inputSrcs = {
|
drv.inputSrcs = {
|
||||||
store->parseStorePath("/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"),
|
store->parseStorePath("/nix/store/c015dhfh5l0lp6wxyvdn7bmwhbbr6hr9-dep1"),
|
||||||
};
|
};
|
||||||
|
|
|
@ -51,6 +51,9 @@ The JSON output is a JSON object whose keys are the store paths of the
|
||||||
derivations, and whose values are a JSON object with the following
|
derivations, and whose values are a JSON object with the following
|
||||||
fields:
|
fields:
|
||||||
|
|
||||||
|
* `name`: The name of the derivation. This is used when calculating the
|
||||||
|
store paths of the derivation's outputs.
|
||||||
|
|
||||||
* `outputs`: Information about the output paths of the
|
* `outputs`: Information about the output paths of the
|
||||||
derivation. This is a JSON object with one member per output, where
|
derivation. This is a JSON object with one member per output, where
|
||||||
the key is the output name and the value is a JSON object with these
|
the key is the output name and the value is a JSON object with these
|
||||||
|
|
Loading…
Reference in a new issue