diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-02 18:12:23 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-09 13:07:13 +0200 |
commit | 4fc124f21ea664b968ab6ee320c6ecb030292c08 (patch) | |
tree | 61ef61a4dfee5976c6e1c1da2cfe97307aa6fe08 /src/buildtool/execution_api/local/local_response.hpp | |
parent | 56f91aac0c25e6e80dbaae087227502312accee6 (diff) | |
download | justbuild-4fc124f21ea664b968ab6ee320c6ecb030292c08.tar.gz |
Use ArtifactDigest in LocalAction
Diffstat (limited to 'src/buildtool/execution_api/local/local_response.hpp')
-rw-r--r-- | src/buildtool/execution_api/local/local_response.hpp | 53 |
1 files changed, 35 insertions, 18 deletions
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 |