diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2022-09-09 10:46:47 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2022-12-21 14:59:04 +0100 |
commit | 1f4edf773b98ad04cc24f281b8cfb64255f72fb1 (patch) | |
tree | a2a0c01660c78fe3e73dc5697a0e70ec69a0d161 /src/other_tools/just_mr/utils.cpp | |
parent | 7c6e2fa5f90259a331b24d9b4f17ce195086af8b (diff) | |
download | justbuild-1f4edf773b98ad04cc24f281b8cfb64255f72fb1.tar.gz |
Just-MR: Add repos-to-setup map
Contains the logic for the checkout of all supported repositories.
Diffstat (limited to 'src/other_tools/just_mr/utils.cpp')
-rw-r--r-- | src/other_tools/just_mr/utils.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
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<std::unordered_set<std::string>*> const& seen) + -> std::optional<ExpressionPtr> { + 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<ExpressionPtr> { + std::unordered_set<std::string> 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 |