diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2022-07-14 17:56:02 +0200 |
---|---|---|
committer | Sascha Roloff <sascha.roloff@huawei.com> | 2022-08-05 14:41:31 +0200 |
commit | c0422f390f9f30b7cc470a814e209bedc7e87f1a (patch) | |
tree | 2895eba2f719792e0b5216f33e1462017462b332 | |
parent | e9037a921755b385b274ae6b05b79c49958affdc (diff) | |
download | justbuild-c0422f390f9f30b7cc470a814e209bedc7e87f1a.tar.gz |
BazelMsgFactory: Support dumping Git tree to string
-rw-r--r-- | src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp | 23 | ||||
-rw-r--r-- | src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp | 5 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp b/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp index ead45f6e..8d4d06c7 100644 --- a/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp +++ b/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp @@ -680,3 +680,26 @@ auto BazelMsgFactory::DirectoryToString(bazel_re::Directory const& dir) noexcept return std::nullopt; } } + +auto BazelMsgFactory::GitTreeToString( + GitCAS::tree_entries_t const& entries) noexcept + -> std::optional<std::string> { + auto json = nlohmann::json::object(); + try { + if (not BazelMsgFactory::ReadObjectInfosFromGitTree( + entries, [&json](auto path, auto info) { + json[path.string()] = info.ToString(/*size_unknown=*/true); + return true; + })) { + Logger::Log(LogLevel::Error, + "reading object infos from Directory failed"); + return std::nullopt; + } + return json.dump(2) + "\n"; + } catch (std::exception const& ex) { + Logger::Log(LogLevel::Error, + "dumping Directory to string failed with:\n{}", + ex.what()); + return std::nullopt; + } +} diff --git a/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp b/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp index 5044a646..06d981eb 100644 --- a/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp +++ b/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp @@ -113,6 +113,11 @@ class BazelMsgFactory { [[nodiscard]] static auto DirectoryToString( bazel_re::Directory const& dir) noexcept -> std::optional<std::string>; + /// \brief Create descriptive string from Git tree entries. + [[nodiscard]] static auto GitTreeToString( + GitCAS::tree_entries_t const& entries) noexcept + -> std::optional<std::string>; + /// \brief Create message vector from std::map. /// \param[in] input map /// \tparam T protobuf message type. It must be a name-value |