1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
// 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_COMMON_EXECUTION_APIHPP
#define INCLUDED_SRC_BUILDTOOL_EXECUTION_API_COMMON_EXECUTION_APIHPP
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "gsl-lite/gsl-lite.hpp"
#include "src/buildtool/common/artifact.hpp" // Artifact::ObjectInfo
#include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp"
#include "src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp"
#include "src/buildtool/execution_api/common/execution_action.hpp"
/// \brief Abstract remote execution API
/// Can be used to create actions.
class IExecutionApi {
public:
using Ptr = std::unique_ptr<IExecutionApi>;
IExecutionApi() = default;
IExecutionApi(IExecutionApi const&) = delete;
IExecutionApi(IExecutionApi&&) = default;
auto operator=(IExecutionApi const&) -> IExecutionApi& = delete;
auto operator=(IExecutionApi&&) -> IExecutionApi& = default;
virtual ~IExecutionApi() = default;
/// \brief Create a new action.
/// \param[in] root_digest Digest of the build root.
/// \param[in] command Command as argv vector
/// \param[in] output_files List of paths to output files.
/// \param[in] output_dirs List of paths to output directories.
/// \param[in] env_vars The environment variables to set.
/// \param[in] properties Platform properties to set.
/// \returns The new action.
[[nodiscard]] virtual auto CreateAction(
ArtifactDigest const& root_digest,
std::vector<std::string> const& command,
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) noexcept
-> IExecutionAction::Ptr = 0;
/// \brief Retrieve artifacts from CAS and store to specified paths.
/// Tree artifacts are resolved its containing file artifacts are
/// recursively retrieved.
[[nodiscard]] virtual auto RetrieveToPaths(
std::vector<Artifact::ObjectInfo> const& artifacts_info,
std::vector<std::filesystem::path> const& output_paths) noexcept
-> bool = 0;
/// \brief Retrieve artifacts from CAS and write to file descriptors.
/// Tree artifacts are not resolved and instead the tree object will be
/// pretty-printed before writing to fd. If `raw_tree` is set, pretty
/// printing will be omitted and the raw tree object will be written
/// instead.
[[nodiscard]] virtual auto RetrieveToFds(
std::vector<Artifact::ObjectInfo> const& artifacts_info,
std::vector<int> const& fds,
bool raw_tree) noexcept -> bool = 0;
/// \brief Synchronization of artifacts between two CASes. Retrieves
/// artifacts from one CAS and writes to another CAS. Tree artifacts are
/// resolved and its containing file artifacts are recursively retrieved.
[[nodiscard]] virtual auto RetrieveToCas(
std::vector<Artifact::ObjectInfo> const& artifacts_info,
gsl::not_null<IExecutionApi*> const& api) noexcept -> bool = 0;
/// \brief Upload blobs to CAS. Uploads only the blobs that are not yet
/// available in CAS, unless `skip_find_missing` is specified.
/// \param blobs Container of blobs to upload.
/// \param skip_find_missing Skip finding missing blobs, just upload all.
/// NOLINTNEXTLINE(google-default-arguments)
[[nodiscard]] virtual auto Upload(BlobContainer const& blobs,
bool skip_find_missing = false) noexcept
-> bool = 0;
[[nodiscard]] virtual auto UploadTree(
std::vector<DependencyGraph::NamedArtifactNodePtr> const&
artifacts) noexcept -> std::optional<ArtifactDigest> = 0;
[[nodiscard]] virtual auto IsAvailable(
ArtifactDigest const& digest) const noexcept -> bool = 0;
[[nodiscard]] virtual auto IsAvailable(
std::vector<ArtifactDigest> const& digests) const noexcept
-> std::vector<ArtifactDigest> = 0;
};
#endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_COMMON_EXECUTION_APIHPP
|