diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2025-02-18 09:50:34 +0100 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2025-02-19 17:50:30 +0100 |
commit | 57edc4cbc764a9815f4990c54111e6ee9bcc8081 (patch) | |
tree | 994fce8baf80fcb76e72fd18004790ed463ca44e | |
parent | 3a0392dacdbfa4cfc84ff2cc96086ec6b18ca939 (diff) | |
download | justbuild-57edc4cbc764a9815f4990c54111e6ee9bcc8081.tar.gz |
{MR}GitApi: Drop inheritance
-rw-r--r-- | src/buildtool/execution_api/git/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/execution_api/git/git_api.hpp | 59 | ||||
-rw-r--r-- | src/buildtool/execution_api/serve/TARGETS | 2 | ||||
-rw-r--r-- | src/buildtool/execution_api/serve/mr_git_api.cpp | 6 | ||||
-rw-r--r-- | src/buildtool/execution_api/serve/mr_git_api.hpp | 97 | ||||
-rw-r--r-- | src/buildtool/serve_api/remote/serve_api.cpp | 2 |
6 files changed, 14 insertions, 153 deletions
diff --git a/src/buildtool/execution_api/git/TARGETS b/src/buildtool/execution_api/git/TARGETS index 3b706715..adc3c908 100644 --- a/src/buildtool/execution_api/git/TARGETS +++ b/src/buildtool/execution_api/git/TARGETS @@ -12,7 +12,6 @@ , ["src/buildtool/execution_api/common", "artifact_blob"] , ["src/buildtool/execution_api/common", "common"] , ["src/buildtool/execution_api/common", "common_api"] - , ["src/buildtool/execution_engine/dag", "dag"] , ["src/buildtool/file_system", "file_system_manager"] , ["src/buildtool/file_system", "git_tree"] , ["src/buildtool/file_system", "object_type"] diff --git a/src/buildtool/execution_api/git/git_api.hpp b/src/buildtool/execution_api/git/git_api.hpp index 3be2b8fd..22834007 100644 --- a/src/buildtool/execution_api/git/git_api.hpp +++ b/src/buildtool/execution_api/git/git_api.hpp @@ -19,7 +19,6 @@ #include <cstdio> #include <filesystem> #include <functional> -#include <map> #include <memory> #include <optional> #include <string> @@ -37,9 +36,7 @@ #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/common/artifact_blob.hpp" #include "src/buildtool/execution_api/common/common_api.hpp" -#include "src/buildtool/execution_api/common/execution_action.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" -#include "src/buildtool/execution_engine/dag/dag.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/file_system/git_tree.hpp" #include "src/buildtool/file_system/object_type.hpp" @@ -47,31 +44,15 @@ #include "src/buildtool/logging/logger.hpp" #include "src/utils/cpp/expected.hpp" -/// \brief API for local execution. -class GitApi final : public IExecutionApi { +class GitApi final { public: - GitApi() = delete; explicit GitApi(gsl::not_null<const RepositoryConfig*> const& repo_config) : repo_config_{repo_config} {} - [[nodiscard]] auto CreateAction( - ArtifactDigest const& /*root_digest*/, - std::vector<std::string> const& /*command*/, - std::string const& /*cwd*/, - std::vector<std::string> const& /*output_files*/, - std::vector<std::string> const& /*output_dirs*/, - std::map<std::string, std::string> const& /*env_vars*/, - std::map<std::string, std::string> const& /*properties*/) const noexcept - -> IExecutionAction::Ptr final { - // Execution not supported from git cas - return nullptr; - } - // NOLINTNEXTLINE(google-default-arguments) [[nodiscard]] auto RetrieveToPaths( std::vector<Artifact::ObjectInfo> const& artifacts_info, - std::vector<std::filesystem::path> const& output_paths, - IExecutionApi const* /*alternative*/ = nullptr) const noexcept - -> bool override { + std::vector<std::filesystem::path> const& output_paths) const noexcept + -> bool { if (artifacts_info.size() != output_paths.size()) { Logger::Log(LogLevel::Error, "different number of digests and output paths."); @@ -118,13 +99,10 @@ class GitApi final : public IExecutionApi { return true; } - // NOLINTNEXTLINE(google-default-arguments) [[nodiscard]] auto RetrieveToFds( std::vector<Artifact::ObjectInfo> const& artifacts_info, std::vector<int> const& fds, - bool raw_tree, - IExecutionApi const* /*alternative*/ = nullptr) const noexcept - -> bool override { + bool raw_tree) const noexcept -> bool { if (artifacts_info.size() != fds.size()) { Logger::Log(LogLevel::Error, "different number of digests and file descriptors."); @@ -190,12 +168,7 @@ class GitApi final : public IExecutionApi { [[nodiscard]] auto RetrieveToCas( std::vector<Artifact::ObjectInfo> const& artifacts_info, - IExecutionApi const& api) const noexcept -> bool override { - // Return immediately if target CAS is this CAS - if (this == &api) { - return true; - } - + IExecutionApi const& api) const noexcept -> bool { // Determine missing artifacts in other CAS. auto missing_artifacts_info = GetMissingArtifactsInfo<Artifact::ObjectInfo>( @@ -303,35 +276,19 @@ class GitApi final : public IExecutionApi { [[nodiscard]] auto RetrieveToMemory( Artifact::ObjectInfo const& artifact_info) const noexcept - -> std::optional<std::string> override { + -> std::optional<std::string> { return repo_config_->ReadBlobFromGitCAS(artifact_info.digest.hash()); } - /// NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] auto Upload(std::unordered_set<ArtifactBlob>&& /*blobs*/, - bool /*skip_find_missing*/ = false) const noexcept - -> bool override { - // Upload to git cas not supported - return false; - } - - [[nodiscard]] auto UploadTree( - std::vector<DependencyGraph::NamedArtifactNodePtr> const& - /*artifacts*/) const noexcept - -> std::optional<ArtifactDigest> override { - // Upload to git cas not supported - return std::nullopt; - } - [[nodiscard]] auto IsAvailable(ArtifactDigest const& digest) const noexcept - -> bool override { + -> bool { return repo_config_->ReadBlobFromGitCAS(digest.hash(), LogLevel::Trace) .has_value(); } [[nodiscard]] auto GetMissingDigests( std::unordered_set<ArtifactDigest> const& digests) const noexcept - -> std::unordered_set<ArtifactDigest> override { + -> std::unordered_set<ArtifactDigest> { std::unordered_set<ArtifactDigest> result; result.reserve(digests.size()); for (auto const& digest : digests) { diff --git a/src/buildtool/execution_api/serve/TARGETS b/src/buildtool/execution_api/serve/TARGETS index 7a15a1c7..7fb0a5bf 100644 --- a/src/buildtool/execution_api/serve/TARGETS +++ b/src/buildtool/execution_api/serve/TARGETS @@ -7,9 +7,7 @@ [ ["@", "gsl", "", "gsl"] , ["src/buildtool/common", "common"] , ["src/buildtool/common", "config"] - , ["src/buildtool/execution_api/common", "artifact_blob"] , ["src/buildtool/execution_api/common", "common"] - , ["src/buildtool/execution_engine/dag", "dag"] , ["src/buildtool/storage", "config"] ] , "stage": ["src", "buildtool", "execution_api", "serve"] diff --git a/src/buildtool/execution_api/serve/mr_git_api.cpp b/src/buildtool/execution_api/serve/mr_git_api.cpp index 9a9f7ec3..723eb351 100644 --- a/src/buildtool/execution_api/serve/mr_git_api.cpp +++ b/src/buildtool/execution_api/serve/mr_git_api.cpp @@ -14,6 +14,7 @@ #include "src/buildtool/execution_api/serve/mr_git_api.hpp" +#include <string> #include <utility> #include "src/buildtool/execution_api/git/git_api.hpp" @@ -35,11 +36,6 @@ MRGitApi::MRGitApi( auto MRGitApi::RetrieveToCas( std::vector<Artifact::ObjectInfo> const& artifacts_info, IExecutionApi const& api) const noexcept -> bool { - // Return immediately if target CAS is this CAS - if (this == &api) { - return true; - } - // in native mode: dispatch to regular GitApi if (compat_storage_config_ == nullptr) { GitApi const git_api{repo_config_}; diff --git a/src/buildtool/execution_api/serve/mr_git_api.hpp b/src/buildtool/execution_api/serve/mr_git_api.hpp index 6b5292c8..f78e1530 100644 --- a/src/buildtool/execution_api/serve/mr_git_api.hpp +++ b/src/buildtool/execution_api/serve/mr_git_api.hpp @@ -15,72 +15,23 @@ #ifndef INCLUDED_SRC_BUILDTOOL_EXECUTION_API_SERVE_MR_GIT_API_HPP #define INCLUDED_SRC_BUILDTOOL_EXECUTION_API_SERVE_MR_GIT_API_HPP -#include <filesystem> -#include <functional> -#include <map> -#include <optional> -#include <string> -#include <unordered_set> #include <vector> #include "gsl/gsl" #include "src/buildtool/common/artifact.hpp" -#include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/repository_config.hpp" -#include "src/buildtool/execution_api/common/artifact_blob.hpp" -#include "src/buildtool/execution_api/common/execution_action.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" -#include "src/buildtool/execution_engine/dag/dag.hpp" #include "src/buildtool/storage/config.hpp" -/// \brief Multi-repo-specific implementation of the abstract Execution API. -/// Handles interaction between the Git CAS and another api, irrespective of the -/// remote-execution protocol used. This instance cannot create actions or store -/// anything to the Git CAS, but has access to local storages. -class MRGitApi final : public IExecutionApi { +/// \brief Handles interaction between the Git CAS and another api, irrespective +/// of the remote-execution protocol used. +class MRGitApi final { public: MRGitApi(gsl::not_null<RepositoryConfig const*> const& repo_config, gsl::not_null<StorageConfig const*> const& native_storage_config, StorageConfig const* compatible_storage_config = nullptr, IExecutionApi const* compatible_local_api = nullptr) noexcept; - /// \brief Not supported. - [[nodiscard]] auto CreateAction( - ArtifactDigest const& /*root_digest*/, - std::vector<std::string> const& /*command*/, - std::string const& /*cwd*/, - std::vector<std::string> const& /*output_files*/, - std::vector<std::string> const& /*output_dirs*/, - std::map<std::string, std::string> const& /*env_vars*/, - std::map<std::string, std::string> const& /*properties*/) const noexcept - -> IExecutionAction::Ptr final { - // Execution not supported. - return nullptr; - } - - /// \brief Not supported. - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] auto RetrieveToPaths( - std::vector<Artifact::ObjectInfo> const& /*artifacts_info*/, - std::vector<std::filesystem::path> const& /*output_paths*/, - IExecutionApi const* /*alternative*/ = nullptr) const noexcept - -> bool final { - // Retrieval to paths not suported. - return false; - } - - /// \brief Not supported. - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] auto RetrieveToFds( - std::vector<Artifact::ObjectInfo> const& /*artifacts_info*/, - std::vector<int> const& /*fds*/, - bool /*raw_tree*/, - IExecutionApi const* /*alternative*/ = nullptr) const noexcept - -> bool final { - // Retrieval to file descriptors not supported. - return false; - } - /// \brief Passes artifacts from Git CAS to specified (remote) api. In /// compatible mode, it must rehash the native digests to be able to upload /// to a compatible remote. Expects native digests. @@ -88,47 +39,7 @@ class MRGitApi final : public IExecutionApi { /// same digest type. [[nodiscard]] auto RetrieveToCas( std::vector<Artifact::ObjectInfo> const& artifacts_info, - IExecutionApi const& api) const noexcept -> bool final; - - /// \brief Not supported. - [[nodiscard]] auto RetrieveToMemory( - Artifact::ObjectInfo const& /*artifact_info*/) const noexcept - -> std::optional<std::string> final { - // Retrieval to memory not supported. - return std::nullopt; - } - - /// \brief Not supported. - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] auto Upload(std::unordered_set<ArtifactBlob>&& /*blobs*/, - bool /*skip_find_missing*/ = false) const noexcept - -> bool final { - // Upload not suppoorted. - return false; - } - - /// \brief Not supported. - [[nodiscard]] auto UploadTree( - std::vector<DependencyGraph::NamedArtifactNodePtr> const& /*artifacts*/) - const noexcept -> std::optional<ArtifactDigest> final { - // Upload tree not supported. - return std::nullopt; - } - - /// \brief Not supported. - [[nodiscard]] auto IsAvailable( - ArtifactDigest const& /*digest*/) const noexcept -> bool final { - // Not supported. - return false; - } - - /// \brief Not implemented. - [[nodiscard]] auto GetMissingDigests( - std::unordered_set<ArtifactDigest> const& /*digests*/) const noexcept - -> std::unordered_set<ArtifactDigest> final { - // Not supported. - return {}; - } + IExecutionApi const& api) const noexcept -> bool; private: gsl::not_null<const RepositoryConfig*> repo_config_; diff --git a/src/buildtool/serve_api/remote/serve_api.cpp b/src/buildtool/serve_api/remote/serve_api.cpp index cb0ea7ac..6eeb85a0 100644 --- a/src/buildtool/serve_api/remote/serve_api.cpp +++ b/src/buildtool/serve_api/remote/serve_api.cpp @@ -61,7 +61,7 @@ auto ServeApi::UploadTree(ArtifactDigest const& tree, native_storage_config.emplace(*config); } - std::shared_ptr<IExecutionApi> git_api; + std::shared_ptr<MRGitApi> git_api; if (with_rehashing) { git_api = std::make_shared<MRGitApi>( &repo, &*native_storage_config, &storage_config_, &*apis_.local); |