libstore: asyncify printClosureDiff

Change-Id: I4982d34e565f9e59931c4e675c2d142fcacce81f
This commit is contained in:
eldritch horrors
2025-02-23 17:18:48 +00:00
parent bc0e0786f0
commit cc3a9897e3
3 changed files with 18 additions and 11 deletions
+1 -1
View File
@@ -371,7 +371,7 @@ void completeFlakeRefWithFragment(
const Strings & defaultFlakeAttrPaths,
std::string_view prefix);
void printClosureDiff(
kj::Promise<Result<void>> printClosureDiff(
ref<Store> store,
const StorePath & beforePath,
const StorePath & afterPath,
+15 -8
View File
@@ -4,6 +4,7 @@
#include "lix/libstore/store-api.hh"
#include "lix/libmain/common-args.hh"
#include "lix/libstore/names.hh"
#include "lix/libutil/result.hh"
#include <regex>
@@ -17,8 +18,9 @@ struct Info
// name -> version -> store paths
typedef std::map<std::string, std::map<std::string, std::map<StorePath, Info>>> GroupedPaths;
GroupedPaths getClosureInfo(ref<Store> store, const StorePath & toplevel)
{
static kj::Promise<Result<GroupedPaths>>
getClosureInfo(ref<Store> store, const StorePath & toplevel)
try {
StorePathSet closure;
store->computeFSClosure({toplevel}, closure);
@@ -43,17 +45,19 @@ GroupedPaths getClosureInfo(ref<Store> store, const StorePath & toplevel)
groupedPaths[drvName.name][drvName.version].emplace(path, Info { .outputName = outputName });
}
return groupedPaths;
co_return groupedPaths;
} catch (...) {
co_return result::current_exception();
}
void printClosureDiff(
kj::Promise<Result<void>> printClosureDiff(
ref<Store> store,
const StorePath & beforePath,
const StorePath & afterPath,
std::string_view indent)
{
auto beforeClosure = getClosureInfo(store, beforePath);
auto afterClosure = getClosureInfo(store, afterPath);
try {
auto beforeClosure = TRY_AWAIT(getClosureInfo(store, beforePath));
auto afterClosure = TRY_AWAIT(getClosureInfo(store, afterPath));
std::set<std::string> allNames;
for (auto & [name, _] : beforeClosure) allNames.insert(name);
@@ -94,6 +98,9 @@ void printClosureDiff(
logger->cout("%s%s: %s", indent, name, concatStringsSep(", ", items));
}
}
co_return result::success();
} catch (...) {
co_return result::current_exception();
}
}
@@ -129,7 +136,7 @@ struct CmdDiffClosures : SourceExprCommand, MixOperateOnOptions
auto beforePath = Installable::toStorePath(*state, getEvalStore(), store, Realise::Outputs, operateOn, before);
auto after = parseInstallable(*state, store, _after);
auto afterPath = Installable::toStorePath(*state, getEvalStore(), store, Realise::Outputs, operateOn, after);
printClosureDiff(store, beforePath, afterPath, "");
aio().blockOn(printClosureDiff(store, beforePath, afterPath, ""));
}
};
+2 -2
View File
@@ -478,10 +478,10 @@ struct CmdProfileDiffClosures : virtual StoreCommand, MixDefaultProfile
if (!first) logger->cout("");
first = false;
logger->cout("Version %d -> %d:", prevGen->number, gen.number);
printClosureDiff(store,
aio().blockOn(printClosureDiff(store,
store->followLinksToStorePath(prevGen->path),
store->followLinksToStorePath(gen.path),
" ");
" "));
}
prevGen = gen;