libstore: remove unused Derivation::tryResolve

Change-Id: Ia36b066badf60b3727ec6c6a04057c3c97461e2c
This commit is contained in:
eldritch horrors
2025-05-20 17:43:46 +00:00
parent 01dcbf3359
commit 484319fd2d
2 changed files with 0 additions and 125 deletions
-104
View File
@@ -732,110 +732,6 @@ std::string hashPlaceholder(const OutputNameView outputName)
static kj::Promise<Result<void>>
rewriteDerivation(Store & store, BasicDerivation & drv, const StringMap & rewrites)
try {
debug("Rewriting the derivation");
for (auto & rewrite : rewrites) {
debug("rewriting %s as %s", rewrite.first, rewrite.second);
}
drv.builder = rewriteStrings(drv.builder, rewrites);
for (auto & arg : drv.args) {
arg = rewriteStrings(arg, rewrites);
}
StringPairs newEnv;
for (auto & envVar : drv.env) {
auto envName = rewriteStrings(envVar.first, rewrites);
auto envValue = rewriteStrings(envVar.second, rewrites);
newEnv.emplace(envName, envValue);
}
drv.env = newEnv;
TRY_AWAIT(hashDerivationModulo(store, Derivation(drv), true));
co_return result::success();
} catch (...) {
co_return result::current_exception();
}
kj::Promise<Result<std::optional<BasicDerivation>>>
Derivation::tryResolve(Store & store, Store * evalStore) const
try {
std::map<std::pair<StorePath, std::string>, StorePath> inputDrvOutputs;
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
auto accum = [&](auto & inputDrv, auto & node) -> kj::Promise<Result<void>> {
try {
for (auto & [outputName, outputPath] :
TRY_AWAIT(store.queryPartialDerivationOutputMap(inputDrv, evalStore)))
{
if (outputPath) {
inputDrvOutputs.insert_or_assign({inputDrv, outputName}, *outputPath);
}
}
co_return result::success();
} catch (...) {
co_return result::current_exception();
}
};
for (auto & [inputDrv, node] : inputDrvs)
TRY_AWAIT(accum(inputDrv, node));
co_return TRY_AWAIT(tryResolve(store, inputDrvOutputs));
} catch (...) {
co_return result::current_exception();
}
static bool tryResolveInput(
Store & store, StorePathSet & inputSrcs, StringMap & inputRewrites,
const StorePath & inputDrv, const StringSet & inputNode,
const std::map<std::pair<StorePath, std::string>, StorePath> & inputDrvOutputs)
{
auto getOutput = [&](const std::string & outputName) {
auto * actualPathOpt = get(inputDrvOutputs, { inputDrv, outputName });
if (!actualPathOpt)
warn("output %s of input %s missing, aborting the resolving",
outputName,
store.printStorePath(inputDrv)
);
return actualPathOpt;
};
for (auto & outputName : inputNode) {
auto actualPathOpt = getOutput(outputName);
if (!actualPathOpt) return false;
auto actualPath = *actualPathOpt;
inputSrcs.insert(std::move(actualPath));
}
return true;
}
kj::Promise<Result<std::optional<BasicDerivation>>> Derivation::tryResolve(
Store & store,
const std::map<std::pair<StorePath, std::string>, StorePath> & inputDrvOutputs) const
try {
BasicDerivation resolved { *this };
// Input paths that we'll want to rewrite in the derivation
StringMap inputRewrites;
for (auto & [inputDrv, inputNode] : inputDrvs)
if (!tryResolveInput(store, resolved.inputSrcs, inputRewrites,
inputDrv, inputNode, inputDrvOutputs))
co_return std::nullopt;
TRY_AWAIT(rewriteDerivation(store, resolved, inputRewrites));
co_return resolved;
} catch (...) {
co_return result::current_exception();
}
kj::Promise<Result<void>>
Derivation::checkInvariants(Store & store, const StorePath & drvPath) const
try {
-21
View File
@@ -234,27 +234,6 @@ struct Derivation : BasicDerivation
std::string unparse(const Store & store, bool maskOutputs,
std::map<std::string, StringSet> * actualInputs = nullptr) const;
/**
* Return the underlying basic derivation but with these changes:
*
* 1. Input drvs are emptied, but the outputs of them that were used
* are added directly to input sources.
*
* 2. Input placeholders are replaced with realized input store
* paths.
*/
kj::Promise<Result<std::optional<BasicDerivation>>>
tryResolve(Store & store, Store * evalStore = nullptr) const;
/**
* Like the above, but instead of querying the Nix database for
* realisations, uses a given mapping from input derivation paths +
* output names to actual output store paths.
*/
kj::Promise<Result<std::optional<BasicDerivation>>> tryResolve(
Store & store,
const std::map<std::pair<StorePath, std::string>, StorePath> & inputDrvOutputs) const;
/**
* Check that the derivation is valid and does not present any
* illegal states.