summaryrefslogtreecommitdiff
path: root/src/buildtool/execution_api/bazel_msg/bazel_blob.hpp
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2022-02-22 17:03:21 +0100
committerKlaus Aehlig <klaus.aehlig@huawei.com>2022-02-22 17:03:21 +0100
commit619def44c1cca9f3cdf63544d5f24f2c7a7d9b77 (patch)
tree01868de723cb82c86842f33743fa7b14e24c1fa3 /src/buildtool/execution_api/bazel_msg/bazel_blob.hpp
downloadjustbuild-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/bazel_msg/bazel_blob.hpp')
-rw-r--r--src/buildtool/execution_api/bazel_msg/bazel_blob.hpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/buildtool/execution_api/bazel_msg/bazel_blob.hpp b/src/buildtool/execution_api/bazel_msg/bazel_blob.hpp
new file mode 100644
index 00000000..115c4018
--- /dev/null
+++ b/src/buildtool/execution_api/bazel_msg/bazel_blob.hpp
@@ -0,0 +1,31 @@
+#ifndef INCLUDED_SRC_BUILDTOOL_EXECUTION_API_BAZEL_MSG_BAZEL_BLOB_HPP
+#define INCLUDED_SRC_BUILDTOOL_EXECUTION_API_BAZEL_MSG_BAZEL_BLOB_HPP
+
+#include <filesystem>
+#include <memory>
+#include <optional>
+#include <string>
+
+#include "src/buildtool/common/artifact_digest.hpp"
+#include "src/buildtool/common/bazel_types.hpp"
+#include "src/buildtool/file_system/file_system_manager.hpp"
+
+struct BazelBlob {
+ BazelBlob(bazel_re::Digest mydigest, std::string mydata)
+ : digest{std::move(mydigest)}, data{std::move(mydata)} {}
+
+ bazel_re::Digest digest{};
+ std::string data{};
+};
+
+[[nodiscard]] static inline auto CreateBlobFromFile(
+ std::filesystem::path const& file_path) noexcept
+ -> std::optional<BazelBlob> {
+ auto const content = FileSystemManager::ReadFile(file_path);
+ if (not content.has_value()) {
+ return std::nullopt;
+ }
+ return BazelBlob{ArtifactDigest::Create(*content), *content};
+}
+
+#endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_BAZEL_MSG_BAZEL_BLOB_HPP