mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 03:56:01 +01:00
Implement realisation operations on dummy store
This commit is contained in:
parent
6995d325ef
commit
266fbebe66
5 changed files with 62 additions and 5 deletions
|
|
@ -1,6 +1,6 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
#include "nix/store/dummy-store.hh"
|
||||
#include "nix/store/dummy-store-impl.hh"
|
||||
#include "nix/store/globals.hh"
|
||||
#include "nix/store/realisation.hh"
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ TEST(DummyStore, realisation_read)
|
|||
auto store = [] {
|
||||
auto cfg = make_ref<DummyStoreConfig>(StoreReference::Params{});
|
||||
cfg->readOnly = false;
|
||||
return cfg->openStore();
|
||||
return cfg->openDummyStore();
|
||||
}();
|
||||
|
||||
auto drvHash = Hash::parseExplicitFormatUnprefixed(
|
||||
|
|
@ -22,6 +22,17 @@ TEST(DummyStore, realisation_read)
|
|||
auto outputName = "foo";
|
||||
|
||||
EXPECT_EQ(store->queryRealisation({drvHash, outputName}), nullptr);
|
||||
|
||||
UnkeyedRealisation value{
|
||||
.outPath = StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv"},
|
||||
};
|
||||
|
||||
store->buildTrace.insert({drvHash, {{outputName, make_ref<UnkeyedRealisation>(value)}}});
|
||||
|
||||
auto value2 = store->queryRealisation({drvHash, outputName});
|
||||
|
||||
ASSERT_TRUE(value2);
|
||||
EXPECT_EQ(*value2, value);
|
||||
}
|
||||
|
||||
} // namespace nix
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "nix/util/callback.hh"
|
||||
#include "nix/util/memory-source-accessor.hh"
|
||||
#include "nix/store/dummy-store-impl.hh"
|
||||
#include "nix/store/realisation.hh"
|
||||
|
||||
#include <boost/unordered/concurrent_flat_map.hpp>
|
||||
|
||||
|
|
@ -251,7 +252,10 @@ struct DummyStoreImpl : DummyStore
|
|||
|
||||
void registerDrvOutput(const Realisation & output) override
|
||||
{
|
||||
unsupported("registerDrvOutput");
|
||||
auto ref = make_ref<UnkeyedRealisation>(output);
|
||||
buildTrace.insert_or_visit({output.id.drvHash, {{output.id.outputName, ref}}}, [&](auto & kv) {
|
||||
kv.second.insert_or_assign(output.id.outputName, make_ref<UnkeyedRealisation>(output));
|
||||
});
|
||||
}
|
||||
|
||||
void narFromPath(const StorePath & path, Sink & sink) override
|
||||
|
|
@ -267,9 +271,18 @@ struct DummyStoreImpl : DummyStore
|
|||
}
|
||||
|
||||
void queryRealisationUncached(
|
||||
const DrvOutput &, Callback<std::shared_ptr<const UnkeyedRealisation>> callback) noexcept override
|
||||
const DrvOutput & drvOutput, Callback<std::shared_ptr<const UnkeyedRealisation>> callback) noexcept override
|
||||
{
|
||||
callback(nullptr);
|
||||
bool visited = false;
|
||||
buildTrace.cvisit(drvOutput.drvHash, [&](const auto & kv) {
|
||||
if (auto it = kv.second.find(drvOutput.outputName); it != kv.second.end()) {
|
||||
visited = true;
|
||||
callback(it->second.get_ptr());
|
||||
}
|
||||
});
|
||||
|
||||
if (!visited)
|
||||
callback(nullptr);
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceAccessor> getFSAccessor(const StorePath & path, bool requireValidPath) override
|
||||
|
|
|
|||
|
|
@ -30,6 +30,18 @@ struct DummyStore : virtual Store
|
|||
*/
|
||||
boost::concurrent_flat_map<StorePath, PathInfoAndContents> contents;
|
||||
|
||||
/**
|
||||
* The build trace maps the pair of a content-addressing (fixed or
|
||||
* floating) derivations an one of its output to a
|
||||
* (content-addressed) store object.
|
||||
*
|
||||
* It is [curried](https://en.wikipedia.org/wiki/Currying), so we
|
||||
* instead having a single output with a `DrvOutput` key, we have an
|
||||
* outer map for the derivation, and inner maps for the outputs of a
|
||||
* given derivation.
|
||||
*/
|
||||
boost::concurrent_flat_map<Hash, std::map<std::string, ref<UnkeyedRealisation>>> buildTrace;
|
||||
|
||||
DummyStore(ref<const Config> config)
|
||||
: Store{*config}
|
||||
, config(config)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "nix/store/store-api.hh"
|
||||
|
||||
#include <boost/unordered/concurrent_flat_map.hpp>
|
||||
|
||||
namespace nix {
|
||||
|
||||
struct DummyStore;
|
||||
|
|
|
|||
|
|
@ -222,3 +222,22 @@ public:
|
|||
};
|
||||
|
||||
} // namespace nix
|
||||
|
||||
template<>
|
||||
struct std::hash<nix::Hash>
|
||||
{
|
||||
std::size_t operator()(const nix::Hash & hash) const noexcept
|
||||
{
|
||||
assert(hash.hashSize > sizeof(size_t));
|
||||
return *reinterpret_cast<const std::size_t *>(&hash.hash);
|
||||
}
|
||||
};
|
||||
|
||||
namespace nix {
|
||||
|
||||
inline std::size_t hash_value(const Hash & hash)
|
||||
{
|
||||
return std::hash<Hash>{}(hash);
|
||||
}
|
||||
|
||||
} // namespace nix
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue