summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/buildtool/compatibility/compatibility.hpp3
-rw-r--r--src/buildtool/crypto/hash_function.hpp20
-rw-r--r--src/buildtool/main/main.cpp7
-rw-r--r--src/buildtool/storage/config.hpp7
-rw-r--r--test/utils/TARGETS2
-rw-r--r--test/utils/remote_execution/main-remote-execution.cpp6
6 files changed, 11 insertions, 34 deletions
diff --git a/src/buildtool/compatibility/compatibility.hpp b/src/buildtool/compatibility/compatibility.hpp
index e2eecb11..2073ad52 100644
--- a/src/buildtool/compatibility/compatibility.hpp
+++ b/src/buildtool/compatibility/compatibility.hpp
@@ -39,9 +39,6 @@ class Compatibility {
}
static void SetCompatible(bool value = true) noexcept {
Instance().compatible_ = value;
- auto const hasher_type = value ? HashFunction::JustHash::Compatible
- : HashFunction::JustHash::Native;
- HashFunction::Instance().SetHashType(hasher_type);
}
[[nodiscard]] static auto RegisterGitEntry(std::string const& git_hash,
diff --git a/src/buildtool/crypto/hash_function.hpp b/src/buildtool/crypto/hash_function.hpp
index 6932a077..8d932016 100644
--- a/src/buildtool/crypto/hash_function.hpp
+++ b/src/buildtool/crypto/hash_function.hpp
@@ -33,22 +33,18 @@ class HashFunction {
Compatible ///< SHA256 for all hashes.
};
- static constexpr auto kDefaultType = JustHash::Native;
-
- explicit HashFunction(JustHash type) noexcept : type_{type} {}
+ explicit HashFunction(JustHash type) noexcept : type_{type} {
+ static_assert(
+ sizeof(HashFunction) <= sizeof(void*),
+ "HashFunction is passed and stored by value. If the "
+ "class is extended so that its size exceeds the size of a pointer, "
+ "the way how HashFunction is passed and stored must be changed.");
+ }
[[nodiscard]] auto GetHashType() const noexcept -> JustHash {
return type_;
}
- [[nodiscard]] static auto Instance() noexcept -> HashFunction& {
- static HashFunction instance{kDefaultType};
- return instance;
- }
-
- /// \brief Set globally used hash type.
- void SetHashType(JustHash type) noexcept { type_ = type; }
-
/// \brief Compute a plain hash.
[[nodiscard]] auto ComputeHash(std::string const& data) const noexcept
-> Hasher::HashDigest {
@@ -92,7 +88,7 @@ class HashFunction {
}
private:
- JustHash type_ = kDefaultType;
+ JustHash const type_;
[[nodiscard]] auto ComputeTaggedHash(
std::string const& data,
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index 9f10b8bc..b089e321 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -259,12 +259,6 @@ void SetupExecutionServiceConfig(ServiceArguments const& args) {
}
}
-void SetupHashFunction() {
- HashFunction::Instance().SetHashType(
- Compatibility::IsCompatible() ? HashFunction::JustHash::Compatible
- : HashFunction::JustHash::Native);
-}
-
void SetupFileChunker() {
FileChunker::Initialize();
}
@@ -797,7 +791,6 @@ auto main(int argc, char* argv[]) -> int {
*/
GitContext::Create();
- SetupHashFunction();
SetupFileChunker();
if (arguments.cmd == SubCommand::kGc) {
diff --git a/src/buildtool/storage/config.hpp b/src/buildtool/storage/config.hpp
index 5861977e..56274c02 100644
--- a/src/buildtool/storage/config.hpp
+++ b/src/buildtool/storage/config.hpp
@@ -222,10 +222,9 @@ class StorageConfig::Builder final {
}
}
- auto hash_function = default_config.hash_function;
- if (hash_type_.has_value()) {
- hash_function = HashFunction{*hash_type_};
- }
+ auto const hash_function = hash_type_.has_value()
+ ? HashFunction{*hash_type_}
+ : default_config.hash_function;
// Hash the execution backend description
auto backend_description_id = default_config.backend_description_id;
diff --git a/test/utils/TARGETS b/test/utils/TARGETS
index 58353130..dd16466a 100644
--- a/test/utils/TARGETS
+++ b/test/utils/TARGETS
@@ -78,8 +78,6 @@
, ["@", "src", "src/buildtool/logging", "logging"]
, ["@", "src", "src/buildtool/file_system", "git_context"]
, ["@", "src", "src/buildtool/file_system", "file_system_manager"]
- , ["@", "src", "src/buildtool/compatibility", "compatibility"]
- , ["@", "src", "src/buildtool/crypto", "hash_function"]
, "log_config"
, "test_env"
, "test_auth_config"
diff --git a/test/utils/remote_execution/main-remote-execution.cpp b/test/utils/remote_execution/main-remote-execution.cpp
index 05aec296..45021c61 100644
--- a/test/utils/remote_execution/main-remote-execution.cpp
+++ b/test/utils/remote_execution/main-remote-execution.cpp
@@ -21,8 +21,6 @@
#include "catch2/catch_session.hpp"
#include "catch2/catch_test_macros.hpp"
-#include "src/buildtool/compatibility/compatibility.hpp"
-#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/execution_api/remote/config.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
#include "src/buildtool/file_system/git_context.hpp"
@@ -51,10 +49,6 @@ void ConfigureRemoteExecution() {
std::exit(EXIT_FAILURE);
}
- HashFunction::Instance().SetHashType(
- Compatibility::IsCompatible() ? HashFunction::JustHash::Compatible
- : HashFunction::JustHash::Native);
-
auto remote_config = TestRemoteConfig::ReadFromEnvironment();
if (not remote_config or remote_config->remote_address == std::nullopt) {
std::exit(EXIT_FAILURE);