mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +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);
|
return store.printStorePath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json SingleDerivedPath::Built::toJSON(Store & store) const {
|
nlohmann::json SingleDerivedPath::Built::toJSON(const StoreDirConfig & store) const
|
||||||
nlohmann::json res;
|
{
|
||||||
res["drvPath"] = drvPath->toJSON(store);
|
return nlohmann::json{
|
||||||
// Fallback for the input-addressed derivation case: We expect to always be
|
{"drvPath", drvPath->toJSON(store)},
|
||||||
// able to print the output paths, so let’s do it
|
{"output", output},
|
||||||
// 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 DerivedPath::Built::toJSON(Store & store) const {
|
nlohmann::json DerivedPath::Built::toJSON(const StoreDirConfig & store) const
|
||||||
nlohmann::json res;
|
{
|
||||||
res["drvPath"] = drvPath->toJSON(store);
|
return nlohmann::json{
|
||||||
// Fallback for the input-addressed derivation case: We expect to always be
|
{"drvPath", drvPath->toJSON(store)},
|
||||||
// able to print the output paths, so let’s do it
|
{"outputs", outputs},
|
||||||
// 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 SingleDerivedPath::toJSON(Store & store) const
|
nlohmann::json SingleDerivedPath::toJSON(const StoreDirConfig & store) const
|
||||||
{
|
{
|
||||||
return std::visit([&](const auto & buildable) {
|
return std::visit([&](const auto & buildable) {
|
||||||
return buildable.toJSON(store);
|
return buildable.toJSON(store);
|
||||||
}, raw());
|
}, raw());
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json DerivedPath::toJSON(Store & store) const
|
nlohmann::json DerivedPath::toJSON(const StoreDirConfig & store) const
|
||||||
{
|
{
|
||||||
return std::visit([&](const auto & buildable) {
|
return std::visit([&](const auto & buildable) {
|
||||||
return buildable.toJSON(store);
|
return buildable.toJSON(store);
|
||||||
|
|
|
@ -77,7 +77,7 @@ struct SingleDerivedPathBuilt {
|
||||||
const StoreDirConfig & store, ref<const SingleDerivedPath> drvPath,
|
const StoreDirConfig & store, ref<const SingleDerivedPath> drvPath,
|
||||||
OutputNameView outputs,
|
OutputNameView outputs,
|
||||||
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
|
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
|
||||||
nlohmann::json toJSON(Store & store) const;
|
nlohmann::json toJSON(const StoreDirConfig & store) const;
|
||||||
|
|
||||||
bool operator == (const SingleDerivedPathBuilt &) const noexcept;
|
bool operator == (const SingleDerivedPathBuilt &) const noexcept;
|
||||||
std::strong_ordering operator <=> (const SingleDerivedPathBuilt &) const noexcept;
|
std::strong_ordering operator <=> (const SingleDerivedPathBuilt &) const noexcept;
|
||||||
|
@ -151,7 +151,7 @@ struct SingleDerivedPath : _SingleDerivedPathRaw {
|
||||||
const StoreDirConfig & store,
|
const StoreDirConfig & store,
|
||||||
std::string_view,
|
std::string_view,
|
||||||
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
|
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
|
||||||
nlohmann::json toJSON(Store & store) const;
|
nlohmann::json toJSON(const StoreDirConfig & store) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline ref<SingleDerivedPath> makeConstantStorePathRef(StorePath drvPath)
|
static inline ref<SingleDerivedPath> makeConstantStorePathRef(StorePath drvPath)
|
||||||
|
@ -204,7 +204,7 @@ struct DerivedPathBuilt {
|
||||||
const StoreDirConfig & store, ref<const SingleDerivedPath>,
|
const StoreDirConfig & store, ref<const SingleDerivedPath>,
|
||||||
std::string_view,
|
std::string_view,
|
||||||
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
|
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
|
||||||
nlohmann::json toJSON(Store & store) const;
|
nlohmann::json toJSON(const StoreDirConfig & store) const;
|
||||||
|
|
||||||
bool operator == (const DerivedPathBuilt &) const noexcept;
|
bool operator == (const DerivedPathBuilt &) const noexcept;
|
||||||
// TODO libc++ 16 (used by darwin) missing `std::set::operator <=>`, can't do yet.
|
// 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 &);
|
static DerivedPath fromSingle(const SingleDerivedPath &);
|
||||||
|
|
||||||
nlohmann::json toJSON(Store & store) const;
|
nlohmann::json toJSON(const StoreDirConfig & store) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<DerivedPath> DerivedPaths;
|
typedef std::vector<DerivedPath> DerivedPaths;
|
||||||
|
|
|
@ -58,14 +58,7 @@ clearCache
|
||||||
|
|
||||||
RES=$(nix build -f dependencies.nix --dry-run --json)
|
RES=$(nix build -f dependencies.nix --dry-run --json)
|
||||||
|
|
||||||
if [[ -z "${NIX_TESTS_CA_BY_DEFAULT-}" ]]; then
|
|
||||||
echo "$RES" | jq '.[0] | [
|
echo "$RES" | jq '.[0] | [
|
||||||
(.drvPath | test("'"$NIX_STORE_DIR"'.*\\.drv")),
|
(.drvPath | test("'"$NIX_STORE_DIR"'.*\\.drv")),
|
||||||
(.outputs.out | test("'"$NIX_STORE_DIR"'"))
|
.outputs == [ "out" ]
|
||||||
] | all'
|
] | all'
|
||||||
else
|
|
||||||
echo "$RES" | jq '.[0] | [
|
|
||||||
(.drvPath | test("'"$NIX_STORE_DIR"'.*\\.drv")),
|
|
||||||
.outputs.out == null
|
|
||||||
] | all'
|
|
||||||
fi
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue