// Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef INCLUDED_SRC_BUILDTOOL_EXECUTION_API_REMOTE_BAZEL_BAZEL_API_HPP #define INCLUDED_SRC_BUILDTOOL_EXECUTION_API_REMOTE_BAZEL_BAZEL_API_HPP #include #include #include #include #include #include #include #include #include "gsl/gsl" #include "src/buildtool/auth/authentication.hpp" #include "src/buildtool/common/artifact.hpp" #include "src/buildtool/common/artifact_blob.hpp" #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/remote/port.hpp" #include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/bazel_msg/execution_config.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/utils/cpp/tmp_dir.hpp" // forward declaration for actual implementations class BazelNetwork; /// \brief Bazel implementation of the abstract Execution API. class BazelApi final : public IExecutionApi { public: BazelApi(std::string const& instance_name, std::string const& host, Port port, gsl::not_null const& auth, gsl::not_null const& retry_config, ExecutionConfiguration const& exec_config, HashFunction hash_function, TmpDir::Ptr temp_space) noexcept; BazelApi(BazelApi const&) = delete; BazelApi(BazelApi&& other) noexcept; auto operator=(BazelApi const&) -> BazelApi& = delete; auto operator=(BazelApi&&) -> BazelApi& = delete; ~BazelApi() final; // NOLINTNEXTLINE(google-default-arguments) [[nodiscard]] auto CreateAction( ArtifactDigest const& root_digest, std::vector const& command, std::string const& cwd, std::vector const& output_files, std::vector const& output_dirs, std::map const& env_vars, std::map const& properties, bool force_legacy = false) const noexcept -> IExecutionAction::Ptr final; // NOLINTNEXTLINE(google-default-arguments) [[nodiscard]] auto RetrieveToPaths( std::vector const& artifacts_info, std::vector const& output_paths, IExecutionApi const* alternative = nullptr) const noexcept -> bool final; // NOLINTNEXTLINE(google-default-arguments) [[nodiscard]] auto RetrieveToFds( std::vector const& artifacts_info, std::vector const& fds, bool raw_tree, IExecutionApi const* alternative = nullptr) const noexcept -> bool final; [[nodiscard]] auto ParallelRetrieveToCas( std::vector const& artifacts_info, IExecutionApi const& api, std::size_t jobs, bool use_blob_splitting) const noexcept -> bool final; [[nodiscard]] auto RetrieveToCas( std::vector const& artifacts_info, IExecutionApi const& api) const noexcept -> bool final; [[nodiscard]] auto Upload(std::unordered_set&& blobs, bool skip_find_missing) const noexcept -> bool final; [[nodiscard]] auto UploadTree( std::vector const& artifacts) const noexcept -> std::optional final; [[nodiscard]] auto IsAvailable(ArtifactDigest const& digest) const noexcept -> bool final; [[nodiscard]] auto GetMissingDigests( std::unordered_set const& digests) const noexcept -> std::unordered_set final; [[nodiscard]] auto RetrieveToMemory( Artifact::ObjectInfo const& artifact_info) const noexcept -> std::optional final; [[nodiscard]] auto SplitBlob(ArtifactDigest const& blob_digest) const noexcept -> std::optional> final; [[nodiscard]] auto BlobSplitSupport() const noexcept -> bool final; [[nodiscard]] auto SpliceBlob( ArtifactDigest const& blob_digest, std::vector const& chunk_digests) const noexcept -> std::optional final; [[nodiscard]] auto BlobSpliceSupport() const noexcept -> bool final; [[nodiscard]] auto GetHashType() const noexcept -> HashFunction::Type final; [[nodiscard]] auto GetTempSpace() const noexcept -> TmpDir::Ptr final; private: std::shared_ptr network_; [[nodiscard]] auto ParallelRetrieveToCasWithCache( std::vector const& all_artifacts_info, IExecutionApi const& api, std::size_t jobs, bool use_blob_splitting, gsl::not_null*> done) const noexcept -> bool; }; #endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_REMOTE_BAZEL_BAZEL_API_HPP