From 24cc2e9fbd536ebc87ee56a2fa01096368e143ce Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Mon, 2 Jun 2025 11:11:39 +0200 Subject: just-mr: Warn for non-content-fixed repo reached from absent main If the main repository is marked absent, warn if during the dependency closure computation any non-content-fixed repositories are reached, i.e., any "file"-type repositories that are neither implicitly nor explicitly marked "to_git". Also warn if the main repository itself is marked absent but is not content fixed. Add small test checking that the new warning is produced. --- src/other_tools/just_mr/setup_utils.cpp | 63 +++++++++++++++++++++++++++++++++ src/other_tools/just_mr/setup_utils.hpp | 2 ++ 2 files changed, 65 insertions(+) (limited to 'src') diff --git a/src/other_tools/just_mr/setup_utils.cpp b/src/other_tools/just_mr/setup_utils.cpp index 07498441..864aa684 100644 --- a/src/other_tools/just_mr/setup_utils.cpp +++ b/src/other_tools/just_mr/setup_utils.cpp @@ -80,6 +80,57 @@ void WarnUnknownKeys(std::string const& name, ExpressionPtr const& repo_def) { return std::nullopt; } +[[nodiscard]] auto IsAbsent(ExpressionPtr const& repo_def) -> bool { + if (repo_def.IsNotNull() and repo_def->IsMap()) { + if (auto repo = repo_def->Get("repository", Expression::none_t{}); + repo.IsNotNull() and repo->IsMap()) { + if (auto pragma = repo->Get("pragma", Expression::none_t{}); + pragma.IsNotNull() and pragma->IsMap()) { + auto absent = pragma->Get("absent", Expression::none_t{}); + return absent.IsNotNull() and absent->IsBool() and + absent->Bool(); + } + } + } + return false; +} + +[[nodiscard]] auto IsNotContentFixed(ExpressionPtr const& repo_def) -> bool { + if (not repo_def.IsNotNull() or not repo_def->IsMap()) { + return false; + } + if (auto repo = repo_def->Get("repository", Expression::none_t{}); + repo.IsNotNull() and repo->IsMap()) { + // Check if type == "file" + auto type = repo->Get("type", Expression::none_t{}); + if (not type.IsNotNull() or not type->IsString()) { + return false; + } + if (type->String() == "file") { + auto pragma = repo->Get("pragma", Expression::none_t{}); + if (not pragma.IsNotNull() or not pragma->IsMap()) { + return true; // not content-fixed if not to_git + } + // Check for explicit to_git == true + if (auto to_git = pragma->Get("to_git", Expression::none_t{}); + to_git.IsNotNull() and to_git->IsBool() and to_git->Bool()) { + return false; + } + // Check for implicit to_git == true + if (auto special = pragma->Get("special", Expression::none_t{}); + special.IsNotNull() and special->IsString()) { + auto const& special_str = special->String(); + if (special_str == "resolve-partially" or + special_str == "resolve-completely") { + return false; + } + } + return true; // not content-fixed if not to_git + } + } + return false; +} + } // namespace namespace JustMR::Utils { @@ -92,6 +143,8 @@ void ReachableRepositories( std::unordered_set include_repos_set; std::unordered_set setup_repos_set; + bool absent_main = IsAbsent(repos->Get(main, Expression::none_t{})); + // traverse all bindings of main repository for (std::queue to_process({main}); not to_process.empty(); to_process.pop()) { @@ -108,6 +161,16 @@ void ReachableRepositories( } WarnUnknownKeys(repo_name, repos_repo_name); + // Warn if main repo is marked absent and current repo (including main) + // is not content-fixed + if (absent_main and IsNotContentFixed(repos_repo_name)) { + Logger::Log(LogLevel::Warning, + "Found non-content-fixed repository {} as dependency " + "of absent main repository {}", + nlohmann::json(repo_name).dump(), + nlohmann::json(main).dump()); + } + // If the current repo is a computed one, process its target repo if (auto precomputed = GetTargetRepoIfPrecomputed(repos, repo_name)) { to_process.push(*std::move(precomputed)); diff --git a/src/other_tools/just_mr/setup_utils.hpp b/src/other_tools/just_mr/setup_utils.hpp index 6b0d8731..7dc482e6 100644 --- a/src/other_tools/just_mr/setup_utils.hpp +++ b/src/other_tools/just_mr/setup_utils.hpp @@ -63,6 +63,8 @@ struct SetupRepos { namespace Utils { /// \brief Get the repo dependency closure for a given main repository. +/// If main repository is absent, emits a warning for any reachable +/// non-content-fixed repository found. /// \param repos ExpressionPtr of Map type. void ReachableRepositories( ExpressionPtr const& repos, -- cgit v1.2.3