libstore: asyncify ParsedDerivation::prepareStructuredAttrs
Change-Id: I6c34bb5fc67046a0c25486bf4f2fa5bbaa62eacf
This commit is contained in:
@@ -470,7 +470,7 @@ static void main_nix_build(AsyncIoRoot & aio, std::string programName, Strings a
|
||||
|
||||
ParsedDerivation parsedDrv(drvInfo.requireDrvPath(*state), drv);
|
||||
|
||||
if (auto structAttrs = parsedDrv.prepareStructuredAttrs(*store, inputs)) {
|
||||
if (auto structAttrs = aio.blockOn(parsedDrv.prepareStructuredAttrs(*store, inputs))) {
|
||||
auto json = structAttrs.value();
|
||||
structuredAttrsRC = writeStructuredAttrsShell(json);
|
||||
|
||||
|
||||
@@ -916,7 +916,9 @@ void LocalDerivationGoal::initEnv()
|
||||
|
||||
kj::Promise<Result<void>> LocalDerivationGoal::writeStructuredAttrs()
|
||||
try {
|
||||
if (auto structAttrsJson = parsedDrv->prepareStructuredAttrs(worker.store, inputPaths)) {
|
||||
if (auto structAttrsJson =
|
||||
TRY_AWAIT(parsedDrv->prepareStructuredAttrs(worker.store, inputPaths)))
|
||||
{
|
||||
auto json = structAttrsJson.value();
|
||||
nlohmann::json rewritten;
|
||||
for (auto & [i, v] : json["outputs"].get<nlohmann::json::object_t>()) {
|
||||
|
||||
@@ -134,10 +134,11 @@ bool ParsedDerivation::useUidRange() const
|
||||
|
||||
static std::regex shVarName("[A-Za-z_][A-Za-z0-9_]*");
|
||||
|
||||
std::optional<nlohmann::json> ParsedDerivation::prepareStructuredAttrs(Store & store, const StorePathSet & inputPaths)
|
||||
{
|
||||
kj::Promise<Result<std::optional<nlohmann::json>>>
|
||||
ParsedDerivation::prepareStructuredAttrs(Store & store, const StorePathSet & inputPaths)
|
||||
try {
|
||||
auto structuredAttrs = getStructuredAttrs();
|
||||
if (!structuredAttrs) return std::nullopt;
|
||||
if (!structuredAttrs) co_return std::nullopt;
|
||||
|
||||
auto json = *structuredAttrs;
|
||||
|
||||
@@ -155,12 +156,14 @@ std::optional<nlohmann::json> ParsedDerivation::prepareStructuredAttrs(Store & s
|
||||
for (auto & p : *i)
|
||||
storePaths.insert(store.toStorePath(p.get<std::string>()).first);
|
||||
json[i.key()] = store.pathInfoToJSON(
|
||||
RUN_ASYNC_IN_NEW_THREAD(store.exportReferences(storePaths, inputPaths)), false, true
|
||||
TRY_AWAIT(store.exportReferences(storePaths, inputPaths)), false, true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return json;
|
||||
co_return json;
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
/* As a convenience to bash scripts, write a shell file that
|
||||
|
||||
@@ -41,7 +41,8 @@ public:
|
||||
|
||||
bool useUidRange() const;
|
||||
|
||||
std::optional<nlohmann::json> prepareStructuredAttrs(Store & store, const StorePathSet & inputPaths);
|
||||
kj::Promise<Result<std::optional<nlohmann::json>>>
|
||||
prepareStructuredAttrs(Store & store, const StorePathSet & inputPaths);
|
||||
};
|
||||
|
||||
std::string writeStructuredAttrsShell(const nlohmann::json & json);
|
||||
|
||||
Reference in New Issue
Block a user