summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/build_engine/expression/TARGETS3
-rw-r--r--src/buildtool/build_engine/expression/expression.cpp10
-rw-r--r--src/buildtool/build_engine/expression/expression.hpp1
-rw-r--r--src/buildtool/build_engine/target_map/TARGETS2
-rw-r--r--src/buildtool/build_engine/target_map/utils.cpp8
-rw-r--r--src/buildtool/common/TARGETS8
-rw-r--r--src/buildtool/common/artifact_description.cpp2
-rw-r--r--src/buildtool/common/artifact_digest.hpp6
-rw-r--r--src/buildtool/common/repository_config.cpp6
-rw-r--r--src/buildtool/common/tree.hpp3
-rw-r--r--src/buildtool/compatibility/compatibility.hpp5
-rw-r--r--src/buildtool/crypto/hash_function.cpp5
-rw-r--r--src/buildtool/crypto/hash_function.hpp51
-rw-r--r--src/buildtool/execution_api/common/execution_common.hpp2
-rw-r--r--src/buildtool/execution_api/local/local_cas_reader.cpp2
-rw-r--r--src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp6
-rw-r--r--src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp9
-rw-r--r--src/buildtool/execution_api/utils/TARGETS1
-rw-r--r--src/buildtool/execution_api/utils/subobject.cpp3
-rw-r--r--src/buildtool/main/TARGETS1
-rw-r--r--src/buildtool/main/install_cas.cpp2
-rw-r--r--src/buildtool/main/main.cpp7
-rw-r--r--src/buildtool/serve_api/serve_service/TARGETS1
-rw-r--r--src/buildtool/serve_api/serve_service/source_tree.cpp7
-rw-r--r--src/buildtool/storage/TARGETS1
-rw-r--r--src/buildtool/storage/compactifier.cpp2
-rw-r--r--src/buildtool/storage/fs_utils.cpp12
-rw-r--r--src/other_tools/repo_map/TARGETS1
-rw-r--r--src/other_tools/repo_map/repos_to_setup_map.cpp5
29 files changed, 101 insertions, 71 deletions
diff --git a/src/buildtool/build_engine/expression/TARGETS b/src/buildtool/build_engine/expression/TARGETS
index 807a43ab..30e64466 100644
--- a/src/buildtool/build_engine/expression/TARGETS
+++ b/src/buildtool/build_engine/expression/TARGETS
@@ -44,7 +44,6 @@
, "linked_map"
, ["src/buildtool/build_engine/base_maps", "entity_name_data"]
, ["src/buildtool/common", "artifact_description"]
- , ["src/buildtool/crypto", "hash_function"]
, ["src/buildtool/multithreading", "atomic_value"]
, ["src/utils/cpp", "json"]
, ["src/utils/cpp", "hash_combine"]
@@ -59,6 +58,8 @@
, ["src/buildtool/logging", "logging"]
, ["src/utils/cpp", "type_safe_arithmetic"]
, ["src/utils/cpp", "path"]
+ , ["src/buildtool/crypto", "hasher"]
+ , ["src/buildtool/crypto", "hash_function"]
]
}
}
diff --git a/src/buildtool/build_engine/expression/expression.cpp b/src/buildtool/build_engine/expression/expression.cpp
index 643d4b31..e155f749 100644
--- a/src/buildtool/build_engine/expression/expression.cpp
+++ b/src/buildtool/build_engine/expression/expression.cpp
@@ -24,6 +24,8 @@
#include "fmt/core.h"
#include "gsl/gsl"
#include "src/buildtool/build_engine/expression/evaluator.hpp"
+#include "src/buildtool/crypto/hash_function.hpp"
+#include "src/buildtool/crypto/hasher.hpp"
#include "src/buildtool/logging/logger.hpp"
#include "src/utils/cpp/gsl.hpp"
#include "src/utils/cpp/json.hpp"
@@ -245,10 +247,11 @@ auto Expression::ComputeHash() const noexcept -> std::string {
: IsNode() ? "#"
: IsName() ? "$"
: ""};
- hash = HashFunction::ComputeHash(prefix + ToString()).Bytes();
+ hash =
+ HashFunction::Instance().ComputeHash(prefix + ToString()).Bytes();
}
else {
- auto hasher = HashFunction::Hasher();
+ auto hasher = HashFunction::Instance().Hasher();
if (IsList()) {
auto list = Value<Expression::list_t>();
hasher.Update("[");
@@ -260,7 +263,8 @@ auto Expression::ComputeHash() const noexcept -> std::string {
auto map = Value<Expression::map_t>();
hasher.Update("{");
for (auto const& el : map->get()) {
- hasher.Update(HashFunction::ComputeHash(el.first).Bytes());
+ hasher.Update(
+ HashFunction::Instance().ComputeHash(el.first).Bytes());
hasher.Update(el.second->ToHash());
}
}
diff --git a/src/buildtool/build_engine/expression/expression.hpp b/src/buildtool/build_engine/expression/expression.hpp
index 1da17dda..ac72ee74 100644
--- a/src/buildtool/build_engine/expression/expression.hpp
+++ b/src/buildtool/build_engine/expression/expression.hpp
@@ -35,7 +35,6 @@
#include "src/buildtool/build_engine/expression/target_node.hpp"
#include "src/buildtool/build_engine/expression/target_result.hpp"
#include "src/buildtool/common/artifact_description.hpp"
-#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/multithreading/atomic_value.hpp"
#include "src/utils/cpp/hex_string.hpp"
#include "src/utils/cpp/json.hpp"
diff --git a/src/buildtool/build_engine/target_map/TARGETS b/src/buildtool/build_engine/target_map/TARGETS
index 6768abe3..9df720e1 100644
--- a/src/buildtool/build_engine/target_map/TARGETS
+++ b/src/buildtool/build_engine/target_map/TARGETS
@@ -74,6 +74,8 @@
, ["src/buildtool/common", "common"]
, ["src/buildtool/common", "config"]
, ["src/buildtool/progress_reporting", "progress"]
+ , ["src/buildtool/crypto", "hasher"]
+ , ["src/buildtool/crypto", "hash_function"]
]
}
, "target_map_testable_internals":
diff --git a/src/buildtool/build_engine/target_map/utils.cpp b/src/buildtool/build_engine/target_map/utils.cpp
index 91269833..79d48ed0 100644
--- a/src/buildtool/build_engine/target_map/utils.cpp
+++ b/src/buildtool/build_engine/target_map/utils.cpp
@@ -21,6 +21,8 @@
#include <utility> // std::move
#include <vector>
+#include "src/buildtool/crypto/hash_function.hpp"
+#include "src/buildtool/crypto/hasher.hpp"
#include "src/utils/cpp/path.hpp"
#include "src/utils/cpp/path_hash.hpp"
@@ -184,9 +186,9 @@ auto BuildMaps::Target::Utils::getTainted(
namespace {
auto hash_vector(std::vector<std::string> const& vec) -> std::string {
- auto hasher = HashFunction::Hasher();
+ auto hasher = HashFunction::Instance().Hasher();
for (auto const& s : vec) {
- hasher.Update(HashFunction::ComputeHash(s).Bytes());
+ hasher.Update(HashFunction::Instance().ComputeHash(s).Bytes());
}
return std::move(hasher).Finalize().Bytes();
}
@@ -202,7 +204,7 @@ auto BuildMaps::Target::Utils::createAction(
double timeout_scale,
const ExpressionPtr& execution_properties_exp,
const ExpressionPtr& inputs_exp) -> ActionDescription::Ptr {
- auto hasher = HashFunction::Hasher();
+ auto hasher = HashFunction::Instance().Hasher();
hasher.Update(hash_vector(output_files));
hasher.Update(hash_vector(output_dirs));
hasher.Update(hash_vector(command));
diff --git a/src/buildtool/common/TARGETS b/src/buildtool/common/TARGETS
index 98c93ff0..e26d4bff 100644
--- a/src/buildtool/common/TARGETS
+++ b/src/buildtool/common/TARGETS
@@ -73,7 +73,8 @@
, ["src/buildtool/file_system", "object_type"]
, ["src/buildtool/logging", "logging"]
]
- , "private-deps": [["src/utils/cpp", "json"]]
+ , "private-deps":
+ [["src/utils/cpp", "json"], ["src/buildtool/crypto", "hash_function"]]
, "stage": ["src", "buildtool", "common"]
}
, "action_description":
@@ -119,7 +120,10 @@
, ["src/buildtool/storage", "storage"]
]
, "stage": ["src", "buildtool", "common"]
- , "private-deps": [["src/utils/automata", "dfa_minimizer"]]
+ , "private-deps":
+ [ ["src/utils/automata", "dfa_minimizer"]
+ , ["src/buildtool/crypto", "hash_function"]
+ ]
}
, "user_structs":
{ "type": ["@", "rules", "CC", "library"]
diff --git a/src/buildtool/common/artifact_description.cpp b/src/buildtool/common/artifact_description.cpp
index 73d0af05..6d27375e 100644
--- a/src/buildtool/common/artifact_description.cpp
+++ b/src/buildtool/common/artifact_description.cpp
@@ -194,7 +194,7 @@ auto ArtifactDescription::ToString(int indent) const noexcept -> std::string {
auto ArtifactDescription::ComputeId(nlohmann::json const& desc) noexcept
-> ArtifactIdentifier {
try {
- return HashFunction::ComputeHash(desc.dump()).Bytes();
+ return HashFunction::Instance().ComputeHash(desc.dump()).Bytes();
} catch (std::exception const& ex) {
Logger::Log(LogLevel::Error,
"Computing artifact id failed with error:\n{}",
diff --git a/src/buildtool/common/artifact_digest.hpp b/src/buildtool/common/artifact_digest.hpp
index 8cbf6ccc..59299232 100644
--- a/src/buildtool/common/artifact_digest.hpp
+++ b/src/buildtool/common/artifact_digest.hpp
@@ -78,13 +78,13 @@ class ArtifactDigest {
-> ArtifactDigest {
if constexpr (kType == ObjectType::Tree) {
return ArtifactDigest{
- HashFunction::ComputeTreeHash(content).HexString(),
+ HashFunction::Instance().ComputeTreeHash(content).HexString(),
content.size(),
/*is_tree=*/true};
}
else {
return ArtifactDigest{
- HashFunction::ComputeBlobHash(content).HexString(),
+ HashFunction::Instance().ComputeBlobHash(content).HexString(),
content.size(),
/*is_tree=*/false};
}
@@ -95,7 +95,7 @@ class ArtifactDigest {
std::filesystem::path const& path) noexcept
-> std::optional<ArtifactDigest> {
static constexpr bool kIsTree = IsTreeObject(kType);
- auto hash = HashFunction::ComputeHashFile(path, kIsTree);
+ auto hash = HashFunction::Instance().ComputeHashFile(path, kIsTree);
if (hash) {
return ArtifactDigest{
hash->first.HexString(), hash->second, kIsTree};
diff --git a/src/buildtool/common/repository_config.cpp b/src/buildtool/common/repository_config.cpp
index d26ba55b..9ef6213a 100644
--- a/src/buildtool/common/repository_config.cpp
+++ b/src/buildtool/common/repository_config.cpp
@@ -14,6 +14,7 @@
#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
@@ -75,8 +76,9 @@ 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::ComputeHash(data.base_desc->dump()).Bytes();
+ auto hash = HashFunction::Instance()
+ .ComputeHash(data.base_desc->dump())
+ .Bytes();
// Add state with name, transitions, and content id
minimizer.AddState(repo, data.info.name_mapping, hash);
}
diff --git a/src/buildtool/common/tree.hpp b/src/buildtool/common/tree.hpp
index e9d5ef84..06c2e7d5 100644
--- a/src/buildtool/common/tree.hpp
+++ b/src/buildtool/common/tree.hpp
@@ -85,7 +85,8 @@ class Tree {
}
static auto ComputeId(inputs_t const& inputs) -> std::string {
- return HashFunction::ComputeHash(ComputeDescription(inputs).dump())
+ return HashFunction::Instance()
+ .ComputeHash(ComputeDescription(inputs).dump())
.HexString();
}
};
diff --git a/src/buildtool/compatibility/compatibility.hpp b/src/buildtool/compatibility/compatibility.hpp
index 46f94b9a..6b3843aa 100644
--- a/src/buildtool/compatibility/compatibility.hpp
+++ b/src/buildtool/compatibility/compatibility.hpp
@@ -41,7 +41,7 @@ class Compatibility {
Instance().compatible_ = value;
auto const hasher_type = value ? HashFunction::JustHash::Compatible
: HashFunction::JustHash::Native;
- HashFunction::SetHashType(hasher_type);
+ HashFunction::Instance().SetHashType(hasher_type);
}
[[nodiscard]] static auto RegisterGitEntry(std::string const& git_hash,
@@ -59,7 +59,8 @@ class Compatibility {
}
// This is only used in compatible mode. Therefore, the default hash
// function produces the compatible hash.
- auto compatible_hash = HashFunction::ComputeHash(data).HexString();
+ auto compatible_hash =
+ HashFunction::Instance().ComputeHash(data).HexString();
std::unique_lock lock_{Instance().mutex_};
Instance().git_to_compatible_[git_hash] = compatible_hash;
Instance().compatible_to_git_[compatible_hash] = {git_hash, repo};
diff --git a/src/buildtool/crypto/hash_function.cpp b/src/buildtool/crypto/hash_function.cpp
index 02e43f1f..d1ca0c2b 100644
--- a/src/buildtool/crypto/hash_function.cpp
+++ b/src/buildtool/crypto/hash_function.cpp
@@ -16,20 +16,19 @@
#include <cstddef>
#include <fstream>
-#include <string>
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
[[nodiscard]] auto HashFunction::ComputeHashFile(
const std::filesystem::path& file_path,
- bool as_tree) noexcept
+ bool as_tree) const noexcept
-> std::optional<std::pair<Hasher::HashDigest, std::uintmax_t>> {
static constexpr std::size_t kChunkSize{4048};
try {
auto hasher = Hasher();
auto size = std::filesystem::file_size(file_path);
- if (HashType() == JustHash::Native) {
+ if (type_ == JustHash::Native) {
hasher.Update(
(as_tree ? std::string{"tree "} : std::string{"blob "}) +
std::to_string(size) + '\0');
diff --git a/src/buildtool/crypto/hash_function.hpp b/src/buildtool/crypto/hash_function.hpp
index f2dc618a..6932a077 100644
--- a/src/buildtool/crypto/hash_function.hpp
+++ b/src/buildtool/crypto/hash_function.hpp
@@ -33,19 +33,30 @@ class HashFunction {
Compatible ///< SHA256 for all hashes.
};
- /// \brief Set globally used hash type.
- static void SetHashType(JustHash type) {
- [[maybe_unused]] auto _ = HashType(type);
+ static constexpr auto kDefaultType = JustHash::Native;
+
+ explicit HashFunction(JustHash type) noexcept : type_{type} {}
+
+ [[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]] static auto ComputeHash(std::string const& data) noexcept
+ [[nodiscard]] auto ComputeHash(std::string const& data) const noexcept
-> Hasher::HashDigest {
return ComputeTaggedHash(data);
}
/// \brief Compute a blob hash.
- [[nodiscard]] static auto ComputeBlobHash(std::string const& data) noexcept
+ [[nodiscard]] auto ComputeBlobHash(std::string const& data) const noexcept
-> Hasher::HashDigest {
static auto const kBlobTagCreator =
[](std::string const& data) -> std::string {
@@ -55,13 +66,12 @@ class HashFunction {
}
/// \brief Compute the blob hash of a file or std::nullopt on IO error.
- [[nodiscard]] static auto ComputeHashFile(
- const std::filesystem::path& file_path,
- bool as_tree) noexcept
+ [[nodiscard]] auto ComputeHashFile(const std::filesystem::path& file_path,
+ bool as_tree) const noexcept
-> std::optional<std::pair<Hasher::HashDigest, std::uintmax_t>>;
/// \brief Compute a tree hash.
- [[nodiscard]] static auto ComputeTreeHash(std::string const& data) noexcept
+ [[nodiscard]] auto ComputeTreeHash(std::string const& data) const noexcept
-> Hasher::HashDigest {
static auto const kTreeTagCreator =
[](std::string const& data) -> std::string {
@@ -71,8 +81,8 @@ class HashFunction {
}
/// \brief Obtain incremental hasher for computing plain hashes.
- [[nodiscard]] static auto Hasher() noexcept -> ::Hasher {
- switch (HashType()) {
+ [[nodiscard]] auto Hasher() const noexcept -> ::Hasher {
+ switch (type_) {
case JustHash::Native:
return ::Hasher{Hasher::HashType::SHA1};
case JustHash::Compatible:
@@ -82,23 +92,14 @@ class HashFunction {
}
private:
- static constexpr auto kDefaultType = JustHash::Native;
-
- [[nodiscard]] static auto HashType(
- std::optional<JustHash> type = std::nullopt) -> JustHash {
- static JustHash type_{kDefaultType};
- if (type) {
- type_ = *type;
- }
- return type_;
- }
+ JustHash type_ = kDefaultType;
- [[nodiscard]] static auto ComputeTaggedHash(
+ [[nodiscard]] auto ComputeTaggedHash(
std::string const& data,
- std::function<std::string(std::string const&)> const& tag_creator =
- {}) noexcept -> Hasher::HashDigest {
+ std::function<std::string(std::string const&)> const& tag_creator = {})
+ const noexcept -> Hasher::HashDigest {
auto hasher = Hasher();
- if (tag_creator and HashType() == JustHash::Native) {
+ if (tag_creator and type_ == JustHash::Native) {
hasher.Update(tag_creator(data));
}
hasher.Update(data);
diff --git a/src/buildtool/execution_api/common/execution_common.hpp b/src/buildtool/execution_api/common/execution_common.hpp
index d3079d5d..6cb0beda 100644
--- a/src/buildtool/execution_api/common/execution_common.hpp
+++ b/src/buildtool/execution_api/common/execution_common.hpp
@@ -106,7 +106,7 @@ static void EncodeUUIDVariant1(std::string* uuid) {
constexpr auto kHexDashPos = std::array{8UL, 12UL, 16UL, 20UL};
auto value = fmt::format("{}-{}", std::to_string(kRandomConstant), seed);
- auto uuid = HashFunction::ComputeHash(value).Bytes();
+ auto uuid = HashFunction::Instance().ComputeHash(value).Bytes();
EncodeUUIDVersion4(&uuid);
EncodeUUIDVariant1(&uuid);
Expects(uuid.size() >= kRawLength);
diff --git a/src/buildtool/execution_api/local/local_cas_reader.cpp b/src/buildtool/execution_api/local/local_cas_reader.cpp
index a8933adc..504b4c74 100644
--- a/src/buildtool/execution_api/local/local_cas_reader.cpp
+++ b/src/buildtool/execution_api/local/local_cas_reader.cpp
@@ -60,7 +60,7 @@ auto LocalCasReader::ReadGitTree(ArtifactDigest const& digest) const noexcept
};
return GitRepo::ReadTreeData(
*content,
- HashFunction::ComputeTreeHash(*content).Bytes(),
+ HashFunction::Instance().ComputeTreeHash(*content).Bytes(),
check_symlinks,
/*is_hex_id=*/false);
}
diff --git a/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp b/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp
index edfd1199..b5cce65e 100644
--- a/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp
+++ b/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp
@@ -52,7 +52,8 @@ namespace {
stub) noexcept -> bool {
// Create empty blob.
std::string empty_str{};
- std::string hash = HashFunction::ComputeBlobHash(empty_str).HexString();
+ std::string hash =
+ HashFunction::Instance().ComputeBlobHash(empty_str).HexString();
bazel_re::Digest digest{};
digest.set_hash(NativeSupport::Prefix(hash, false));
digest.set_size_bytes(empty_str.size());
@@ -117,7 +118,8 @@ namespace {
stub) noexcept -> bool {
// Create empty blob.
std::string empty_str{};
- std::string hash = HashFunction::ComputeBlobHash(empty_str).HexString();
+ std::string hash =
+ HashFunction::Instance().ComputeBlobHash(empty_str).HexString();
bazel_re::Digest digest{};
digest.set_hash(NativeSupport::Prefix(hash, false));
digest.set_size_bytes(empty_str.size());
diff --git a/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp b/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp
index 9f4c34c8..4547ff8c 100644
--- a/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp
+++ b/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp
@@ -89,10 +89,11 @@ auto BazelNetworkReader::ReadGitTree(ArtifactDigest const& digest)
};
std::string const& content = *read_blob->data;
- return GitRepo::ReadTreeData(content,
- HashFunction::ComputeTreeHash(content).Bytes(),
- check_symlinks,
- /*is_hex_id=*/false);
+ return GitRepo::ReadTreeData(
+ content,
+ HashFunction::Instance().ComputeTreeHash(content).Bytes(),
+ check_symlinks,
+ /*is_hex_id=*/false);
}
auto BazelNetworkReader::DumpRawTree(Artifact::ObjectInfo const& info,
diff --git a/src/buildtool/execution_api/utils/TARGETS b/src/buildtool/execution_api/utils/TARGETS
index 77a29955..b202a9ea 100644
--- a/src/buildtool/execution_api/utils/TARGETS
+++ b/src/buildtool/execution_api/utils/TARGETS
@@ -11,6 +11,7 @@
[ ["src/buildtool/compatibility", "compatibility"]
, ["src/buildtool/execution_api/bazel_msg", "bazel_msg_factory"]
, ["src/buildtool/logging", "logging"]
+ , ["src/buildtool/crypto", "hash_function"]
]
, "stage": ["src", "buildtool", "execution_api", "utils"]
}
diff --git a/src/buildtool/execution_api/utils/subobject.cpp b/src/buildtool/execution_api/utils/subobject.cpp
index 4217c910..20eda828 100644
--- a/src/buildtool/execution_api/utils/subobject.cpp
+++ b/src/buildtool/execution_api/utils/subobject.cpp
@@ -16,6 +16,7 @@
#ifndef BOOTSTRAP_BUILD_TOOL
#include "src/buildtool/compatibility/compatibility.hpp"
+#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp"
#include "src/buildtool/execution_api/common/tree_reader_utils.hpp"
#include "src/buildtool/logging/log_level.hpp"
@@ -77,7 +78,7 @@ auto RetrieveSubPathId(Artifact::ObjectInfo object_info,
else {
auto entries = GitRepo::ReadTreeData(
*data,
- HashFunction::ComputeTreeHash(*data).Bytes(),
+ HashFunction::Instance().ComputeTreeHash(*data).Bytes(),
[](auto const& /*unused*/) { return true; },
/*is_hex_id=*/false);
if (not entries) {
diff --git a/src/buildtool/main/TARGETS b/src/buildtool/main/TARGETS
index 7ddedaa7..7f39d28f 100644
--- a/src/buildtool/main/TARGETS
+++ b/src/buildtool/main/TARGETS
@@ -36,6 +36,7 @@
, ["src/buildtool/serve_api/remote", "serve_api"]
, ["src/buildtool/execution_api/common", "api_bundle"]
, ["src/utils/cpp", "gsl"]
+ , ["src/buildtool/crypto", "hash_function"]
, "common"
, "cli"
, "version"
diff --git a/src/buildtool/main/install_cas.cpp b/src/buildtool/main/install_cas.cpp
index 21f694e3..8af7a2df 100644
--- a/src/buildtool/main/install_cas.cpp
+++ b/src/buildtool/main/install_cas.cpp
@@ -32,7 +32,7 @@ namespace {
[[nodiscard]] auto InvalidSizeString(std::string const& size_str,
std::string const& hash,
bool has_remote) noexcept -> bool {
- static auto const kEmptyHash = HashFunction::ComputeBlobHash("");
+ static auto const kEmptyHash = HashFunction::Instance().ComputeBlobHash("");
return Compatibility::IsCompatible() and // native mode is fine
(size_str == "0" or size_str.empty()) and // not "0" or "" is fine
kEmptyHash.HexString() != hash and // empty hash is fine
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index e78cb41b..a3be587b 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -38,6 +38,7 @@
#include "src/buildtool/common/repository_config.hpp"
#include "src/buildtool/common/statistics.hpp"
#include "src/buildtool/compatibility/compatibility.hpp"
+#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/execution_api/local/config.hpp"
#include "src/buildtool/file_system/file_root.hpp"
#include "src/buildtool/logging/log_config.hpp"
@@ -257,9 +258,9 @@ void SetupExecutionServiceConfig(ServiceArguments const& args) {
}
void SetupHashFunction() {
- HashFunction::SetHashType(Compatibility::IsCompatible()
- ? HashFunction::JustHash::Compatible
- : HashFunction::JustHash::Native);
+ HashFunction::Instance().SetHashType(
+ Compatibility::IsCompatible() ? HashFunction::JustHash::Compatible
+ : HashFunction::JustHash::Native);
}
void SetupFileChunker() {
diff --git a/src/buildtool/serve_api/serve_service/TARGETS b/src/buildtool/serve_api/serve_service/TARGETS
index 92886167..ecdb353b 100644
--- a/src/buildtool/serve_api/serve_service/TARGETS
+++ b/src/buildtool/serve_api/serve_service/TARGETS
@@ -39,6 +39,7 @@
, ["src/buildtool/storage", "fs_utils"]
, ["src/utils/archive", "archive_ops"]
, ["src/buildtool/execution_api/git", "git"]
+ , ["src/buildtool/crypto", "hash_function"]
]
}
, "serve_server_implementation":
diff --git a/src/buildtool/serve_api/serve_service/source_tree.cpp b/src/buildtool/serve_api/serve_service/source_tree.cpp
index 29e9ade2..f86fdb45 100644
--- a/src/buildtool/serve_api/serve_service/source_tree.cpp
+++ b/src/buildtool/serve_api/serve_service/source_tree.cpp
@@ -25,6 +25,7 @@
#include "src/buildtool/common/artifact_digest.hpp"
#include "src/buildtool/compatibility/compatibility.hpp"
#include "src/buildtool/compatibility/native_support.hpp"
+#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/execution_api/git/git_api.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
#include "src/buildtool/file_system/git_repo.hpp"
@@ -1158,9 +1159,9 @@ auto SourceTreeService::ServeDistdirTree(
kv.name(), std::make_pair(blob_digest, kv.executable()));
}
// get hash of distdir content; this must match with that in just-mr
- auto content_id =
- HashFunction::ComputeBlobHash(nlohmann::json(content_list).dump())
- .HexString();
+ auto content_id = HashFunction::Instance()
+ .ComputeBlobHash(nlohmann::json(content_list).dump())
+ .HexString();
// create in-memory tree of the distdir, now that we know we have all blobs
auto tree = GitRepo::CreateShallowTree(entries);
if (not tree) {
diff --git a/src/buildtool/storage/TARGETS b/src/buildtool/storage/TARGETS
index 1cd5fed9..0b264aab 100644
--- a/src/buildtool/storage/TARGETS
+++ b/src/buildtool/storage/TARGETS
@@ -108,6 +108,7 @@
, ["src/buildtool/logging", "log_level"]
, ["src/buildtool/logging", "logging"]
, ["src/utils/cpp", "path"]
+ , ["src/buildtool/crypto", "hash_function"]
]
}
, "file_chunker":
diff --git a/src/buildtool/storage/compactifier.cpp b/src/buildtool/storage/compactifier.cpp
index 7dac4a06..34f17b67 100644
--- a/src/buildtool/storage/compactifier.cpp
+++ b/src/buildtool/storage/compactifier.cpp
@@ -156,7 +156,7 @@ template <ObjectType kType>
}
// Calculate reference hash size:
- auto const kHashSize = HashFunction::Hasher().GetHashLength();
+ auto const kHashSize = HashFunction::Instance().Hasher().GetHashLength();
auto const kFileNameSize =
kHashSize - FileStorageData::kDirectoryNameLength;
diff --git a/src/buildtool/storage/fs_utils.cpp b/src/buildtool/storage/fs_utils.cpp
index 03ef75c6..2db157fb 100644
--- a/src/buildtool/storage/fs_utils.cpp
+++ b/src/buildtool/storage/fs_utils.cpp
@@ -19,6 +19,7 @@
#include <utility>
#include "nlohmann/json.hpp"
+#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
@@ -76,11 +77,12 @@ auto GetForeignFileTreeIDFile(StorageConfig const& storage_config,
-> std::filesystem::path {
return GetDistdirTreeIDFile(
storage_config,
- HashFunction::ComputeBlobHash(
- nlohmann::json(
- std::unordered_map<std::string, std::pair<std::string, bool>>{
- {name, {content, executable}}})
- .dump())
+ HashFunction::Instance()
+ .ComputeBlobHash(
+ nlohmann::json(std::unordered_map<std::string,
+ std::pair<std::string, bool>>{
+ {name, {content, executable}}})
+ .dump())
.HexString(),
generation);
}
diff --git a/src/other_tools/repo_map/TARGETS b/src/other_tools/repo_map/TARGETS
index 1b2f23a0..89ea95fd 100644
--- a/src/other_tools/repo_map/TARGETS
+++ b/src/other_tools/repo_map/TARGETS
@@ -26,6 +26,7 @@
, ["src/other_tools/ops_maps", "content_cas_map"]
, ["src/other_tools/ops_maps", "git_tree_fetch_map"]
, ["src/other_tools/utils", "parse_archive"]
+ , ["src/buildtool/crypto", "hash_function"]
]
}
}
diff --git a/src/other_tools/repo_map/repos_to_setup_map.cpp b/src/other_tools/repo_map/repos_to_setup_map.cpp
index 7ccb73d9..d3519a27 100644
--- a/src/other_tools/repo_map/repos_to_setup_map.cpp
+++ b/src/other_tools/repo_map/repos_to_setup_map.cpp
@@ -18,6 +18,7 @@
#include <utility> // std::move
#include "fmt/core.h"
+#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/file_system/file_root.hpp"
#include "src/buildtool/file_system/symlinks_map/pragma_special.hpp"
#include "src/buildtool/logging/log_level.hpp"
@@ -591,8 +592,8 @@ void DistdirCheckout(ExpressionPtr const& repo_desc,
}
// get hash of distdir content
auto distdir_content_id =
- HashFunction::ComputeBlobHash(
- nlohmann::json(*distdir_content_for_id).dump())
+ HashFunction::Instance()
+ .ComputeBlobHash(nlohmann::json(*distdir_content_for_id).dump())
.HexString();
// get the WS root as git tree
DistdirInfo distdir_info = {