summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/common/TARGETS6
-rw-r--r--src/buildtool/common/repository_config.cpp33
-rw-r--r--src/buildtool/common/repository_config.hpp12
3 files changed, 28 insertions, 23 deletions
diff --git a/src/buildtool/common/TARGETS b/src/buildtool/common/TARGETS
index e26d4bff..df3c0e33 100644
--- a/src/buildtool/common/TARGETS
+++ b/src/buildtool/common/TARGETS
@@ -118,12 +118,10 @@
, ["src/buildtool/file_system", "git_cas"]
, ["src/buildtool/multithreading", "atomic_value"]
, ["src/buildtool/storage", "storage"]
- ]
- , "stage": ["src", "buildtool", "common"]
- , "private-deps":
- [ ["src/utils/automata", "dfa_minimizer"]
, ["src/buildtool/crypto", "hash_function"]
]
+ , "stage": ["src", "buildtool", "common"]
+ , "private-deps": [["src/utils/automata", "dfa_minimizer"]]
}
, "user_structs":
{ "type": ["@", "rules", "CC", "library"]
diff --git a/src/buildtool/common/repository_config.cpp b/src/buildtool/common/repository_config.cpp
index 9ef6213a..735e2c01 100644
--- a/src/buildtool/common/repository_config.cpp
+++ b/src/buildtool/common/repository_config.cpp
@@ -14,7 +14,6 @@
#include "src/buildtool/common/repository_config.hpp"
-#include "src/buildtool/crypto/hash_function.hpp"
#include "src/utils/automata/dfa_minimizer.hpp"
auto RepositoryConfig::RepositoryInfo::BaseContentDescription() const
@@ -38,12 +37,13 @@ auto RepositoryConfig::RepositoryInfo::BaseContentDescription() const
auto RepositoryConfig::RepositoryKey(Storage const& storage,
std::string const& repo) const noexcept
-> std::optional<std::string> {
- auto const& unique = DeduplicateRepo(repo);
+ auto const unique = DeduplicateRepo(repo, storage.GetHashFunction());
if (auto const* data = Data(unique)) {
// compute key only once (thread-safe)
return data->key.SetOnceAndGet(
[this, &storage, &unique]() -> std::optional<std::string> {
- if (auto graph = BuildGraphForRepository(unique)) {
+ if (auto graph = BuildGraphForRepository(
+ unique, storage.GetHashFunction())) {
auto const& cas = storage.CAS();
if (auto digest = cas.StoreBlob(graph->dump(2))) {
return ArtifactDigest{*digest}.hash();
@@ -56,10 +56,11 @@ auto RepositoryConfig::RepositoryKey(Storage const& storage,
}
// Obtain canonical name (according to bisimulation) for the given repository.
-auto RepositoryConfig::DeduplicateRepo(std::string const& repo) const
- -> std::string const& {
+auto RepositoryConfig::DeduplicateRepo(std::string const& repo,
+ HashFunction hash_function) const
+ -> std::string {
// Compute duplicates map only once (thread-safe)
- auto const& duplicates = duplicates_.SetOnceAndGet([this] {
+ auto const& duplicates = duplicates_.SetOnceAndGet([this, &hash_function] {
// To detect duplicate repository descriptions, we represent each
// repository as a DFA state with repo name as state name, repo
// bindings as state transitions, and repo base description as state
@@ -76,9 +77,8 @@ auto RepositoryConfig::DeduplicateRepo(std::string const& repo) const
// content-fixed.
if (data.base_desc) {
// Use hash of content-fixed base description as content id
- auto hash = HashFunction::Instance()
- .ComputeHash(data.base_desc->dump())
- .Bytes();
+ auto hash =
+ hash_function.ComputeHash(data.base_desc->dump()).Bytes();
// Add state with name, transitions, and content id
minimizer.AddState(repo, data.info.name_mapping, hash);
}
@@ -96,12 +96,14 @@ auto RepositoryConfig::DeduplicateRepo(std::string const& repo) const
// Returns the repository-local representation of its dependency graph if all
// contained repositories are content fixed or return std::nullopt otherwise.
-auto RepositoryConfig::BuildGraphForRepository(std::string const& repo) const
+auto RepositoryConfig::BuildGraphForRepository(std::string const& repo,
+ HashFunction hash_function) const
-> std::optional<nlohmann::json> {
auto graph = nlohmann::json::object();
int id_counter{};
std::unordered_map<std::string, std::string> repo_ids{};
- if (AddToGraphAndGetId(&graph, &id_counter, &repo_ids, repo)) {
+ if (AddToGraphAndGetId(
+ &graph, &id_counter, &repo_ids, repo, hash_function)) {
return graph;
}
return std::nullopt;
@@ -117,8 +119,9 @@ auto RepositoryConfig::AddToGraphAndGetId(
gsl::not_null<int*> const& id_counter,
gsl::not_null<std::unordered_map<std::string, std::string>*> const&
repo_ids,
- std::string const& repo) const -> std::optional<std::string> {
- auto const& unique_repo = DeduplicateRepo(repo);
+ std::string const& repo,
+ HashFunction hash_function) const -> std::optional<std::string> {
+ auto const unique_repo = DeduplicateRepo(repo, hash_function);
auto repo_it = repo_ids->find(unique_repo);
if (repo_it != repo_ids->end()) {
// The same or equivalent repository was already requested before
@@ -136,8 +139,8 @@ auto RepositoryConfig::AddToGraphAndGetId(
auto repo_desc = *data->base_desc;
repo_desc["bindings"] = nlohmann::json::object();
for (auto const& [local_name, global_name] : data->info.name_mapping) {
- auto global_id =
- AddToGraphAndGetId(graph, id_counter, repo_ids, global_name);
+ auto global_id = AddToGraphAndGetId(
+ graph, id_counter, repo_ids, global_name, hash_function);
if (not global_id) {
return std::nullopt;
}
diff --git a/src/buildtool/common/repository_config.hpp b/src/buildtool/common/repository_config.hpp
index 8c5c29a5..34918d51 100644
--- a/src/buildtool/common/repository_config.hpp
+++ b/src/buildtool/common/repository_config.hpp
@@ -25,6 +25,7 @@
#include "gsl/gsl"
#include "nlohmann/json.hpp"
+#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/file_system/file_root.hpp"
#include "src/buildtool/file_system/git_cas.hpp"
#include "src/buildtool/multithreading/atomic_value.hpp"
@@ -187,10 +188,12 @@ class RepositoryConfig {
return nullptr;
}
- [[nodiscard]] auto DeduplicateRepo(std::string const& repo) const
- -> std::string const&;
+ [[nodiscard]] auto DeduplicateRepo(std::string const& repo,
+ HashFunction hash_function) const
+ -> std::string;
- [[nodiscard]] auto BuildGraphForRepository(std::string const& repo) const
+ [[nodiscard]] auto BuildGraphForRepository(std::string const& repo,
+ HashFunction hash_function) const
-> std::optional<nlohmann::json>;
[[nodiscard]] auto AddToGraphAndGetId(
@@ -198,7 +201,8 @@ class RepositoryConfig {
gsl::not_null<int*> const& id_counter,
gsl::not_null<std::unordered_map<std::string, std::string>*> const&
repo_ids,
- std::string const& repo) const -> std::optional<std::string>;
+ std::string const& repo,
+ HashFunction hash_function) const -> std::optional<std::string>;
};
#endif // INCLUDED_SRC_BUILDTOOL_COMMON_REPOSITORY_CONFIG_HPP