summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/buildtool/file_system/object_cas.hpp21
-rw-r--r--src/buildtool/storage/local_cas.hpp8
-rw-r--r--src/buildtool/storage/local_cas.tpp10
-rw-r--r--test/buildtool/file_system/TARGETS1
-rw-r--r--test/buildtool/file_system/object_cas.test.cpp11
5 files changed, 26 insertions, 25 deletions
diff --git a/src/buildtool/file_system/object_cas.hpp b/src/buildtool/file_system/object_cas.hpp
index 95091773..d8ea71a2 100644
--- a/src/buildtool/file_system/object_cas.hpp
+++ b/src/buildtool/file_system/object_cas.hpp
@@ -23,7 +23,6 @@
#include "gsl/gsl"
#include "src/buildtool/common/artifact_digest.hpp"
-#include "src/buildtool/common/bazel_types.hpp"
#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/file_system/file_storage.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
@@ -43,7 +42,7 @@ class ObjectCAS {
public:
/// \brief Callback type for checking blob existence.
/// \returns true if a blob for the given digest exists at the given path.
- using ExistsFunc = std::function<bool(bazel_re::Digest const&,
+ using ExistsFunc = std::function<bool(ArtifactDigest const&,
std::filesystem::path const&)>;
/// \brief Create new object CAS in store_path directory.
@@ -77,7 +76,7 @@ class ObjectCAS {
/// \param bytes The bytes do create the blob from.
/// \returns Digest of the stored blob or nullopt in case of error.
[[nodiscard]] auto StoreBlobFromBytes(std::string const& bytes)
- const noexcept -> std::optional<bazel_re::Digest> {
+ const noexcept -> std::optional<ArtifactDigest> {
return StoreBlob(bytes, /*is_owner=*/true);
}
@@ -87,16 +86,16 @@ class ObjectCAS {
/// \returns Digest of the stored blob or nullopt in case of error.
[[nodiscard]] auto StoreBlobFromFile(std::filesystem::path const& file_path,
bool is_owner = false) const noexcept
- -> std::optional<bazel_re::Digest> {
+ -> std::optional<ArtifactDigest> {
return StoreBlob(file_path, is_owner);
}
/// \brief Get path to blob.
/// \param digest Digest of the blob to lookup.
/// \returns Path to blob if found or nullopt otherwise.
- [[nodiscard]] auto BlobPath(bazel_re::Digest const& digest) const noexcept
+ [[nodiscard]] auto BlobPath(ArtifactDigest const& digest) const noexcept
-> std::optional<std::filesystem::path> {
- auto id = NativeSupport::Unprefix(digest.hash());
+ auto const& id = digest.hash();
auto blob_path = file_store_.GetPath(id);
if (not IsAvailable(digest, blob_path)) {
logger_.Emit(LogLevel::Debug, "Blob not found {}", id);
@@ -124,17 +123,17 @@ class ObjectCAS {
};
[[nodiscard]] auto CreateDigest(std::string const& bytes) const noexcept
- -> std::optional<bazel_re::Digest> {
+ -> std::optional<ArtifactDigest> {
return ArtifactDigest::Create<kType>(hash_function_, bytes);
}
[[nodiscard]] auto CreateDigest(std::filesystem::path const& file_path)
- const noexcept -> std::optional<bazel_re::Digest> {
+ const noexcept -> std::optional<ArtifactDigest> {
return ArtifactDigest::CreateFromFile<kType>(hash_function_, file_path);
}
[[nodiscard]] auto IsAvailable(
- bazel_re::Digest const& digest,
+ ArtifactDigest const& digest,
std::filesystem::path const& path) const noexcept -> bool {
try {
return std::invoke(exists_.get(), digest, path);
@@ -160,9 +159,9 @@ class ObjectCAS {
/// \brief Store blob from unspecified data to storage.
template <class T>
[[nodiscard]] auto StoreBlob(T const& data, bool is_owner) const noexcept
- -> std::optional<bazel_re::Digest> {
+ -> std::optional<ArtifactDigest> {
if (auto digest = CreateDigest(data)) {
- auto id = NativeSupport::Unprefix(digest->hash());
+ auto const& id = digest->hash();
if (IsAvailable(*digest, file_store_.GetPath(id))) {
return digest;
}
diff --git a/src/buildtool/storage/local_cas.hpp b/src/buildtool/storage/local_cas.hpp
index 86bfc0e4..3097780a 100644
--- a/src/buildtool/storage/local_cas.hpp
+++ b/src/buildtool/storage/local_cas.hpp
@@ -149,8 +149,9 @@ class LocalCAS {
[[nodiscard]] auto BlobPathNoSync(bazel_re::Digest const& digest,
bool is_executable) const noexcept
-> std::optional<std::filesystem::path> {
- return is_executable ? cas_exec_.BlobPath(digest)
- : cas_file_.BlobPath(digest);
+ auto const a_digest = static_cast<ArtifactDigest>(digest);
+ return is_executable ? cas_exec_.BlobPath(a_digest)
+ : cas_file_.BlobPath(a_digest);
}
/// \brief Split a blob into chunks.
@@ -181,7 +182,8 @@ class LocalCAS {
/// \returns Path to the tree if found or nullopt otherwise.
[[nodiscard]] auto TreePath(bazel_re::Digest const& digest) const noexcept
-> std::optional<std::filesystem::path> {
- return cas_tree_.BlobPath(digest);
+ auto const a_digest = static_cast<ArtifactDigest>(digest);
+ return cas_tree_.BlobPath(a_digest);
}
/// \brief Split a tree into chunks.
diff --git a/src/buildtool/storage/local_cas.tpp b/src/buildtool/storage/local_cas.tpp
index 3f6af365..fb828617 100644
--- a/src/buildtool/storage/local_cas.tpp
+++ b/src/buildtool/storage/local_cas.tpp
@@ -113,13 +113,14 @@ auto LocalCAS<kDoGlobalUplink>::LocalUplinkGitTree(
bazel_re::Digest const& digest,
bool splice_result) const noexcept -> bool {
// Determine tree path in latest generation.
- auto tree_path_latest = latest.cas_tree_.BlobPath(digest);
+ auto const a_digest = static_cast<ArtifactDigest>(digest);
+ auto tree_path_latest = latest.cas_tree_.BlobPath(a_digest);
if (tree_path_latest) {
return true;
}
// Determine tree path of given generation.
- auto tree_path = cas_tree_.BlobPath(digest);
+ auto tree_path = cas_tree_.BlobPath(a_digest);
std::optional<LargeObject> spliced;
if (not tree_path) {
spliced = TrySplice<ObjectType::Tree>(digest);
@@ -213,8 +214,9 @@ auto LocalCAS<kDoGlobalUplink>::LocalUplinkBazelDirectory(
return true;
}
+ auto const a_digest = static_cast<ArtifactDigest>(digest);
// Determine bazel directory path of given generation.
- auto dir_path = cas_tree_.BlobPath(digest);
+ auto dir_path = cas_tree_.BlobPath(a_digest);
std::optional<LargeObject> spliced;
if (not dir_path) {
spliced = TrySplice<ObjectType::Tree>(digest);
@@ -244,7 +246,7 @@ auto LocalCAS<kDoGlobalUplink>::LocalUplinkBazelDirectory(
}
// Determine bazel directory path in latest generation.
- auto dir_path_latest = latest.cas_tree_.BlobPath(digest);
+ auto dir_path_latest = latest.cas_tree_.BlobPath(a_digest);
if (spliced) {
// Uplink the large entry afterwards:
diff --git a/test/buildtool/file_system/TARGETS b/test/buildtool/file_system/TARGETS
index baa886f0..a9632e48 100644
--- a/test/buildtool/file_system/TARGETS
+++ b/test/buildtool/file_system/TARGETS
@@ -23,7 +23,6 @@
, ["@", "src", "src/buildtool/file_system", "file_system_manager"]
, ["@", "src", "src/buildtool/file_system", "object_cas"]
, ["@", "src", "src/buildtool/file_system", "object_type"]
- , ["@", "src", "src/buildtool/common", "bazel_types"]
, ["@", "src", "src/buildtool/common", "common"]
, ["@", "src", "src/buildtool/storage", "config"]
, ["utils", "test_storage_config"]
diff --git a/test/buildtool/file_system/object_cas.test.cpp b/test/buildtool/file_system/object_cas.test.cpp
index e9ebf580..58e011a0 100644
--- a/test/buildtool/file_system/object_cas.test.cpp
+++ b/test/buildtool/file_system/object_cas.test.cpp
@@ -14,12 +14,11 @@
#include "src/buildtool/file_system/object_cas.hpp"
-#include <functional> // std::equal_to
+#include <optional> // has_value()
#include <string>
#include "catch2/catch_test_macros.hpp"
#include "src/buildtool/common/artifact_digest.hpp"
-#include "src/buildtool/common/bazel_types.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
#include "src/buildtool/file_system/object_type.hpp"
#include "src/buildtool/storage/config.hpp"
@@ -42,7 +41,7 @@ TEST_CASE("ObjectCAS", "[file_system]") {
// add blob
auto cas_digest = cas.StoreBlobFromBytes(test_content);
CHECK(cas_digest);
- CHECK(std::equal_to<bazel_re::Digest>{}(*cas_digest, test_digest));
+ CHECK(*cas_digest == test_digest);
// verify blob
auto blob_path = cas.BlobPath(*cas_digest);
@@ -60,7 +59,7 @@ TEST_CASE("ObjectCAS", "[file_system]") {
// add blob
auto cas_digest = cas.StoreBlobFromFile("tmp/test");
CHECK(cas_digest);
- CHECK(std::equal_to<bazel_re::Digest>{}(*cas_digest, test_digest));
+ CHECK(*cas_digest == test_digest);
// verify blob
auto blob_path = cas.BlobPath(*cas_digest);
@@ -81,7 +80,7 @@ TEST_CASE("ObjectCAS", "[file_system]") {
// add blob
auto cas_digest = cas.StoreBlobFromBytes(test_content);
CHECK(cas_digest);
- CHECK(std::equal_to<bazel_re::Digest>{}(*cas_digest, test_digest));
+ CHECK(*cas_digest == test_digest);
// verify blob
auto blob_path = cas.BlobPath(*cas_digest);
@@ -99,7 +98,7 @@ TEST_CASE("ObjectCAS", "[file_system]") {
// add blob
auto cas_digest = cas.StoreBlobFromFile("tmp/test");
CHECK(cas_digest);
- CHECK(std::equal_to<bazel_re::Digest>{}(*cas_digest, test_digest));
+ CHECK(*cas_digest == test_digest);
// verify blob
auto blob_path = cas.BlobPath(*cas_digest);