summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/common/artifact_digest.hpp19
-rw-r--r--src/buildtool/execution_api/local/local_api.hpp10
-rw-r--r--src/buildtool/execution_engine/executor/executor.hpp3
3 files changed, 17 insertions, 15 deletions
diff --git a/src/buildtool/common/artifact_digest.hpp b/src/buildtool/common/artifact_digest.hpp
index d3f828af..36332cdd 100644
--- a/src/buildtool/common/artifact_digest.hpp
+++ b/src/buildtool/common/artifact_digest.hpp
@@ -16,22 +16,23 @@
// be cast to bazel_re::Digest which is the wire format that contains prefixed
// hashes in native mode.
class ArtifactDigest {
+ friend struct std::hash<ArtifactDigest>;
+
public:
ArtifactDigest() noexcept = default;
explicit ArtifactDigest(bazel_re::Digest const& digest) noexcept
: size_{gsl::narrow<std::size_t>(digest.size_bytes())},
hash_{NativeSupport::Unprefix(digest.hash())},
- // In compatible mode, no tree information is stored in a digest,
- // NativeSupport::IsTree will always return false in compatible mode.
+ // Tree information is only stored in a digest in native mode and
+ // false in compatible mode.
is_tree_{NativeSupport::IsTree(digest.hash())} {}
ArtifactDigest(std::string hash, std::size_t size, bool is_tree) noexcept
: size_{size},
hash_{std::move(hash)},
- // In compatible mode, no tree information is stored in a digest. This
- // information is only relevant in native mode, since the hash needs
- // to be prefixed accordingly.
+ // Tree information is only stored in a digest in native mode and
+ // false in compatible mode.
is_tree_{not Compatibility::IsCompatible() and is_tree} {
gsl_ExpectsAudit(not NativeSupport::IsPrefixed(hash_));
}
@@ -46,8 +47,6 @@ class ArtifactDigest {
[[nodiscard]] auto size() const noexcept -> std::size_t { return size_; }
- [[nodiscard]] auto is_tree() const noexcept -> bool { return is_tree_; }
-
// NOLINTNEXTLINE allow implicit casts
[[nodiscard]] operator bazel_re::Digest() const {
return CreateBazelDigest(hash_, size_, is_tree_);
@@ -96,9 +95,9 @@ struct hash<ArtifactDigest> {
[[nodiscard]] auto operator()(ArtifactDigest const& digest) const noexcept
-> std::size_t {
std::size_t seed{};
- hash_combine(&seed, digest.hash());
- hash_combine(&seed, digest.size());
- hash_combine(&seed, digest.is_tree());
+ hash_combine(&seed, digest.hash_);
+ hash_combine(&seed, digest.size_);
+ hash_combine(&seed, digest.is_tree_);
return seed;
}
};
diff --git a/src/buildtool/execution_api/local/local_api.hpp b/src/buildtool/execution_api/local/local_api.hpp
index 06388287..6e1c0074 100644
--- a/src/buildtool/execution_api/local/local_api.hpp
+++ b/src/buildtool/execution_api/local/local_api.hpp
@@ -152,16 +152,18 @@ class LocalApi final : public IExecutionApi {
[[nodiscard]] auto IsAvailable(ArtifactDigest const& digest) const noexcept
-> bool final {
- return static_cast<bool>(digest.is_tree()
- ? storage_->TreePath(digest)
- : storage_->BlobPath(digest, false));
+ return static_cast<bool>(
+ NativeSupport::IsTree(static_cast<bazel_re::Digest>(digest).hash())
+ ? storage_->TreePath(digest)
+ : storage_->BlobPath(digest, false));
}
[[nodiscard]] auto IsAvailable(std::vector<ArtifactDigest> const& digests)
const noexcept -> std::vector<ArtifactDigest> final {
std::vector<ArtifactDigest> result;
for (auto const& digest : digests) {
- auto const& path = digest.is_tree()
+ auto const& path = NativeSupport::IsTree(
+ static_cast<bazel_re::Digest>(digest).hash())
? storage_->TreePath(digest)
: storage_->BlobPath(digest, false);
if (not path) {
diff --git a/src/buildtool/execution_engine/executor/executor.hpp b/src/buildtool/execution_engine/executor/executor.hpp
index 546c5165..fb3593c8 100644
--- a/src/buildtool/execution_engine/executor/executor.hpp
+++ b/src/buildtool/execution_engine/executor/executor.hpp
@@ -260,7 +260,8 @@ class ExecutorImpl {
ArtifactDigest const& digest,
std::string const& hash) noexcept -> bool {
std::optional<std::string> content;
- if (digest.is_tree()) {
+ if (NativeSupport::IsTree(
+ static_cast<bazel_re::Digest>(digest).hash())) {
// if known tree is not available, recursively upload its content
auto tree = ReadGitTree(repo, hash);
if (not tree) {