this finally gives us a witness type we can use to prove that a certain call graph subtree can't be used in kj promises using only a single new assumption: if EvalState& is never held as a reference member of a type and instead only ever passes as an argument or held on the stack we can be certain that anything that has access to en EvalState ref must never be run inside a promise and, crucially, that anything that doesn't have access to an EvalState& *can* be run inside a promise without problems. Change-Id: I6c15ada479175ad7e6cd3e4a729a5586b3ba30d6
109 lines
3.3 KiB
C++
109 lines
3.3 KiB
C++
#include "lix/libcmd/installable-attr-path.hh"
|
|
#include "lix/libstore/outputs-spec.hh"
|
|
#include "lix/libcmd/command.hh"
|
|
#include "lix/libexpr/attr-path.hh"
|
|
#include "lix/libcmd/common-eval-args.hh"
|
|
#include "lix/libexpr/eval.hh"
|
|
#include "lix/libexpr/get-drvs.hh"
|
|
#include "lix/libexpr/flake/flake.hh"
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
namespace nix {
|
|
|
|
InstallableAttrPath::InstallableAttrPath(
|
|
ref<eval_cache::CachingEvaluator> state,
|
|
SourceExprCommand & cmd,
|
|
Value * v,
|
|
const std::string & attrPath,
|
|
ExtendedOutputsSpec extendedOutputsSpec)
|
|
: InstallableValue(state)
|
|
, cmd(cmd)
|
|
, v(allocRootValue(v))
|
|
, attrPath(attrPath)
|
|
, extendedOutputsSpec(std::move(extendedOutputsSpec))
|
|
{ }
|
|
|
|
std::pair<Value *, PosIdx> InstallableAttrPath::toValue(EvalState & state)
|
|
{
|
|
auto [vRes, pos] = findAlongAttrPath(state, attrPath, *cmd.getAutoArgs(*evaluator), **v);
|
|
state.forceValue(*vRes, pos);
|
|
return {vRes, pos};
|
|
}
|
|
|
|
DerivedPathsWithInfo InstallableAttrPath::toDerivedPaths(EvalState & state)
|
|
{
|
|
auto [v, pos] = toValue(state);
|
|
|
|
if (std::optional derivedPathWithInfo = trySinglePathToDerivedPaths(
|
|
state, *v, pos, fmt("while evaluating the attribute '%s'", attrPath)
|
|
))
|
|
{
|
|
return { *derivedPathWithInfo };
|
|
}
|
|
|
|
Bindings & autoArgs = *cmd.getAutoArgs(*evaluator);
|
|
|
|
DrvInfos drvInfos;
|
|
getDerivations(state, *v, "", autoArgs, drvInfos, false);
|
|
|
|
// Backward compatibility hack: group results by drvPath. This
|
|
// helps keep .all output together.
|
|
std::map<StorePath, OutputsSpec> byDrvPath;
|
|
|
|
for (auto & drvInfo : drvInfos) {
|
|
auto drvPath = drvInfo.queryDrvPath(state);
|
|
if (!drvPath)
|
|
throw Error("'%s' is not a derivation", what());
|
|
|
|
auto newOutputs = std::visit(overloaded {
|
|
[&](const ExtendedOutputsSpec::Default & d) -> OutputsSpec {
|
|
std::set<std::string> outputsToInstall;
|
|
for (auto & output : drvInfo.queryOutputs(state, false, true))
|
|
outputsToInstall.insert(output.first);
|
|
return OutputsSpec::Names { std::move(outputsToInstall) };
|
|
},
|
|
[&](const ExtendedOutputsSpec::Explicit & e) -> OutputsSpec {
|
|
return e;
|
|
},
|
|
}, extendedOutputsSpec.raw);
|
|
|
|
auto [iter, didInsert] = byDrvPath.emplace(*drvPath, newOutputs);
|
|
|
|
if (!didInsert)
|
|
iter->second = iter->second.union_(newOutputs);
|
|
}
|
|
|
|
DerivedPathsWithInfo res;
|
|
for (auto & [drvPath, outputs] : byDrvPath)
|
|
res.push_back({
|
|
.path = DerivedPath::Built {
|
|
.drvPath = makeConstantStorePathRef(drvPath),
|
|
.outputs = outputs,
|
|
},
|
|
.info = make_ref<ExtraPathInfoValue>(ExtraPathInfoValue::Value {
|
|
.extendedOutputsSpec = outputs,
|
|
/* FIXME: reconsider backwards compatibility above
|
|
so we can fill in this info. */
|
|
}),
|
|
});
|
|
|
|
return res;
|
|
}
|
|
|
|
InstallableAttrPath InstallableAttrPath::parse(
|
|
ref<eval_cache::CachingEvaluator> state,
|
|
SourceExprCommand & cmd,
|
|
Value * v,
|
|
std::string_view prefix,
|
|
ExtendedOutputsSpec extendedOutputsSpec)
|
|
{
|
|
return {
|
|
state, cmd, v,
|
|
prefix == "." ? "" : std::string { prefix },
|
|
std::move(extendedOutputsSpec),
|
|
};
|
|
}
|
|
|
|
}
|