libstore: asyncify a bunch of toJSON methods
why these are allowed to do IO that can end up blocking is beyond us Change-Id: I9718900b016b3c0755d5bb668a5c270546cc4b17
This commit is contained in:
+25
-16
@@ -80,38 +80,47 @@ SingleDerivedPath SingleBuiltPath::discardOutputPath() const
|
||||
);
|
||||
}
|
||||
|
||||
nlohmann::json BuiltPath::Built::toJSON(const Store & store) const
|
||||
{
|
||||
kj::Promise<Result<nlohmann::json>> BuiltPath::Built::toJSON(const Store & store) const
|
||||
try {
|
||||
nlohmann::json res;
|
||||
res["drvPath"] = drvPath->toJSON(store);
|
||||
res["drvPath"] = TRY_AWAIT(drvPath->toJSON(store));
|
||||
for (const auto & [outputName, outputPath] : outputs) {
|
||||
res["outputs"][outputName] = store.printStorePath(outputPath);
|
||||
}
|
||||
return res;
|
||||
co_return res;
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
nlohmann::json SingleBuiltPath::Built::toJSON(const Store & store) const
|
||||
{
|
||||
kj::Promise<Result<nlohmann::json>> SingleBuiltPath::Built::toJSON(const Store & store) const
|
||||
try {
|
||||
nlohmann::json res;
|
||||
res["drvPath"] = drvPath->toJSON(store);
|
||||
res["drvPath"] = TRY_AWAIT(drvPath->toJSON(store));
|
||||
auto & [outputName, outputPath] = output;
|
||||
res["output"] = outputName;
|
||||
res["outputPath"] = store.printStorePath(outputPath);
|
||||
return res;
|
||||
co_return res;
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
nlohmann::json SingleBuiltPath::toJSON(const Store & store) const
|
||||
{
|
||||
return std::visit([&](const auto & buildable) {
|
||||
kj::Promise<Result<nlohmann::json>> SingleBuiltPath::toJSON(const Store & store) const
|
||||
try {
|
||||
co_return TRY_AWAIT(std::visit([&](const auto & buildable) {
|
||||
return buildable.toJSON(store);
|
||||
}, raw());
|
||||
}, raw()));
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
nlohmann::json BuiltPath::toJSON(const Store & store) const
|
||||
{
|
||||
return std::visit([&](const auto & buildable) {
|
||||
|
||||
kj::Promise<Result<nlohmann::json>> BuiltPath::toJSON(const Store & store) const
|
||||
try {
|
||||
co_return TRY_AWAIT(std::visit([&](const auto & buildable) {
|
||||
return buildable.toJSON(store);
|
||||
}, raw());
|
||||
}, raw()));
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
kj::Promise<Result<RealisedPath::Set>> BuiltPath::toRealisedPaths(Store & store) const
|
||||
|
||||
@@ -17,7 +17,7 @@ struct SingleBuiltPathBuilt {
|
||||
|
||||
std::string to_string(const Store & store) const;
|
||||
static SingleBuiltPathBuilt parse(const Store & store, std::string_view, std::string_view);
|
||||
nlohmann::json toJSON(const Store & store) const;
|
||||
kj::Promise<Result<nlohmann::json>> toJSON(const Store & store) const;
|
||||
|
||||
DECLARE_CMP(SingleBuiltPathBuilt);
|
||||
};
|
||||
@@ -45,7 +45,7 @@ struct SingleBuiltPath : built_path::detail::SingleBuiltPathRaw {
|
||||
SingleDerivedPath discardOutputPath() const;
|
||||
|
||||
static SingleBuiltPath parse(const Store & store, std::string_view);
|
||||
nlohmann::json toJSON(const Store & store) const;
|
||||
kj::Promise<Result<nlohmann::json>> toJSON(const Store & store) const;
|
||||
};
|
||||
|
||||
static inline ref<SingleBuiltPath> staticDrv(StorePath drvPath)
|
||||
@@ -64,7 +64,7 @@ struct BuiltPathBuilt {
|
||||
|
||||
std::string to_string(const Store & store) const;
|
||||
static BuiltPathBuilt parse(const Store & store, std::string_view, std::string_view);
|
||||
nlohmann::json toJSON(const Store & store) const;
|
||||
kj::Promise<Result<nlohmann::json>> toJSON(const Store & store) const;
|
||||
|
||||
DECLARE_CMP(BuiltPathBuilt);
|
||||
};
|
||||
@@ -94,7 +94,7 @@ struct BuiltPath : built_path::detail::BuiltPathRaw {
|
||||
StorePathSet outPaths() const;
|
||||
kj::Promise<Result<RealisedPath::Set>> toRealisedPaths(Store & store) const;
|
||||
|
||||
nlohmann::json toJSON(const Store & store) const;
|
||||
kj::Promise<Result<nlohmann::json>> toJSON(const Store & store) const;
|
||||
};
|
||||
|
||||
typedef std::vector<BuiltPath> BuiltPaths;
|
||||
|
||||
@@ -28,14 +28,17 @@ CMP(SingleDerivedPath, DerivedPathBuilt, outputs)
|
||||
#undef CMP
|
||||
#undef CMP_ONE
|
||||
|
||||
nlohmann::json DerivedPath::Opaque::toJSON(const Store & store) const
|
||||
{
|
||||
return store.printStorePath(path);
|
||||
kj::Promise<Result<nlohmann::json>> DerivedPath::Opaque::toJSON(const Store & store) const
|
||||
try {
|
||||
return {store.printStorePath(path)};
|
||||
} catch (...) {
|
||||
return {result::current_exception()};
|
||||
}
|
||||
|
||||
nlohmann::json SingleDerivedPath::Built::toJSON(Store & store) const {
|
||||
kj::Promise<Result<nlohmann::json>> SingleDerivedPath::Built::toJSON(Store & store) const
|
||||
try {
|
||||
nlohmann::json res;
|
||||
res["drvPath"] = drvPath->toJSON(store);
|
||||
res["drvPath"] = TRY_AWAIT(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
|
||||
@@ -48,12 +51,15 @@ nlohmann::json SingleDerivedPath::Built::toJSON(Store & store) const {
|
||||
res["outputPath"] = store.printStorePath(*p);
|
||||
else
|
||||
res["outputPath"] = nullptr;
|
||||
return res;
|
||||
co_return res;
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
nlohmann::json DerivedPath::Built::toJSON(Store & store) const {
|
||||
kj::Promise<Result<nlohmann::json>> DerivedPath::Built::toJSON(Store & store) const
|
||||
try {
|
||||
nlohmann::json res;
|
||||
res["drvPath"] = drvPath->toJSON(store);
|
||||
res["drvPath"] = TRY_AWAIT(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
|
||||
@@ -65,21 +71,27 @@ nlohmann::json DerivedPath::Built::toJSON(Store & store) const {
|
||||
else
|
||||
res["outputs"][output] = nullptr;
|
||||
}
|
||||
return res;
|
||||
co_return res;
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
nlohmann::json SingleDerivedPath::toJSON(Store & store) const
|
||||
{
|
||||
return std::visit([&](const auto & buildable) {
|
||||
kj::Promise<Result<nlohmann::json>> SingleDerivedPath::toJSON(Store & store) const
|
||||
try {
|
||||
co_return TRY_AWAIT(std::visit([&](const auto & buildable) {
|
||||
return buildable.toJSON(store);
|
||||
}, raw());
|
||||
}, raw()));
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
nlohmann::json DerivedPath::toJSON(Store & store) const
|
||||
{
|
||||
return std::visit([&](const auto & buildable) {
|
||||
kj::Promise<Result<nlohmann::json>> DerivedPath::toJSON(Store & store) const
|
||||
try {
|
||||
co_return TRY_AWAIT(std::visit([&](const auto & buildable) {
|
||||
return buildable.toJSON(store);
|
||||
}, raw());
|
||||
}, raw()));
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
std::string DerivedPath::Opaque::to_string(const Store & store) const
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
#include "lix/libstore/outputs-spec.hh"
|
||||
#include "lix/libutil/comparator.hh"
|
||||
#include "lix/libutil/ref.hh"
|
||||
#include "lix/libutil/result.hh"
|
||||
|
||||
#include <kj/async.h>
|
||||
#include <variant>
|
||||
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
@@ -27,7 +29,7 @@ struct DerivedPathOpaque {
|
||||
|
||||
std::string to_string(const Store & store) const;
|
||||
static DerivedPathOpaque parse(const Store & store, std::string_view);
|
||||
nlohmann::json toJSON(const Store & store) const;
|
||||
kj::Promise<Result<nlohmann::json>> toJSON(const Store & store) const;
|
||||
|
||||
GENERATE_CMP(DerivedPathOpaque, me->path);
|
||||
};
|
||||
@@ -74,7 +76,7 @@ struct SingleDerivedPathBuilt {
|
||||
const Store & store, ref<SingleDerivedPath> drvPath,
|
||||
OutputNameView outputs,
|
||||
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
|
||||
nlohmann::json toJSON(Store & store) const;
|
||||
kj::Promise<Result<nlohmann::json>> toJSON(Store & store) const;
|
||||
|
||||
DECLARE_CMP(SingleDerivedPathBuilt);
|
||||
};
|
||||
@@ -146,7 +148,7 @@ struct SingleDerivedPath : derived_path::detail::SingleDerivedPathRaw {
|
||||
const Store & store,
|
||||
std::string_view,
|
||||
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
|
||||
nlohmann::json toJSON(Store & store) const;
|
||||
kj::Promise<Result<nlohmann::json>> toJSON(Store & store) const;
|
||||
};
|
||||
|
||||
static inline ref<SingleDerivedPath> makeConstantStorePathRef(StorePath drvPath)
|
||||
@@ -199,7 +201,7 @@ struct DerivedPathBuilt {
|
||||
const Store & store, ref<SingleDerivedPath>,
|
||||
std::string_view,
|
||||
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
|
||||
nlohmann::json toJSON(Store & store) const;
|
||||
kj::Promise<Result<nlohmann::json>> toJSON(Store & store) const;
|
||||
|
||||
DECLARE_CMP(DerivedPathBuilt);
|
||||
};
|
||||
@@ -276,7 +278,7 @@ struct DerivedPath : derived_path::detail::DerivedPathRaw {
|
||||
*/
|
||||
static DerivedPath fromSingle(const SingleDerivedPath &);
|
||||
|
||||
nlohmann::json toJSON(Store & store) const;
|
||||
kj::Promise<Result<nlohmann::json>> toJSON(Store & store) const;
|
||||
};
|
||||
|
||||
typedef std::vector<DerivedPath> DerivedPaths;
|
||||
|
||||
+8
-6
@@ -9,23 +9,25 @@
|
||||
|
||||
using namespace nix;
|
||||
|
||||
static nlohmann::json derivedPathsToJSON(const DerivedPaths & paths, Store & store)
|
||||
static nlohmann::json derivedPathsToJSON(AsyncIoRoot & aio, const DerivedPaths & paths, Store & store)
|
||||
{
|
||||
auto res = nlohmann::json::array();
|
||||
for (auto & t : paths) {
|
||||
std::visit([&](const auto & t) {
|
||||
res.push_back(t.toJSON(store));
|
||||
res.push_back(aio.blockOn(t.toJSON(store)));
|
||||
}, t.raw());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static nlohmann::json builtPathsWithResultToJSON(const std::vector<BuiltPathWithResult> & buildables, const Store & store)
|
||||
static nlohmann::json builtPathsWithResultToJSON(
|
||||
AsyncIoRoot & aio, const std::vector<BuiltPathWithResult> & buildables, const Store & store
|
||||
)
|
||||
{
|
||||
auto res = nlohmann::json::array();
|
||||
for (auto & b : buildables) {
|
||||
std::visit([&](const auto & t) {
|
||||
auto j = t.toJSON(store);
|
||||
auto j = aio.blockOn(t.toJSON(store));
|
||||
if (b.result) {
|
||||
if (b.result->startTime)
|
||||
j["startTime"] = b.result->startTime;
|
||||
@@ -132,7 +134,7 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile
|
||||
printMissing(store, pathsToBuild, lvlError);
|
||||
|
||||
if (json)
|
||||
logger->cout("%s", derivedPathsToJSON(pathsToBuild, *store).dump());
|
||||
logger->cout("%s", derivedPathsToJSON(aio(), pathsToBuild, *store).dump());
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -143,7 +145,7 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile
|
||||
installables,
|
||||
repair ? bmRepair : buildMode);
|
||||
|
||||
if (json) logger->cout("%s", builtPathsWithResultToJSON(buildables, *store).dump());
|
||||
if (json) logger->cout("%s", builtPathsWithResultToJSON(aio(), buildables, *store).dump());
|
||||
|
||||
if (outLink != "")
|
||||
if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>())
|
||||
|
||||
Reference in New Issue
Block a user