From 1f4edf773b98ad04cc24f281b8cfb64255f72fb1 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Fri, 9 Sep 2022 10:46:47 +0200 Subject: Just-MR: Add repos-to-setup map Contains the logic for the checkout of all supported repositories. --- src/other_tools/just_mr/utils.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/other_tools/just_mr/utils.cpp') diff --git a/src/other_tools/just_mr/utils.cpp b/src/other_tools/just_mr/utils.cpp index 4d668bc6..f0ca606c 100644 --- a/src/other_tools/just_mr/utils.cpp +++ b/src/other_tools/just_mr/utils.cpp @@ -100,4 +100,35 @@ void AddDistfileToCAS(std::filesystem::path const& distfile, } } +// NOLINTNEXTLINE(misc-no-recursion) +auto ResolveRepo(ExpressionPtr const& repo_desc, + ExpressionPtr const& repos, + gsl::not_null*> const& seen) + -> std::optional { + if (not repo_desc->IsString()) { + return repo_desc; + } + auto desc_str = repo_desc->String(); + if (seen->contains(desc_str)) { + // cyclic dependency + return std::nullopt; + } + [[maybe_unused]] auto insert_res = seen->insert(desc_str); + return ResolveRepo(repos[desc_str]["repository"], repos, seen); +} + +auto ResolveRepo(ExpressionPtr const& repo_desc, + ExpressionPtr const& repos) noexcept + -> std::optional { + std::unordered_set seen = {}; + try { + return ResolveRepo(repo_desc, repos, &seen); + } catch (std::exception const& e) { + Logger::Log(LogLevel::Error, + "Config: while resolving dependencies: {}", + e.what()); + return std::nullopt; + } +} + } // namespace JustMR::Utils -- cgit v1.2.3