mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 12:06:01 +01:00
libutil: Move references.{hh,cc} to libstore
The implicit dependency on refLength (which is the StorePath::HashLen) is not good. Also the companion tests and benchmarks are already in libstore-tests.
This commit is contained in:
parent
1b4aa5c1ef
commit
2e3ebfb829
15 changed files with 48 additions and 59 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
#include "nix/util/references.hh"
|
#include "nix/store/references.hh"
|
||||||
#include "nix/store/path.hh"
|
#include "nix/store/path.hh"
|
||||||
#include "nix/util/base-nix-32.hh"
|
#include "nix/util/base-nix-32.hh"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,46 @@
|
||||||
#include "nix/util/references.hh"
|
#include "nix/store/references.hh"
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
struct RewriteParams
|
||||||
|
{
|
||||||
|
std::string originalString, finalString;
|
||||||
|
StringMap rewrites;
|
||||||
|
|
||||||
|
friend std::ostream & operator<<(std::ostream & os, const RewriteParams & bar)
|
||||||
|
{
|
||||||
|
StringSet strRewrites;
|
||||||
|
for (auto & [from, to] : bar.rewrites)
|
||||||
|
strRewrites.insert(from + "->" + to);
|
||||||
|
return os << "OriginalString: " << bar.originalString << std::endl
|
||||||
|
<< "Rewrites: " << dropEmptyInitThenConcatStringsSep(",", strRewrites) << std::endl
|
||||||
|
<< "Expected result: " << bar.finalString;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class RewriteTest : public ::testing::TestWithParam<RewriteParams>
|
||||||
|
{};
|
||||||
|
|
||||||
|
TEST_P(RewriteTest, IdentityRewriteIsIdentity)
|
||||||
|
{
|
||||||
|
RewriteParams param = GetParam();
|
||||||
|
StringSink rewritten;
|
||||||
|
auto rewriter = RewritingSink(param.rewrites, rewritten);
|
||||||
|
rewriter(param.originalString);
|
||||||
|
rewriter.flush();
|
||||||
|
ASSERT_EQ(rewritten.s, param.finalString);
|
||||||
|
}
|
||||||
|
|
||||||
|
INSTANTIATE_TEST_CASE_P(
|
||||||
|
references,
|
||||||
|
RewriteTest,
|
||||||
|
::testing::Values(
|
||||||
|
RewriteParams{"foooo", "baroo", {{"foo", "bar"}, {"bar", "baz"}}},
|
||||||
|
RewriteParams{"foooo", "bazoo", {{"fou", "bar"}, {"foo", "baz"}}},
|
||||||
|
RewriteParams{"foooo", "foooo", {}}));
|
||||||
|
|
||||||
TEST(references, scan)
|
TEST(references, scan)
|
||||||
{
|
{
|
||||||
std::string hash1 = "dc04vv14dak1c1r48qa0m23vr9jy8sm0";
|
std::string hash1 = "dc04vv14dak1c1r48qa0m23vr9jy8sm0";
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@ headers = [ config_pub_h ] + files(
|
||||||
'posix-fs-canonicalise.hh',
|
'posix-fs-canonicalise.hh',
|
||||||
'profiles.hh',
|
'profiles.hh',
|
||||||
'realisation.hh',
|
'realisation.hh',
|
||||||
|
'references.hh',
|
||||||
'remote-fs-accessor.hh',
|
'remote-fs-accessor.hh',
|
||||||
'remote-store-connection.hh',
|
'remote-store-connection.hh',
|
||||||
'remote-store.hh',
|
'remote-store.hh',
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
///@file
|
///@file
|
||||||
|
|
||||||
#include "nix/util/references.hh"
|
#include "nix/store/references.hh"
|
||||||
#include "nix/store/path.hh"
|
#include "nix/store/path.hh"
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
#include "nix/store/derivations.hh"
|
#include "nix/store/derivations.hh"
|
||||||
#include "nix/store/realisation.hh"
|
#include "nix/store/realisation.hh"
|
||||||
#include "nix/store/nar-info.hh"
|
#include "nix/store/nar-info.hh"
|
||||||
#include "nix/util/references.hh"
|
#include "nix/store/references.hh"
|
||||||
#include "nix/util/callback.hh"
|
#include "nix/util/callback.hh"
|
||||||
#include "nix/util/topo-sort.hh"
|
#include "nix/util/topo-sort.hh"
|
||||||
#include "nix/util/finally.hh"
|
#include "nix/util/finally.hh"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include "nix/store/make-content-addressed.hh"
|
#include "nix/store/make-content-addressed.hh"
|
||||||
#include "nix/util/references.hh"
|
#include "nix/store/references.hh"
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -316,6 +316,7 @@ sources = files(
|
||||||
'posix-fs-canonicalise.cc',
|
'posix-fs-canonicalise.cc',
|
||||||
'profiles.cc',
|
'profiles.cc',
|
||||||
'realisation.cc',
|
'realisation.cc',
|
||||||
|
'references.cc',
|
||||||
'remote-fs-accessor.cc',
|
'remote-fs-accessor.cc',
|
||||||
'remote-store.cc',
|
'remote-store.cc',
|
||||||
'restricted-store.cc',
|
'restricted-store.cc',
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include "nix/util/references.hh"
|
#include "nix/store/references.hh"
|
||||||
|
#include "nix/store/path.hh"
|
||||||
#include "nix/util/hash.hh"
|
#include "nix/util/hash.hh"
|
||||||
#include "nix/util/archive.hh"
|
|
||||||
#include "nix/util/base-nix-32.hh"
|
#include "nix/util/base-nix-32.hh"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
static size_t refLength = 32; /* characters */
|
static constexpr auto refLength = StorePath::HashLen;
|
||||||
|
|
||||||
static void search(std::string_view s, StringSet & hashes, StringSet & seen)
|
static void search(std::string_view s, StringSet & hashes, StringSet & seen)
|
||||||
{
|
{
|
||||||
|
|
@ -9,7 +9,6 @@
|
||||||
#include "nix/util/util.hh"
|
#include "nix/util/util.hh"
|
||||||
#include "nix/store/nar-info-disk-cache.hh"
|
#include "nix/store/nar-info-disk-cache.hh"
|
||||||
#include "nix/util/thread-pool.hh"
|
#include "nix/util/thread-pool.hh"
|
||||||
#include "nix/util/references.hh"
|
|
||||||
#include "nix/util/archive.hh"
|
#include "nix/util/archive.hh"
|
||||||
#include "nix/util/callback.hh"
|
#include "nix/util/callback.hh"
|
||||||
#include "nix/util/git.hh"
|
#include "nix/util/git.hh"
|
||||||
|
|
@ -18,7 +17,6 @@
|
||||||
// `addMultipleToStore`.
|
// `addMultipleToStore`.
|
||||||
#include "nix/store/worker-protocol.hh"
|
#include "nix/store/worker-protocol.hh"
|
||||||
#include "nix/util/signals.hh"
|
#include "nix/util/signals.hh"
|
||||||
#include "nix/util/users.hh"
|
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,6 @@ sources = files(
|
||||||
'pool.cc',
|
'pool.cc',
|
||||||
'position.cc',
|
'position.cc',
|
||||||
'processes.cc',
|
'processes.cc',
|
||||||
'references.cc',
|
|
||||||
'sort.cc',
|
'sort.cc',
|
||||||
'spawn.cc',
|
'spawn.cc',
|
||||||
'strings.cc',
|
'strings.cc',
|
||||||
|
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
#include "nix/util/references.hh"
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
namespace nix {
|
|
||||||
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
struct RewriteParams
|
|
||||||
{
|
|
||||||
string originalString, finalString;
|
|
||||||
StringMap rewrites;
|
|
||||||
|
|
||||||
friend std::ostream & operator<<(std::ostream & os, const RewriteParams & bar)
|
|
||||||
{
|
|
||||||
StringSet strRewrites;
|
|
||||||
for (auto & [from, to] : bar.rewrites)
|
|
||||||
strRewrites.insert(from + "->" + to);
|
|
||||||
return os << "OriginalString: " << bar.originalString << std::endl
|
|
||||||
<< "Rewrites: " << dropEmptyInitThenConcatStringsSep(",", strRewrites) << std::endl
|
|
||||||
<< "Expected result: " << bar.finalString;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class RewriteTest : public ::testing::TestWithParam<RewriteParams>
|
|
||||||
{};
|
|
||||||
|
|
||||||
TEST_P(RewriteTest, IdentityRewriteIsIdentity)
|
|
||||||
{
|
|
||||||
RewriteParams param = GetParam();
|
|
||||||
StringSink rewritten;
|
|
||||||
auto rewriter = RewritingSink(param.rewrites, rewritten);
|
|
||||||
rewriter(param.originalString);
|
|
||||||
rewriter.flush();
|
|
||||||
ASSERT_EQ(rewritten.s, param.finalString);
|
|
||||||
}
|
|
||||||
|
|
||||||
INSTANTIATE_TEST_CASE_P(
|
|
||||||
references,
|
|
||||||
RewriteTest,
|
|
||||||
::testing::Values(
|
|
||||||
RewriteParams{"foooo", "baroo", {{"foo", "bar"}, {"bar", "baz"}}},
|
|
||||||
RewriteParams{"foooo", "bazoo", {{"fou", "bar"}, {"foo", "baz"}}},
|
|
||||||
RewriteParams{"foooo", "foooo", {}}));
|
|
||||||
|
|
||||||
} // namespace nix
|
|
||||||
|
|
@ -55,7 +55,6 @@ headers = files(
|
||||||
'posix-source-accessor.hh',
|
'posix-source-accessor.hh',
|
||||||
'processes.hh',
|
'processes.hh',
|
||||||
'ref.hh',
|
'ref.hh',
|
||||||
'references.hh',
|
|
||||||
'regex-combinators.hh',
|
'regex-combinators.hh',
|
||||||
'repair-flag.hh',
|
'repair-flag.hh',
|
||||||
'serialise.hh',
|
'serialise.hh',
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,6 @@ sources = [ config_priv_h ] + files(
|
||||||
'pos-table.cc',
|
'pos-table.cc',
|
||||||
'position.cc',
|
'position.cc',
|
||||||
'posix-source-accessor.cc',
|
'posix-source-accessor.cc',
|
||||||
'references.cc',
|
|
||||||
'serialise.cc',
|
'serialise.cc',
|
||||||
'signature/local-keys.cc',
|
'signature/local-keys.cc',
|
||||||
'signature/signer.cc',
|
'signature/signer.cc',
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
#include "nix/store/content-address.hh"
|
#include "nix/store/content-address.hh"
|
||||||
#include "nix/cmd/legacy.hh"
|
#include "nix/cmd/legacy.hh"
|
||||||
#include "nix/main/shared.hh"
|
#include "nix/main/shared.hh"
|
||||||
#include "nix/util/references.hh"
|
#include "nix/store/references.hh"
|
||||||
#include "nix/util/archive.hh"
|
#include "nix/util/archive.hh"
|
||||||
#include "nix/util/git.hh"
|
#include "nix/util/git.hh"
|
||||||
#include "nix/util/posix-source-accessor.hh"
|
#include "nix/util/posix-source-accessor.hh"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue