mirror of
https://github.com/NixOS/nix
synced 2025-06-30 19:57:59 +02:00
Merge pull request #3859 from obsidiansystems/drv-outputs-map-allow-missing
`queryDerivationOutputMap` no longer assumes all outputs have a mapping
This commit is contained in:
commit
4d77513d97
9 changed files with 142 additions and 37 deletions
|
@ -70,10 +70,84 @@ template<class T> T readStorePaths(const Store & store, Source & from);
|
|||
|
||||
void writeStorePaths(const Store & store, Sink & out, const StorePathSet & paths);
|
||||
|
||||
/* To guide overloading */
|
||||
template<typename T>
|
||||
struct Phantom {};
|
||||
|
||||
|
||||
namespace worker_proto {
|
||||
/* FIXME maybe move more stuff inside here */
|
||||
|
||||
StorePath read(const Store & store, Source & from, Phantom<StorePath> _);
|
||||
void write(const Store & store, Sink & out, const StorePath & storePath);
|
||||
|
||||
template<typename T>
|
||||
std::map<std::string, T> read(const Store & store, Source & from, Phantom<std::map<std::string, T>> _);
|
||||
template<typename T>
|
||||
void write(const Store & store, Sink & out, const std::map<string, T> & resMap);
|
||||
template<typename T>
|
||||
std::optional<T> read(const Store & store, Source & from, Phantom<std::optional<T>> _);
|
||||
template<typename T>
|
||||
void write(const Store & store, Sink & out, const std::optional<T> & optVal);
|
||||
|
||||
/* Specialization which uses and empty string for the empty case, taking
|
||||
advantage of the fact StorePaths always serialize to a non-empty string.
|
||||
This is done primarily for backwards compatability, so that StorePath <=
|
||||
std::optional<StorePath>, where <= is the compatability partial order.
|
||||
*/
|
||||
template<>
|
||||
void write(const Store & store, Sink & out, const std::optional<StorePath> & optVal);
|
||||
|
||||
template<typename T>
|
||||
std::map<std::string, T> read(const Store & store, Source & from, Phantom<std::map<std::string, T>> _)
|
||||
{
|
||||
std::map<string, T> resMap;
|
||||
auto size = (size_t)readInt(from);
|
||||
while (size--) {
|
||||
auto thisKey = readString(from);
|
||||
resMap.insert_or_assign(std::move(thisKey), nix::worker_proto::read(store, from, Phantom<T> {}));
|
||||
}
|
||||
return resMap;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void write(const Store & store, Sink & out, const std::map<string, T> & resMap)
|
||||
{
|
||||
out << resMap.size();
|
||||
for (auto & i : resMap) {
|
||||
out << i.first;
|
||||
nix::worker_proto::write(store, out, i.second);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::optional<T> read(const Store & store, Source & from, Phantom<std::optional<T>> _)
|
||||
{
|
||||
auto tag = readNum<uint8_t>(from);
|
||||
switch (tag) {
|
||||
case 0:
|
||||
return std::nullopt;
|
||||
case 1:
|
||||
return nix::worker_proto::read(store, from, Phantom<T> {});
|
||||
default:
|
||||
throw Error("got an invalid tag bit for std::optional: %#04x", tag);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void write(const Store & store, Sink & out, const std::optional<T> & optVal)
|
||||
{
|
||||
out << (optVal ? 1 : 0);
|
||||
if (optVal)
|
||||
nix::worker_proto::write(store, out, *optVal);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
StorePathCAMap readStorePathCAMap(const Store & store, Source & from);
|
||||
|
||||
void writeStorePathCAMap(const Store & store, Sink & out, const StorePathCAMap & paths);
|
||||
|
||||
void writeOutputPathMap(const Store & store, Sink & out, const OutputPathMap & paths);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue