summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-09-02 18:12:23 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-09-09 13:07:13 +0200
commit4fc124f21ea664b968ab6ee320c6ecb030292c08 (patch)
tree61ef61a4dfee5976c6e1c1da2cfe97307aa6fe08
parent56f91aac0c25e6e80dbaae087227502312accee6 (diff)
downloadjustbuild-4fc124f21ea664b968ab6ee320c6ecb030292c08.tar.gz
Use ArtifactDigest in LocalAction
-rw-r--r--src/buildtool/execution_api/local/local_action.cpp41
-rw-r--r--src/buildtool/execution_api/local/local_action.hpp4
-rw-r--r--src/buildtool/execution_api/local/local_response.hpp53
3 files changed, 55 insertions, 43 deletions
diff --git a/src/buildtool/execution_api/local/local_action.cpp b/src/buildtool/execution_api/local/local_action.cpp
index 2c79b32e..97507d35 100644
--- a/src/buildtool/execution_api/local/local_action.cpp
+++ b/src/buildtool/execution_api/local/local_action.cpp
@@ -21,7 +21,7 @@
#include <system_error>
#include <utility>
-#include "src/buildtool/compatibility/native_support.hpp"
+#include "src/buildtool/common/artifact_digest_factory.hpp"
#include "src/buildtool/execution_api/common/tree_reader.hpp"
#include "src/buildtool/execution_api/local/local_cas_reader.hpp"
#include "src/buildtool/execution_api/local/local_response.hpp"
@@ -117,7 +117,7 @@ auto LocalAction::Execute(Logger const* logger) noexcept
}
if (ExecutionEnabled(cache_flag_)) {
- if (auto output = Run(static_cast<bazel_re::Digest>(*action))) {
+ if (auto output = Run(*action)) {
if (cache_flag_ == CacheFlag::PretendCached) {
// ensure the same id is created as if caching were enabled
auto const action_cached =
@@ -146,11 +146,10 @@ auto LocalAction::Execute(Logger const* logger) noexcept
return nullptr;
}
-auto LocalAction::Run(bazel_re::Digest const& action_id) const noexcept
+auto LocalAction::Run(ArtifactDigest const& action_id) const noexcept
-> std::optional<Output> {
- auto exec_path =
- CreateUniquePath(local_context_.storage_config->ExecutionRoot() /
- NativeSupport::Unprefix(action_id.hash()));
+ auto const exec_path = CreateUniquePath(
+ local_context_.storage_config->ExecutionRoot() / action_id.hash());
if (not exec_path) {
return std::nullopt;
@@ -179,20 +178,19 @@ auto LocalAction::Run(bazel_re::Digest const& action_id) const noexcept
if (exit_code.has_value()) {
Output result{};
result.action.set_exit_code(*exit_code);
- if (gsl::owner<bazel_re::Digest*> digest_ptr =
- DigestFromOwnedFile(*exec_path / "stdout")) {
- result.action.set_allocated_stdout_digest(digest_ptr);
+ if (auto const digest = DigestFromOwnedFile(*exec_path / "stdout")) {
+ *result.action.mutable_stdout_digest() =
+ ArtifactDigestFactory::ToBazel(*digest);
}
- if (gsl::owner<bazel_re::Digest*> digest_ptr =
- DigestFromOwnedFile(*exec_path / "stderr")) {
- result.action.set_allocated_stderr_digest(digest_ptr);
+ if (auto const digest = DigestFromOwnedFile(*exec_path / "stderr")) {
+ *result.action.mutable_stderr_digest() =
+ ArtifactDigestFactory::ToBazel(*digest);
}
if (CollectAndStoreOutputs(&result.action, build_root / cwd_)) {
if (cache_flag_ == CacheFlag::CacheOutput) {
- ArtifactDigest const a_digest{action_id};
if (not local_context_.storage->ActionCache().StoreResult(
- a_digest, result.action)) {
+ action_id, result.action)) {
logger_.Emit(LogLevel::Warning,
"failed to store action results");
}
@@ -384,8 +382,8 @@ auto LocalAction::CollectOutputFileOrSymlink(
if (digest) {
auto out_file = bazel_re::OutputFile{};
out_file.set_path(local_path);
- out_file.set_allocated_digest(
- gsl::owner<bazel_re::Digest*>{new bazel_re::Digest{*digest}});
+ *out_file.mutable_digest() =
+ ArtifactDigestFactory::ToBazel(*digest);
out_file.set_is_executable(is_executable);
return out_file;
}
@@ -422,7 +420,7 @@ auto LocalAction::CollectOutputDirOrSymlink(
auto out_dir = bazel_re::OutputDirectory{};
out_dir.set_path(local_path);
(*out_dir.mutable_tree_digest()) =
- static_cast<bazel_re::Digest>(*digest);
+ ArtifactDigestFactory::ToBazel(*digest);
return out_dir;
}
}
@@ -496,10 +494,7 @@ auto LocalAction::CollectAndStoreOutputs(
}
auto LocalAction::DigestFromOwnedFile(std::filesystem::path const& file_path)
- const noexcept -> gsl::owner<bazel_re::Digest*> {
- if (auto digest = local_context_.storage->CAS().StoreBlob</*kOwner=*/true>(
- file_path, /*is_executable=*/false)) {
- return new bazel_re::Digest{std::move(*digest)};
- }
- return nullptr;
+ const noexcept -> std::optional<ArtifactDigest> {
+ return local_context_.storage->CAS().StoreBlob</*kOwner=*/true>(
+ file_path, /*is_executable=*/false);
}
diff --git a/src/buildtool/execution_api/local/local_action.hpp b/src/buildtool/execution_api/local/local_action.hpp
index dedc2951..d6ab0e58 100644
--- a/src/buildtool/execution_api/local/local_action.hpp
+++ b/src/buildtool/execution_api/local/local_action.hpp
@@ -117,7 +117,7 @@ class LocalAction final : public IExecutionAction {
return BazelMsgFactory::CreateActionDigestFromCommandLine(request);
}
- [[nodiscard]] auto Run(bazel_re::Digest const& action_id) const noexcept
+ [[nodiscard]] auto Run(ArtifactDigest const& action_id) const noexcept
-> std::optional<Output>;
[[nodiscard]] auto StageInput(
@@ -154,7 +154,7 @@ class LocalAction final : public IExecutionAction {
/// \brief Store file from path in file CAS and return pointer to digest.
[[nodiscard]] auto DigestFromOwnedFile(
std::filesystem::path const& file_path) const noexcept
- -> gsl::owner<bazel_re::Digest*>;
+ -> std::optional<ArtifactDigest>;
};
#endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_LOCAL_LOCAL_ACTION_HPP
diff --git a/src/buildtool/execution_api/local/local_response.hpp b/src/buildtool/execution_api/local/local_response.hpp
index 8e563c5d..3cc04361 100644
--- a/src/buildtool/execution_api/local/local_response.hpp
+++ b/src/buildtool/execution_api/local/local_response.hpp
@@ -44,23 +44,15 @@ class LocalResponse final : public IExecutionResponse {
return (output_.action.stdout_digest().size_bytes() != 0);
}
auto StdErr() noexcept -> std::string final {
- if (auto path = storage_.CAS().BlobPath(
- static_cast<ArtifactDigest>(output_.action.stderr_digest()),
- /*is_executable=*/false)) {
- if (auto content = FileSystemManager::ReadFile(*path)) {
- return std::move(*content);
- }
+ if (auto content = ReadContent(output_.action.stderr_digest())) {
+ return *std::move(content);
}
Logger::Log(LogLevel::Debug, "reading stderr failed");
return {};
}
auto StdOut() noexcept -> std::string final {
- if (auto path = storage_.CAS().BlobPath(
- static_cast<ArtifactDigest>(output_.action.stdout_digest()),
- /*is_executable=*/false)) {
- if (auto content = FileSystemManager::ReadFile(*path)) {
- return std::move(*content);
- }
+ if (auto content = ReadContent(output_.action.stdout_digest())) {
+ return *std::move(content);
}
Logger::Log(LogLevel::Debug, "reading stdout failed");
return {};
@@ -121,14 +113,20 @@ class LocalResponse final : public IExecutionResponse {
dir_symlinks.reserve(static_cast<std::size_t>(
action_result.output_directory_symlinks_size()));
+ auto const hash_type = storage_.GetHashFunction().GetType();
// collect files and store them
for (auto const& file : action_result.output_files()) {
+ auto digest =
+ ArtifactDigestFactory::FromBazel(hash_type, file.digest());
+ if (not digest) {
+ return;
+ }
try {
artifacts.emplace(
file.path(),
- Artifact::ObjectInfo{
- .digest = ArtifactDigest{file.digest()},
- .type = file.is_executable() ? ObjectType::Executable
+ Artifact::ObjectInfo{.digest = *std::move(digest),
+ .type = file.is_executable()
+ ? ObjectType::Executable
: ObjectType::File});
} catch (...) {
return;
@@ -166,12 +164,16 @@ class LocalResponse final : public IExecutionResponse {
// collect directories and store them
for (auto const& dir : action_result.output_directories()) {
+ auto digest =
+ ArtifactDigestFactory::FromBazel(hash_type, dir.tree_digest());
+ if (not digest) {
+ return;
+ }
try {
artifacts.emplace(
dir.path(),
- Artifact::ObjectInfo{
- .digest = ArtifactDigest{dir.tree_digest()},
- .type = ObjectType::Tree});
+ Artifact::ObjectInfo{.digest = *std::move(digest),
+ .type = ObjectType::Tree});
} catch (...) {
return;
}
@@ -179,6 +181,21 @@ class LocalResponse final : public IExecutionResponse {
artifacts_ = std::move(artifacts);
dir_symlinks_ = std::move(dir_symlinks);
}
+
+ [[nodiscard]] auto ReadContent(bazel_re::Digest const& digest)
+ const noexcept -> std::optional<std::string> {
+ auto const a_digest = ArtifactDigestFactory::FromBazel(
+ storage_.GetHashFunction().GetType(), digest);
+ if (not a_digest) {
+ return std::nullopt;
+ }
+ auto const path =
+ storage_.CAS().BlobPath(*a_digest, /*is_executable=*/false);
+ if (not path) {
+ return std::nullopt;
+ }
+ return FileSystemManager::ReadFile(*path);
+ }
};
#endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_LOCAL_LOCAL_RESPONSE_HPP