summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSascha Roloff <sascha.roloff@huawei.com>2025-04-30 17:52:26 +0200
committerSascha Roloff <sascha.roloff@huawei.com>2025-05-05 10:31:26 +0200
commit61b8b045dc710fb32b67f94d8201224f0f1da233 (patch)
tree542c2626782c2b1f5c1ae908985cb8e931b7b100 /src
parent3a9fab9787826425599400e91f43f3f9b1b6a5ec (diff)
downloadjustbuild-61b8b045dc710fb32b67f94d8201224f0f1da233.tar.gz
TreeOperationsUtils: make free-standing implementation functions member functions of the class
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/execution_engine/tree_operations/TARGETS2
-rw-r--r--src/buildtool/execution_engine/tree_operations/tree_operations_utils.cpp41
-rw-r--r--src/buildtool/execution_engine/tree_operations/tree_operations_utils.hpp37
3 files changed, 52 insertions, 28 deletions
diff --git a/src/buildtool/execution_engine/tree_operations/TARGETS b/src/buildtool/execution_engine/tree_operations/TARGETS
index 3a7e4183..0dd9e602 100644
--- a/src/buildtool/execution_engine/tree_operations/TARGETS
+++ b/src/buildtool/execution_engine/tree_operations/TARGETS
@@ -5,6 +5,7 @@
, "srcs": ["tree_operations_utils.cpp"]
, "deps":
[ ["src/buildtool/common", "common"]
+ , ["src/buildtool/crypto", "hash_function"]
, ["src/buildtool/execution_api/common", "common"]
, ["src/utils/cpp", "expected"]
]
@@ -16,7 +17,6 @@
, ["src/buildtool/common", "artifact_blob"]
, ["src/buildtool/common", "bazel_types"]
, ["src/buildtool/common", "protocol_traits"]
- , ["src/buildtool/crypto", "hash_function"]
, ["src/buildtool/file_system", "git_repo"]
, ["src/buildtool/file_system", "object_type"]
, ["src/buildtool/logging", "log_level"]
diff --git a/src/buildtool/execution_engine/tree_operations/tree_operations_utils.cpp b/src/buildtool/execution_engine/tree_operations/tree_operations_utils.cpp
index 436975f6..e1bd60b6 100644
--- a/src/buildtool/execution_engine/tree_operations/tree_operations_utils.cpp
+++ b/src/buildtool/execution_engine/tree_operations/tree_operations_utils.cpp
@@ -16,8 +16,6 @@
#include <cstddef>
#include <functional>
-#include <optional>
-#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
@@ -27,28 +25,18 @@
#include "gsl/gsl"
#include "nlohmann/json.hpp"
#include "src/buildtool/common/artifact_blob.hpp"
-#include "src/buildtool/common/artifact_digest.hpp"
#include "src/buildtool/common/artifact_digest_factory.hpp"
#include "src/buildtool/common/bazel_types.hpp"
#include "src/buildtool/common/protocol_traits.hpp"
-#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/file_system/git_repo.hpp"
#include "src/buildtool/file_system/object_type.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
#include "src/utils/cpp/hex_string.hpp"
-namespace {
-struct TreeEntry {
- Artifact::ObjectInfo info{};
- std::optional<std::string> symlink_target{};
-};
-
-using TreeEntries = std::unordered_map<std::string, TreeEntry>;
-
-[[nodiscard]] auto ParseBazelDirectory(std::string const& tree_data,
- HashFunction::Type hash_type) noexcept
- -> std::optional<TreeEntries> {
+auto TreeOperationsUtils::ParseBazelDirectory(
+ std::string const& tree_data,
+ HashFunction::Type hash_type) noexcept -> std::optional<TreeEntries> {
bazel_re::Directory bazel_directory{};
if (not bazel_directory.ParseFromString(tree_data)) {
return std::nullopt;
@@ -104,9 +92,9 @@ using TreeEntries = std::unordered_map<std::string, TreeEntry>;
return tree_entries;
}
-[[nodiscard]] auto ParseGitTree(std::string const& tree_data,
- ArtifactDigest const& tree_digest,
- HashFunction::Type hash_type) noexcept
+auto TreeOperationsUtils::ParseGitTree(std::string const& tree_data,
+ ArtifactDigest const& tree_digest,
+ HashFunction::Type hash_type) noexcept
-> std::optional<TreeEntries> {
// For a tree-overlay computation, the actual target of a symbolic
// link is not relevant. Symbolic links are just considered as
@@ -148,8 +136,9 @@ using TreeEntries = std::unordered_map<std::string, TreeEntry>;
return tree_entries;
}
-[[nodiscard]] auto ReadTree(IExecutionApi const& api,
- Artifact::ObjectInfo const& tree_info) noexcept
+auto TreeOperationsUtils::ReadTree(
+ IExecutionApi const& api,
+ Artifact::ObjectInfo const& tree_info) noexcept
-> expected<TreeEntries, std::string> {
// Fetch tree data.
auto tree_data = api.RetrieveToMemory(tree_info);
@@ -170,7 +159,7 @@ using TreeEntries = std::unordered_map<std::string, TreeEntry>;
return *tree_entries;
}
-[[nodiscard]] auto SerializeBazelDirectory(
+auto TreeOperationsUtils::SerializeBazelDirectory(
TreeEntries const& tree_entries) noexcept -> std::optional<std::string> {
// Convert tree entries to bazel directory.
bazel_re::Directory bazel_directory{};
@@ -209,8 +198,8 @@ using TreeEntries = std::unordered_map<std::string, TreeEntry>;
return bazel_directory.SerializeAsString();
}
-[[nodiscard]] auto SerializeGitTree(TreeEntries const& tree_entries) noexcept
- -> std::optional<std::string> {
+auto TreeOperationsUtils::SerializeGitTree(
+ TreeEntries const& tree_entries) noexcept -> std::optional<std::string> {
// Convert tree entries to git entries.
GitRepo::tree_entries_t git_entries{};
git_entries.reserve(tree_entries.size());
@@ -234,8 +223,8 @@ using TreeEntries = std::unordered_map<std::string, TreeEntry>;
return git_tree->second;
}
-[[nodiscard]] auto WriteTree(IExecutionApi const& api,
- TreeEntries const& tree_entries) noexcept
+auto TreeOperationsUtils::WriteTree(IExecutionApi const& api,
+ TreeEntries const& tree_entries) noexcept
-> expected<ArtifactDigest, std::string> {
// Serialize tree entries.
auto tree_data = ProtocolTraits::IsNative(api.GetHashType())
@@ -258,8 +247,6 @@ using TreeEntries = std::unordered_map<std::string, TreeEntry>;
return unexpected{fmt::format("Failed to upload tree blob")};
}
-} // namespace
-
auto TreeOperationsUtils::ComputeTreeOverlay(
IExecutionApi const& api,
Artifact::ObjectInfo const& base_tree_info,
diff --git a/src/buildtool/execution_engine/tree_operations/tree_operations_utils.hpp b/src/buildtool/execution_engine/tree_operations/tree_operations_utils.hpp
index bd818793..1315ad5c 100644
--- a/src/buildtool/execution_engine/tree_operations/tree_operations_utils.hpp
+++ b/src/buildtool/execution_engine/tree_operations/tree_operations_utils.hpp
@@ -16,15 +16,26 @@
#define INCLUDED_SRC_BUILDTOOL_EXECUTION_ENGINE_TREE_OPERATIONS_TREE_OPERATIONS_UTILS_HPP
#include <filesystem>
+#include <optional>
#include <string>
+#include <unordered_map>
#include "src/buildtool/common/artifact.hpp"
+#include "src/buildtool/common/artifact_digest.hpp"
+#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/execution_api/common/execution_api.hpp"
#include "src/utils/cpp/expected.hpp"
/// \brief Utility functions for tree operations.
class TreeOperationsUtils final {
public:
+ struct TreeEntry {
+ Artifact::ObjectInfo info{};
+ std::optional<std::string> symlink_target{};
+ };
+
+ using TreeEntries = std::unordered_map<std::string, TreeEntry>;
+
/// \brief Computes a new tree from two existing ones by overlaying
/// their contents.
/// \param api The execution API to be used.
@@ -43,6 +54,32 @@ class TreeOperationsUtils final {
bool disjoint,
std::filesystem::path const& where = std::filesystem::path{}) noexcept
-> expected<Artifact::ObjectInfo, std::string>;
+
+ [[nodiscard]] static auto ReadTree(
+ IExecutionApi const& api,
+ Artifact::ObjectInfo const& tree_info) noexcept
+ -> expected<TreeEntries, std::string>;
+
+ [[nodiscard]] static auto WriteTree(
+ IExecutionApi const& api,
+ TreeEntries const& tree_entries) noexcept
+ -> expected<ArtifactDigest, std::string>;
+
+ private:
+ [[nodiscard]] static auto ParseBazelDirectory(
+ std::string const& tree_data,
+ HashFunction::Type hash_type) noexcept -> std::optional<TreeEntries>;
+
+ [[nodiscard]] static auto ParseGitTree(
+ std::string const& tree_data,
+ ArtifactDigest const& tree_digest,
+ HashFunction::Type hash_type) noexcept -> std::optional<TreeEntries>;
+
+ [[nodiscard]] static auto SerializeBazelDirectory(
+ TreeEntries const& tree_entries) noexcept -> std::optional<std::string>;
+
+ [[nodiscard]] static auto SerializeGitTree(
+ TreeEntries const& tree_entries) noexcept -> std::optional<std::string>;
};
#endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_ENGINE_TREE_OPERATIONS_TREE_OPERATIONS_UTILS_HPP