mirror of
https://github.com/NixOS/nix
synced 2025-06-24 22:11:15 +02:00
Don't do store operations in *DerivedPath::toJSON
It is inappropriate to do "real work" when converting plain old data to JSON.
This commit is contained in:
parent
fd25391628
commit
fb028ae701
3 changed files with 22 additions and 48 deletions
|
@ -41,49 +41,30 @@ nlohmann::json DerivedPath::Opaque::toJSON(const StoreDirConfig & store) const
|
|||
return store.printStorePath(path);
|
||||
}
|
||||
|
||||
nlohmann::json SingleDerivedPath::Built::toJSON(Store & store) const {
|
||||
nlohmann::json res;
|
||||
res["drvPath"] = drvPath->toJSON(store);
|
||||
// Fallback for the input-addressed derivation case: We expect to always be
|
||||
// able to print the output paths, so let’s do it
|
||||
// FIXME try-resolve on drvPath
|
||||
const auto outputMap = store.queryPartialDerivationOutputMap(resolveDerivedPath(store, *drvPath));
|
||||
res["output"] = output;
|
||||
auto outputPathIter = outputMap.find(output);
|
||||
if (outputPathIter == outputMap.end())
|
||||
res["outputPath"] = nullptr;
|
||||
else if (std::optional p = outputPathIter->second)
|
||||
res["outputPath"] = store.printStorePath(*p);
|
||||
else
|
||||
res["outputPath"] = nullptr;
|
||||
return res;
|
||||
nlohmann::json SingleDerivedPath::Built::toJSON(const StoreDirConfig & store) const
|
||||
{
|
||||
return nlohmann::json{
|
||||
{"drvPath", drvPath->toJSON(store)},
|
||||
{"output", output},
|
||||
};
|
||||
}
|
||||
|
||||
nlohmann::json DerivedPath::Built::toJSON(Store & store) const {
|
||||
nlohmann::json res;
|
||||
res["drvPath"] = drvPath->toJSON(store);
|
||||
// Fallback for the input-addressed derivation case: We expect to always be
|
||||
// able to print the output paths, so let’s do it
|
||||
// FIXME try-resolve on drvPath
|
||||
const auto outputMap = store.queryPartialDerivationOutputMap(resolveDerivedPath(store, *drvPath));
|
||||
for (const auto & [output, outputPathOpt] : outputMap) {
|
||||
if (!outputs.contains(output)) continue;
|
||||
if (outputPathOpt)
|
||||
res["outputs"][output] = store.printStorePath(*outputPathOpt);
|
||||
else
|
||||
res["outputs"][output] = nullptr;
|
||||
}
|
||||
return res;
|
||||
nlohmann::json DerivedPath::Built::toJSON(const StoreDirConfig & store) const
|
||||
{
|
||||
return nlohmann::json{
|
||||
{"drvPath", drvPath->toJSON(store)},
|
||||
{"outputs", outputs},
|
||||
};
|
||||
}
|
||||
|
||||
nlohmann::json SingleDerivedPath::toJSON(Store & store) const
|
||||
nlohmann::json SingleDerivedPath::toJSON(const StoreDirConfig & store) const
|
||||
{
|
||||
return std::visit([&](const auto & buildable) {
|
||||
return buildable.toJSON(store);
|
||||
}, raw());
|
||||
}
|
||||
|
||||
nlohmann::json DerivedPath::toJSON(Store & store) const
|
||||
nlohmann::json DerivedPath::toJSON(const StoreDirConfig & store) const
|
||||
{
|
||||
return std::visit([&](const auto & buildable) {
|
||||
return buildable.toJSON(store);
|
||||
|
|
|
@ -77,7 +77,7 @@ struct SingleDerivedPathBuilt {
|
|||
const StoreDirConfig & store, ref<const SingleDerivedPath> drvPath,
|
||||
OutputNameView outputs,
|
||||
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
|
||||
nlohmann::json toJSON(Store & store) const;
|
||||
nlohmann::json toJSON(const StoreDirConfig & store) const;
|
||||
|
||||
bool operator == (const SingleDerivedPathBuilt &) const noexcept;
|
||||
std::strong_ordering operator <=> (const SingleDerivedPathBuilt &) const noexcept;
|
||||
|
@ -151,7 +151,7 @@ struct SingleDerivedPath : _SingleDerivedPathRaw {
|
|||
const StoreDirConfig & store,
|
||||
std::string_view,
|
||||
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
|
||||
nlohmann::json toJSON(Store & store) const;
|
||||
nlohmann::json toJSON(const StoreDirConfig & store) const;
|
||||
};
|
||||
|
||||
static inline ref<SingleDerivedPath> makeConstantStorePathRef(StorePath drvPath)
|
||||
|
@ -204,7 +204,7 @@ struct DerivedPathBuilt {
|
|||
const StoreDirConfig & store, ref<const SingleDerivedPath>,
|
||||
std::string_view,
|
||||
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
|
||||
nlohmann::json toJSON(Store & store) const;
|
||||
nlohmann::json toJSON(const StoreDirConfig & store) const;
|
||||
|
||||
bool operator == (const DerivedPathBuilt &) const noexcept;
|
||||
// TODO libc++ 16 (used by darwin) missing `std::set::operator <=>`, can't do yet.
|
||||
|
@ -285,7 +285,7 @@ struct DerivedPath : _DerivedPathRaw {
|
|||
*/
|
||||
static DerivedPath fromSingle(const SingleDerivedPath &);
|
||||
|
||||
nlohmann::json toJSON(Store & store) const;
|
||||
nlohmann::json toJSON(const StoreDirConfig & store) const;
|
||||
};
|
||||
|
||||
typedef std::vector<DerivedPath> DerivedPaths;
|
||||
|
|
|
@ -58,14 +58,7 @@ clearCache
|
|||
|
||||
RES=$(nix build -f dependencies.nix --dry-run --json)
|
||||
|
||||
if [[ -z "${NIX_TESTS_CA_BY_DEFAULT-}" ]]; then
|
||||
echo "$RES" | jq '.[0] | [
|
||||
(.drvPath | test("'"$NIX_STORE_DIR"'.*\\.drv")),
|
||||
(.outputs.out | test("'"$NIX_STORE_DIR"'"))
|
||||
] | all'
|
||||
else
|
||||
echo "$RES" | jq '.[0] | [
|
||||
(.drvPath | test("'"$NIX_STORE_DIR"'.*\\.drv")),
|
||||
.outputs.out == null
|
||||
] | all'
|
||||
fi
|
||||
echo "$RES" | jq '.[0] | [
|
||||
(.drvPath | test("'"$NIX_STORE_DIR"'.*\\.drv")),
|
||||
.outputs == [ "out" ]
|
||||
] | all'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue