mirror of
https://github.com/NixOS/nix.git
synced 2025-11-13 14:02:42 +01:00
This method does *not* create a new type of goal. We instead just make
`DerivationGoal` more sophisticated, which is much easier to do now that
`DerivationBuildingGoal` has been split from it (and so many fields are
gone, or or local variables instead).
This avoids the need for a secondarily trampoline goal that interacted
poorly with `addWantedOutputs`. That, I hope, will mean the bugs from
before do not reappear.
There may in fact be a reason to introduce such a trampoline in the
future, but it would only happen in conjunction with getting rid of
`addWantedOutputs`.
Restores the functionality (and tests) that was reverted in
f4f28cdd0e.
75 lines
2.3 KiB
C++
75 lines
2.3 KiB
C++
#include "nix/store/derived-path-map.hh"
|
|
#include "nix/util/util.hh"
|
|
|
|
namespace nix {
|
|
|
|
template<typename V>
|
|
typename DerivedPathMap<V>::ChildNode & DerivedPathMap<V>::ensureSlot(const SingleDerivedPath & k)
|
|
{
|
|
std::function<ChildNode &(const SingleDerivedPath & )> initIter;
|
|
initIter = [&](const auto & k) -> auto & {
|
|
return std::visit(overloaded {
|
|
[&](const SingleDerivedPath::Opaque & bo) -> auto & {
|
|
// will not overwrite if already there
|
|
return map[bo.path];
|
|
},
|
|
[&](const SingleDerivedPath::Built & bfd) -> auto & {
|
|
auto & n = initIter(*bfd.drvPath);
|
|
return n.childMap[bfd.output];
|
|
},
|
|
}, k.raw());
|
|
};
|
|
return initIter(k);
|
|
}
|
|
|
|
template<typename V>
|
|
typename DerivedPathMap<V>::ChildNode * DerivedPathMap<V>::findSlot(const SingleDerivedPath & k)
|
|
{
|
|
std::function<ChildNode *(const SingleDerivedPath & )> initIter;
|
|
initIter = [&](const auto & k) {
|
|
return std::visit(overloaded {
|
|
[&](const SingleDerivedPath::Opaque & bo) {
|
|
auto it = map.find(bo.path);
|
|
return it != map.end()
|
|
? &it->second
|
|
: nullptr;
|
|
},
|
|
[&](const SingleDerivedPath::Built & bfd) {
|
|
auto * n = initIter(*bfd.drvPath);
|
|
if (!n) return (ChildNode *)nullptr;
|
|
|
|
auto it = n->childMap.find(bfd.output);
|
|
return it != n->childMap.end()
|
|
? &it->second
|
|
: nullptr;
|
|
},
|
|
}, k.raw());
|
|
};
|
|
return initIter(k);
|
|
}
|
|
|
|
}
|
|
|
|
// instantiations
|
|
|
|
#include "nix/store/build/derivation-goal.hh"
|
|
namespace nix {
|
|
|
|
template<>
|
|
bool DerivedPathMap<StringSet>::ChildNode::operator == (
|
|
const DerivedPathMap<StringSet>::ChildNode &) const noexcept = default;
|
|
|
|
// TODO libc++ 16 (used by darwin) missing `std::map::operator <=>`, can't do yet.
|
|
#if 0
|
|
template<>
|
|
std::strong_ordering DerivedPathMap<StringSet>::ChildNode::operator <=> (
|
|
const DerivedPathMap<StringSet>::ChildNode &) const noexcept = default;
|
|
#endif
|
|
|
|
template struct DerivedPathMap<StringSet>::ChildNode;
|
|
template struct DerivedPathMap<StringSet>;
|
|
|
|
template struct DerivedPathMap<std::weak_ptr<DerivationGoal>>;
|
|
|
|
|
|
};
|