diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2022-02-22 17:03:21 +0100 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2022-02-22 17:03:21 +0100 |
commit | 619def44c1cca9f3cdf63544d5f24f2c7a7d9b77 (patch) | |
tree | 01868de723cb82c86842f33743fa7b14e24c1fa3 /src/buildtool/execution_api/remote/bazel/bazel_response.hpp | |
download | justbuild-619def44c1cca9f3cdf63544d5f24f2c7a7d9b77.tar.gz |
Initial self-hosting commit
This is the initial version of our tool that is able to
build itself. In can be bootstrapped by
./bin/bootstrap.py
Co-authored-by: Oliver Reiche <oliver.reiche@huawei.com>
Co-authored-by: Victor Moreno <victor.moreno1@huawei.com>
Diffstat (limited to 'src/buildtool/execution_api/remote/bazel/bazel_response.hpp')
-rw-r--r-- | src/buildtool/execution_api/remote/bazel/bazel_response.hpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/buildtool/execution_api/remote/bazel/bazel_response.hpp b/src/buildtool/execution_api/remote/bazel/bazel_response.hpp new file mode 100644 index 00000000..778efa0a --- /dev/null +++ b/src/buildtool/execution_api/remote/bazel/bazel_response.hpp @@ -0,0 +1,77 @@ +#ifndef INCLUDED_SRC_BUILDTOOL_EXECUTION_API_REMOTE_BAZEL_BAZEL_RESPONSE_HPP +#define INCLUDED_SRC_BUILDTOOL_EXECUTION_API_REMOTE_BAZEL_BAZEL_RESPONSE_HPP + +#include <string> +#include <vector> + +#include "src/buildtool/execution_api/common/execution_api.hpp" +#include "src/buildtool/execution_api/remote/bazel/bazel_execution_client.hpp" +#include "src/buildtool/execution_api/remote/bazel/bazel_network.hpp" + +class BazelAction; + +/// \brief Bazel implementation of the abstract Execution Response. +/// Access Bazel execution output data and obtain a Bazel Artifact. +class BazelResponse final : public IExecutionResponse { + friend class BazelAction; + + public: + auto Status() const noexcept -> StatusCode final { + return output_.status.ok() ? StatusCode::Success : StatusCode::Failed; + } + auto HasStdErr() const noexcept -> bool final { + return IsDigestNotEmpty(output_.action_result.stderr_digest()); + } + auto HasStdOut() const noexcept -> bool final { + return IsDigestNotEmpty(output_.action_result.stdout_digest()); + } + auto StdErr() noexcept -> std::string final { + return ReadStringBlob(output_.action_result.stderr_digest()); + } + auto StdOut() noexcept -> std::string final { + return ReadStringBlob(output_.action_result.stdout_digest()); + } + auto ExitCode() const noexcept -> int final { + return output_.action_result.exit_code(); + } + auto IsCached() const noexcept -> bool final { + return output_.cached_result; + }; + + auto ActionDigest() const noexcept -> std::string final { + return action_id_; + } + + auto Artifacts() const noexcept -> ArtifactInfos final; + + private: + std::string action_id_{}; + std::shared_ptr<BazelNetwork> const network_{}; + std::shared_ptr<LocalTreeMap> const tree_map_{}; + BazelExecutionClient::ExecutionOutput output_{}; + + BazelResponse(std::string action_id, + std::shared_ptr<BazelNetwork> network, + std::shared_ptr<LocalTreeMap> tree_map, + BazelExecutionClient::ExecutionOutput output) + : action_id_{std::move(action_id)}, + network_{std::move(network)}, + tree_map_{std::move(tree_map)}, + output_{std::move(output)} {} + + [[nodiscard]] auto ReadStringBlob(bazel_re::Digest const& id) noexcept + -> std::string; + + [[nodiscard]] static auto IsDigestNotEmpty(bazel_re::Digest const& id) + -> bool { + return id.size_bytes() != 0; + } + + [[nodiscard]] auto UploadTreeMessageDirectories( + bazel_re::Tree const& tree) const -> std::optional<ArtifactDigest>; + + [[nodiscard]] auto ProcessDirectoryMessage(bazel_re::Directory const& dir) + const noexcept -> std::optional<BazelBlob>; +}; + +#endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_REMOTE_BAZEL_BAZEL_RESPONSE_HPP |