libstore: asyncify Store::derivationFromPath
Change-Id: Ic6b54642da08f258c113d5076b34b7c13096f540
This commit is contained in:
@@ -327,7 +327,7 @@ static void main_nix_build(AsyncIoRoot & aio, std::string programName, Strings a
|
||||
throw UsageError("nix-shell requires a single derivation");
|
||||
|
||||
auto & drvInfo = drvs.front();
|
||||
auto drv = evalStore->derivationFromPath(drvInfo.requireDrvPath(*state));
|
||||
auto drv = aio.blockOn(evalStore->derivationFromPath(drvInfo.requireDrvPath(*state)));
|
||||
|
||||
std::vector<DerivedPath> pathsToBuild;
|
||||
RealisedPath::Set pathsToCopy;
|
||||
|
||||
@@ -69,7 +69,7 @@ try {
|
||||
if (path.path.isDerivation()) {
|
||||
if (build) TRY_AWAIT(store->buildPaths({path.toDerivedPath()}));
|
||||
auto outputPaths = store->queryDerivationOutputMap(path.path);
|
||||
Derivation drv = store->derivationFromPath(path.path);
|
||||
Derivation drv = TRY_AWAIT(store->derivationFromPath(path.path));
|
||||
rootNr++;
|
||||
|
||||
/* FIXME: Encode this empty special case explicitly in the type. */
|
||||
@@ -232,7 +232,7 @@ static kj::Promise<Result<StorePathSet>> maybeUseOutputs(const StorePath & store
|
||||
try {
|
||||
if (forceRealise) TRY_AWAIT(realisePath({storePath}));
|
||||
if (useOutput && storePath.isDerivation()) {
|
||||
auto drv = store->derivationFromPath(storePath);
|
||||
auto drv = TRY_AWAIT(store->derivationFromPath(storePath));
|
||||
StorePathSet outputs;
|
||||
if (forceRealise)
|
||||
co_return store->queryDerivationOutputs(storePath);
|
||||
@@ -394,7 +394,7 @@ static void opQuery(AsyncIoRoot & aio, Strings opFlags, Strings opArgs)
|
||||
case qBinding:
|
||||
for (auto & i : opArgs) {
|
||||
auto path = useDeriver(store->followLinksToStorePath(i));
|
||||
Derivation drv = store->derivationFromPath(path);
|
||||
Derivation drv = aio.blockOn(store->derivationFromPath(path));
|
||||
StringPairs::iterator j = drv.env.find(bindingName);
|
||||
if (j == drv.env.end())
|
||||
throw Error("derivation '%s' has no environment binding named '%s'",
|
||||
@@ -479,7 +479,7 @@ static void opPrintEnv(AsyncIoRoot & aio, Strings opFlags, Strings opArgs)
|
||||
if (opArgs.size() != 1) throw UsageError("'--print-env' requires one derivation store path");
|
||||
|
||||
Path drvPath = opArgs.front();
|
||||
Derivation drv = store->derivationFromPath(store->parseStorePath(drvPath));
|
||||
Derivation drv = aio.blockOn(store->derivationFromPath(store->parseStorePath(drvPath)));
|
||||
|
||||
/* Print each environment variable in the derivation in a format
|
||||
* that can be sourced by the shell. */
|
||||
|
||||
@@ -25,7 +25,7 @@ DrvInfo::DrvInfo(ref<Store> store, const std::string & drvPathWithOutputs)
|
||||
|
||||
this->drvPath = drvPath;
|
||||
|
||||
auto drv = store->derivationFromPath(drvPath);
|
||||
auto drv = RUN_ASYNC_IN_NEW_THREAD(store->derivationFromPath(drvPath));
|
||||
|
||||
name = drvPath.name();
|
||||
|
||||
|
||||
@@ -235,7 +235,7 @@ struct QueryMissingContext
|
||||
}
|
||||
if (knownOutputPaths && invalid.empty()) return;
|
||||
|
||||
auto drv = make_ref<Derivation>(store.derivationFromPath(drvPath));
|
||||
auto drv = make_ref<Derivation>(aio.blockOn(store.derivationFromPath(drvPath)));
|
||||
ParsedDerivation parsedDrv(StorePath(drvPath), *drv);
|
||||
|
||||
if (!knownOutputPaths && settings.useSubstitutes && parsedDrv.substitutesAllowed()) {
|
||||
|
||||
@@ -937,7 +937,7 @@ StorePathSet Store::exportReferences(const StorePathSet & storePaths, const Stor
|
||||
|
||||
for (auto & j : paths2) {
|
||||
if (j.isDerivation()) {
|
||||
Derivation drv = derivationFromPath(j);
|
||||
Derivation drv = RUN_ASYNC_IN_NEW_THREAD(derivationFromPath(j));
|
||||
for (auto & k : drv.outputsAndOptPaths(*this)) {
|
||||
if (!k.second.second)
|
||||
/* FIXME: I am confused why we are calling
|
||||
@@ -1359,10 +1359,12 @@ std::string showPaths(const PathSet & paths)
|
||||
}
|
||||
|
||||
|
||||
Derivation Store::derivationFromPath(const StorePath & drvPath)
|
||||
{
|
||||
RUN_ASYNC_IN_NEW_THREAD(ensurePath(drvPath));
|
||||
return readDerivation(drvPath);
|
||||
kj::Promise<Result<Derivation>> Store::derivationFromPath(const StorePath & drvPath)
|
||||
try {
|
||||
TRY_AWAIT(ensurePath(drvPath));
|
||||
co_return readDerivation(drvPath);
|
||||
} catch (...) {
|
||||
co_return result::current_exception();
|
||||
}
|
||||
|
||||
Derivation readDerivationCommon(Store& store, const StorePath& drvPath, bool requireValidPath)
|
||||
|
||||
@@ -732,7 +732,7 @@ public:
|
||||
* Read a derivation, after ensuring its existence through
|
||||
* ensurePath().
|
||||
*/
|
||||
Derivation derivationFromPath(const StorePath & drvPath);
|
||||
kj::Promise<Result<Derivation>> derivationFromPath(const StorePath & drvPath);
|
||||
|
||||
/**
|
||||
* Read a derivation (which must already be valid).
|
||||
|
||||
+1
-1
@@ -212,7 +212,7 @@ const static std::string getEnvSh =
|
||||
environment to a file and exits. */
|
||||
static kj::Promise<Result<StorePath>> getDerivationEnvironment(ref<Store> store, ref<Store> evalStore, const StorePath & drvPath)
|
||||
try {
|
||||
auto drv = evalStore->derivationFromPath(drvPath);
|
||||
auto drv = TRY_AWAIT(evalStore->derivationFromPath(drvPath));
|
||||
|
||||
auto builder = baseNameOf(drv.builder);
|
||||
if (builder != "bash")
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "lix/libstore/globals.hh"
|
||||
#include "lix/libstore/store-api.hh"
|
||||
#include "lix/libstore/crypto.hh"
|
||||
#include "lix/libutil/async.hh"
|
||||
|
||||
#include <sodium.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
@@ -39,6 +40,12 @@ static ref<Store> store()
|
||||
return ref<Store>(_store);
|
||||
}
|
||||
|
||||
static AsyncIoRoot & aio()
|
||||
{
|
||||
static thread_local AsyncIoRoot root;
|
||||
return root;
|
||||
}
|
||||
|
||||
|
||||
MODULE = Nix::Store PACKAGE = Nix::Store
|
||||
PROTOTYPES: ENABLE
|
||||
@@ -313,7 +320,7 @@ SV * derivationFromPath(char * drvPath)
|
||||
HV *hash;
|
||||
CODE:
|
||||
try {
|
||||
Derivation drv = store()->derivationFromPath(store()->parseStorePath(drvPath));
|
||||
Derivation drv = aio().blockOn(store()->derivationFromPath(store()->parseStorePath(drvPath)));
|
||||
hash = newHV();
|
||||
|
||||
HV * outputs = newHV();
|
||||
|
||||
Reference in New Issue
Block a user