forked from lix-project/lix
Merge pull request #3583 from mkenigs/InstallablesRefactor
Installables refactor
This commit is contained in:
commit
fbade0b7cc
3 changed files with 42 additions and 63 deletions
|
@ -179,33 +179,8 @@ struct InstallableStorePath : Installable
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<InstallableValue::DerivationInfo> InstallableValue::toDerivations()
|
|
||||||
{
|
|
||||||
auto state = cmd.getEvalState();
|
|
||||||
|
|
||||||
auto v = toValue(*state).first;
|
|
||||||
|
|
||||||
Bindings & autoArgs = *cmd.getAutoArgs(*state);
|
|
||||||
|
|
||||||
DrvInfos drvInfos;
|
|
||||||
getDerivations(*state, *v, "", autoArgs, drvInfos, false);
|
|
||||||
|
|
||||||
std::vector<DerivationInfo> res;
|
|
||||||
for (auto & drvInfo : drvInfos) {
|
|
||||||
res.push_back({
|
|
||||||
state->store->parseStorePath(drvInfo.queryDrvPath()),
|
|
||||||
state->store->parseStorePath(drvInfo.queryOutPath()),
|
|
||||||
drvInfo.queryOutputName()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
Buildables InstallableValue::toBuildables()
|
Buildables InstallableValue::toBuildables()
|
||||||
{
|
{
|
||||||
auto state = cmd.getEvalState();
|
|
||||||
|
|
||||||
Buildables res;
|
Buildables res;
|
||||||
|
|
||||||
StorePathSet drvPaths;
|
StorePathSet drvPaths;
|
||||||
|
@ -237,30 +212,14 @@ Buildables InstallableValue::toBuildables()
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct InstallableExpr : InstallableValue
|
|
||||||
{
|
|
||||||
std::string text;
|
|
||||||
|
|
||||||
InstallableExpr(SourceExprCommand & cmd, const std::string & text)
|
|
||||||
: InstallableValue(cmd), text(text) { }
|
|
||||||
|
|
||||||
std::string what() override { return text; }
|
|
||||||
|
|
||||||
std::pair<Value *, Pos> toValue(EvalState & state) override
|
|
||||||
{
|
|
||||||
auto v = state.allocValue();
|
|
||||||
state.eval(state.parseExprFromString(text, absPath(".")), *v);
|
|
||||||
return {v, noPos};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct InstallableAttrPath : InstallableValue
|
struct InstallableAttrPath : InstallableValue
|
||||||
{
|
{
|
||||||
|
SourceExprCommand & cmd;
|
||||||
RootValue v;
|
RootValue v;
|
||||||
std::string attrPath;
|
std::string attrPath;
|
||||||
|
|
||||||
InstallableAttrPath(SourceExprCommand & cmd, Value * v, const std::string & attrPath)
|
InstallableAttrPath(ref<EvalState> state, SourceExprCommand & cmd, Value * v, const std::string & attrPath)
|
||||||
: InstallableValue(cmd), v(allocRootValue(v)), attrPath(attrPath)
|
: InstallableValue(state), cmd(cmd), v(allocRootValue(v)), attrPath(attrPath)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
std::string what() override { return attrPath; }
|
std::string what() override { return attrPath; }
|
||||||
|
@ -271,8 +230,31 @@ struct InstallableAttrPath : InstallableValue
|
||||||
state.forceValue(*vRes);
|
state.forceValue(*vRes);
|
||||||
return {vRes, pos};
|
return {vRes, pos};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual std::vector<InstallableValue::DerivationInfo> toDerivations() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::vector<InstallableValue::DerivationInfo> InstallableAttrPath::toDerivations()
|
||||||
|
{
|
||||||
|
auto v = toValue(*state).first;
|
||||||
|
|
||||||
|
Bindings & autoArgs = *cmd.getAutoArgs(*state);
|
||||||
|
|
||||||
|
DrvInfos drvInfos;
|
||||||
|
getDerivations(*state, *v, "", autoArgs, drvInfos, false);
|
||||||
|
|
||||||
|
std::vector<DerivationInfo> res;
|
||||||
|
for (auto & drvInfo : drvInfos) {
|
||||||
|
res.push_back({
|
||||||
|
state->store->parseStorePath(drvInfo.queryDrvPath()),
|
||||||
|
state->store->parseStorePath(drvInfo.queryOutPath()),
|
||||||
|
drvInfo.queryOutputName()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> InstallableFlake::getActualAttrPaths()
|
std::vector<std::string> InstallableFlake::getActualAttrPaths()
|
||||||
{
|
{
|
||||||
std::vector<std::string> res;
|
std::vector<std::string> res;
|
||||||
|
@ -330,10 +312,9 @@ ref<eval_cache::EvalCache> openEvalCache(
|
||||||
|
|
||||||
std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableFlake::toDerivation()
|
std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableFlake::toDerivation()
|
||||||
{
|
{
|
||||||
auto state = cmd.getEvalState();
|
|
||||||
|
|
||||||
auto lockedFlake = std::make_shared<flake::LockedFlake>(
|
auto lockedFlake = std::make_shared<flake::LockedFlake>(
|
||||||
lockFlake(*state, flakeRef, cmd.lockFlags));
|
lockFlake(*state, flakeRef, lockFlags));
|
||||||
|
|
||||||
auto cache = openEvalCache(*state, lockedFlake, true);
|
auto cache = openEvalCache(*state, lockedFlake, true);
|
||||||
auto root = cache->getRoot();
|
auto root = cache->getRoot();
|
||||||
|
@ -379,7 +360,7 @@ std::vector<InstallableValue::DerivationInfo> InstallableFlake::toDerivations()
|
||||||
|
|
||||||
std::pair<Value *, Pos> InstallableFlake::toValue(EvalState & state)
|
std::pair<Value *, Pos> InstallableFlake::toValue(EvalState & state)
|
||||||
{
|
{
|
||||||
auto lockedFlake = lockFlake(state, flakeRef, cmd.lockFlags);
|
auto lockedFlake = lockFlake(state, flakeRef, lockFlags);
|
||||||
|
|
||||||
auto vOutputs = getFlakeOutputs(state, lockedFlake);
|
auto vOutputs = getFlakeOutputs(state, lockedFlake);
|
||||||
|
|
||||||
|
@ -402,7 +383,7 @@ std::vector<std::pair<std::shared_ptr<eval_cache::AttrCursor>, std::string>>
|
||||||
InstallableFlake::getCursor(EvalState & state, bool useEvalCache)
|
InstallableFlake::getCursor(EvalState & state, bool useEvalCache)
|
||||||
{
|
{
|
||||||
auto evalCache = openEvalCache(state,
|
auto evalCache = openEvalCache(state,
|
||||||
std::make_shared<flake::LockedFlake>(lockFlake(state, flakeRef, cmd.lockFlags)),
|
std::make_shared<flake::LockedFlake>(lockFlake(state, flakeRef, lockFlags)),
|
||||||
useEvalCache);
|
useEvalCache);
|
||||||
|
|
||||||
auto root = evalCache->getRoot();
|
auto root = evalCache->getRoot();
|
||||||
|
@ -440,7 +421,7 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto & s : ss)
|
for (auto & s : ss)
|
||||||
result.push_back(std::make_shared<InstallableAttrPath>(*this, vFile, s == "." ? "" : s));
|
result.push_back(std::make_shared<InstallableAttrPath>(state, *this, vFile, s == "." ? "" : s));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -450,9 +431,9 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
|
||||||
try {
|
try {
|
||||||
auto [flakeRef, fragment] = parseFlakeRefWithFragment(s, absPath("."));
|
auto [flakeRef, fragment] = parseFlakeRefWithFragment(s, absPath("."));
|
||||||
result.push_back(std::make_shared<InstallableFlake>(
|
result.push_back(std::make_shared<InstallableFlake>(
|
||||||
*this, std::move(flakeRef),
|
getEvalState(), std::move(flakeRef),
|
||||||
fragment == "" ? getDefaultFlakeAttrPaths() : Strings{fragment},
|
fragment == "" ? getDefaultFlakeAttrPaths() : Strings{fragment},
|
||||||
getDefaultFlakeAttrPathPrefixes()));
|
getDefaultFlakeAttrPathPrefixes(), lockFlags));
|
||||||
continue;
|
continue;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ex = std::current_exception();
|
ex = std::current_exception();
|
||||||
|
|
|
@ -37,10 +37,7 @@ struct Installable
|
||||||
|
|
||||||
virtual std::string what() = 0;
|
virtual std::string what() = 0;
|
||||||
|
|
||||||
virtual Buildables toBuildables()
|
virtual Buildables toBuildables() = 0;
|
||||||
{
|
|
||||||
throw Error("argument '%s' cannot be built", what());
|
|
||||||
}
|
|
||||||
|
|
||||||
Buildable toBuildable();
|
Buildable toBuildable();
|
||||||
|
|
||||||
|
@ -64,9 +61,9 @@ struct Installable
|
||||||
|
|
||||||
struct InstallableValue : Installable
|
struct InstallableValue : Installable
|
||||||
{
|
{
|
||||||
SourceExprCommand & cmd;
|
ref<EvalState> state;
|
||||||
|
|
||||||
InstallableValue(SourceExprCommand & cmd) : cmd(cmd) { }
|
InstallableValue(ref<EvalState> state) : state(state) {}
|
||||||
|
|
||||||
struct DerivationInfo
|
struct DerivationInfo
|
||||||
{
|
{
|
||||||
|
@ -75,7 +72,7 @@ struct InstallableValue : Installable
|
||||||
std::string outputName;
|
std::string outputName;
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual std::vector<DerivationInfo> toDerivations();
|
virtual std::vector<DerivationInfo> toDerivations() = 0;
|
||||||
|
|
||||||
Buildables toBuildables() override;
|
Buildables toBuildables() override;
|
||||||
};
|
};
|
||||||
|
@ -85,11 +82,12 @@ struct InstallableFlake : InstallableValue
|
||||||
FlakeRef flakeRef;
|
FlakeRef flakeRef;
|
||||||
Strings attrPaths;
|
Strings attrPaths;
|
||||||
Strings prefixes;
|
Strings prefixes;
|
||||||
|
const flake::LockFlags & lockFlags;
|
||||||
|
|
||||||
InstallableFlake(SourceExprCommand & cmd, FlakeRef && flakeRef,
|
InstallableFlake(ref<EvalState> state, FlakeRef && flakeRef,
|
||||||
Strings && attrPaths, Strings && prefixes)
|
Strings && attrPaths, Strings && prefixes, const flake::LockFlags & lockFlags)
|
||||||
: InstallableValue(cmd), flakeRef(flakeRef), attrPaths(attrPaths),
|
: InstallableValue(state), flakeRef(flakeRef), attrPaths(attrPaths),
|
||||||
prefixes(prefixes)
|
prefixes(prefixes), lockFlags(lockFlags)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
std::string what() override { return flakeRef.to_string() + "#" + *attrPaths.begin(); }
|
std::string what() override { return flakeRef.to_string() + "#" + *attrPaths.begin(); }
|
||||||
|
|
|
@ -336,7 +336,7 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf
|
||||||
Activity act(*logger, lvlChatty, actUnknown,
|
Activity act(*logger, lvlChatty, actUnknown,
|
||||||
fmt("checking '%s' for updates", element.source->attrPath));
|
fmt("checking '%s' for updates", element.source->attrPath));
|
||||||
|
|
||||||
InstallableFlake installable(*this, FlakeRef(element.source->originalRef), {element.source->attrPath}, {});
|
InstallableFlake installable(getEvalState(), FlakeRef(element.source->originalRef), {element.source->attrPath}, {}, lockFlags);
|
||||||
|
|
||||||
auto [attrPath, resolvedRef, drv] = installable.toDerivation();
|
auto [attrPath, resolvedRef, drv] = installable.toDerivation();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue