summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-12-18 12:08:36 +0100
committerMaksim Denisov <denisov.maksim@huawei.com>2024-12-19 16:37:59 +0100
commit17d7bbde834a6575ece9c71bdf8ae91b69bc9204 (patch)
tree47fc2d60c9c5a38506aabfd317be2e5cbc3565ac
parent0000839adc5805997d5afdda924fb6f5e45e0a90 (diff)
downloadjustbuild-17d7bbde834a6575ece9c71bdf8ae91b69bc9204.tar.gz
Implement TreeStructureRoot
-rw-r--r--src/buildtool/file_system/precomputed_root.cpp43
-rw-r--r--src/buildtool/file_system/precomputed_root.hpp32
2 files changed, 73 insertions, 2 deletions
diff --git a/src/buildtool/file_system/precomputed_root.cpp b/src/buildtool/file_system/precomputed_root.cpp
index 8e20f2f0..f62bab64 100644
--- a/src/buildtool/file_system/precomputed_root.cpp
+++ b/src/buildtool/file_system/precomputed_root.cpp
@@ -86,6 +86,25 @@ template <>
.target_name = std::string{root[3]},
.config = root[4]};
}
+
+template <>
+[[nodiscard]] auto ParseImpl<TreeStructureRoot>(nlohmann::json const& root)
+ -> expected<TreeStructureRoot, std::string> {
+ if (root.size() != TreeStructureRoot::kSchemeLength) {
+ return unexpected{
+ fmt::format("The root has a wrong number of arguments: {}\nThe "
+ "scheme requires [<scheme>, <root>]",
+ root.dump())};
+ }
+
+ if (not root[1].is_string()) {
+ return unexpected{fmt::format(
+ "The root has a wrong type of <root>. Expected a string, got {}",
+ root[1].dump())};
+ }
+
+ return TreeStructureRoot{.repository = std::string{root[1]}};
+}
} // namespace
auto ComputedRoot::operator==(ComputedRoot const& other) const noexcept
@@ -126,6 +145,27 @@ auto ComputedRoot::ComputeHash() const -> std::size_t {
return seed;
}
+auto TreeStructureRoot::operator==(
+ TreeStructureRoot const& other) const noexcept -> bool {
+ return repository == other.repository;
+}
+
+auto TreeStructureRoot::operator<(TreeStructureRoot const& other) const noexcept
+ -> bool {
+ return repository < other.repository;
+}
+
+auto TreeStructureRoot::ToString() const -> std::string {
+ return fmt::format("[\"tree structure\", {}]",
+ nlohmann::json(repository).dump());
+}
+auto TreeStructureRoot::ComputeHash() const -> std::size_t {
+ std::size_t seed{};
+ hash_combine<std::string>(&seed, kMarker);
+ hash_combine<std::string>(&seed, repository);
+ return seed;
+}
+
auto PrecomputedRoot::Parse(nlohmann::json const& root) noexcept
-> expected<PrecomputedRoot, std::string> {
if ((not root.is_array()) or root.empty()) {
@@ -137,6 +177,9 @@ auto PrecomputedRoot::Parse(nlohmann::json const& root) noexcept
if (root[0] == ComputedRoot::kMarker) {
return ParsePrecomputed<ComputedRoot>(root);
}
+ if (root[0] == TreeStructureRoot::kMarker) {
+ return ParsePrecomputed<TreeStructureRoot>(root);
+ }
return unexpected{
fmt::format("Unknown precomputed type of the root {}", root.dump())};
diff --git a/src/buildtool/file_system/precomputed_root.hpp b/src/buildtool/file_system/precomputed_root.hpp
index 8261b94c..6df59bc9 100644
--- a/src/buildtool/file_system/precomputed_root.hpp
+++ b/src/buildtool/file_system/precomputed_root.hpp
@@ -42,6 +42,22 @@ struct ComputedRoot final {
[[nodiscard]] auto ComputeHash() const -> std::size_t;
};
+struct TreeStructureRoot final {
+ static constexpr auto kMarker = "tree structure";
+ static constexpr std::size_t kSchemeLength = 2;
+
+ std::string repository;
+
+ [[nodiscard]] auto operator==(TreeStructureRoot const& other) const noexcept
+ -> bool;
+
+ [[nodiscard]] auto operator<(TreeStructureRoot const& other) const noexcept
+ -> bool;
+
+ [[nodiscard]] auto ToString() const -> std::string;
+ [[nodiscard]] auto ComputeHash() const -> std::size_t;
+};
+
namespace std {
template <typename>
struct hash;
@@ -51,7 +67,7 @@ struct hash;
/// real build starts.
class PrecomputedRoot final {
public:
- using root_t = std::variant<ComputedRoot>;
+ using root_t = std::variant<ComputedRoot, TreeStructureRoot>;
explicit PrecomputedRoot() : PrecomputedRoot(ComputedRoot{}) {}
explicit PrecomputedRoot(root_t root)
: root_{std::move(root)}, hash_{ComputeHash(root_)} {}
@@ -61,7 +77,8 @@ class PrecomputedRoot final {
[[nodiscard]] static auto IsPrecomputedMarker(
std::string const& marker) noexcept -> bool {
- return marker == ComputedRoot::kMarker;
+ return marker == ComputedRoot::kMarker or
+ marker == TreeStructureRoot::kMarker;
}
[[nodiscard]] auto operator==(PrecomputedRoot const& other) const noexcept
@@ -86,6 +103,17 @@ class PrecomputedRoot final {
return std::nullopt;
}
+ [[nodiscard]] auto IsTreeStructure() const noexcept -> bool {
+ return std::holds_alternative<TreeStructureRoot>(root_);
+ }
+ [[nodiscard]] auto AsTreeStructure() const noexcept
+ -> std::optional<TreeStructureRoot> {
+ if (auto const* root = std::get_if<TreeStructureRoot>(&root_)) {
+ return *root;
+ }
+ return std::nullopt;
+ }
+
private:
root_t root_;
std::size_t hash_;