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 <gtest/gtest.h>
|
||||||
|
|
||||||
#include "nix/store/dummy-store.hh"
|
#include "nix/store/dummy-store-impl.hh"
|
||||||
#include "nix/store/globals.hh"
|
#include "nix/store/globals.hh"
|
||||||
#include "nix/store/realisation.hh"
|
#include "nix/store/realisation.hh"
|
||||||
|
|
||||||
|
|
@ -13,7 +13,7 @@ TEST(DummyStore, realisation_read)
|
||||||
auto store = [] {
|
auto store = [] {
|
||||||
auto cfg = make_ref<DummyStoreConfig>(StoreReference::Params{});
|
auto cfg = make_ref<DummyStoreConfig>(StoreReference::Params{});
|
||||||
cfg->readOnly = false;
|
cfg->readOnly = false;
|
||||||
return cfg->openStore();
|
return cfg->openDummyStore();
|
||||||
}();
|
}();
|
||||||
|
|
||||||
auto drvHash = Hash::parseExplicitFormatUnprefixed(
|
auto drvHash = Hash::parseExplicitFormatUnprefixed(
|
||||||
|
|
@ -22,6 +22,17 @@ TEST(DummyStore, realisation_read)
|
||||||
auto outputName = "foo";
|
auto outputName = "foo";
|
||||||
|
|
||||||
EXPECT_EQ(store->queryRealisation({drvHash, outputName}), nullptr);
|
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
|
} // namespace nix
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include "nix/util/callback.hh"
|
#include "nix/util/callback.hh"
|
||||||
#include "nix/util/memory-source-accessor.hh"
|
#include "nix/util/memory-source-accessor.hh"
|
||||||
#include "nix/store/dummy-store-impl.hh"
|
#include "nix/store/dummy-store-impl.hh"
|
||||||
|
#include "nix/store/realisation.hh"
|
||||||
|
|
||||||
#include <boost/unordered/concurrent_flat_map.hpp>
|
#include <boost/unordered/concurrent_flat_map.hpp>
|
||||||
|
|
||||||
|
|
@ -251,7 +252,10 @@ struct DummyStoreImpl : DummyStore
|
||||||
|
|
||||||
void registerDrvOutput(const Realisation & output) override
|
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
|
void narFromPath(const StorePath & path, Sink & sink) override
|
||||||
|
|
@ -267,8 +271,17 @@ struct DummyStoreImpl : DummyStore
|
||||||
}
|
}
|
||||||
|
|
||||||
void queryRealisationUncached(
|
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
|
||||||
{
|
{
|
||||||
|
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);
|
callback(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,18 @@ struct DummyStore : virtual Store
|
||||||
*/
|
*/
|
||||||
boost::concurrent_flat_map<StorePath, PathInfoAndContents> contents;
|
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)
|
DummyStore(ref<const Config> config)
|
||||||
: Store{*config}
|
: Store{*config}
|
||||||
, config(config)
|
, config(config)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include "nix/store/store-api.hh"
|
#include "nix/store/store-api.hh"
|
||||||
|
|
||||||
|
#include <boost/unordered/concurrent_flat_map.hpp>
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
struct DummyStore;
|
struct DummyStore;
|
||||||
|
|
|
||||||
|
|
@ -222,3 +222,22 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace nix
|
} // 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