From fea52bc9439759779e3c276849372fc812afe7a9 Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Thu, 16 Jan 2025 09:49:11 +0100 Subject: JustMr: Support absent tree structure roots --- src/other_tools/utils/parse_precomputed_root.cpp | 35 +++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/other_tools/utils/parse_precomputed_root.cpp') diff --git a/src/other_tools/utils/parse_precomputed_root.cpp b/src/other_tools/utils/parse_precomputed_root.cpp index 7b9ef519..f30316e6 100644 --- a/src/other_tools/utils/parse_precomputed_root.cpp +++ b/src/other_tools/utils/parse_precomputed_root.cpp @@ -21,6 +21,34 @@ #include "src/buildtool/build_engine/expression/expression.hpp" namespace { +[[nodiscard]] auto ParseAbsent(ExpressionPtr const& repository) + -> expected { + auto const pragma = repository->Get("pragma", Expression::none_t{}); + if (not pragma.IsNotNull()) { + // Missing "pragma", absent == false + return false; + } + + if (not pragma->IsMap()) { + return unexpected{fmt::format( + "Key \"pragma\", if given, should be a map, but found {}", + pragma->ToString())}; + } + + auto const is_absent = pragma->Get("absent", Expression::none_t{}); + if (not is_absent.IsNotNull()) { + // "pragma" doesn't contain "absent", absent == false + return false; + } + + if (not is_absent->IsBool()) { + return unexpected{fmt::format( + "Expected pragma \"absent\" to be boolean, but found {}", + is_absent->ToString())}; + } + return is_absent->Bool(); +} + [[nodiscard]] auto ParseComputedRoot(ExpressionPtr const& repository) -> expected { auto const repo = repository->Get("repo", Expression::none_t{}); @@ -67,7 +95,12 @@ namespace { if (not repo.IsNotNull()) { return unexpected{"Mandatory key \"repo\" is missing"}; } - return TreeStructureRoot{.repository = repo->String(), .absent = false}; + + auto absent = ParseAbsent(repository); + if (not absent.has_value()) { + return unexpected{std::move(absent).error()}; + } + return TreeStructureRoot{.repository = repo->String(), .absent = *absent}; } } // namespace -- cgit v1.2.3