From f0d5b0423de0eb72cda0b5624ac28d72bf65cffd Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Tue, 24 Sep 2024 10:04:03 +0200 Subject: Repository setup: Warn about unknown keys Warn if a repository definition contains unknown keys (that are therefore ignored), as this often indicates a typo in the repository specification. However, for some common naming of extensions (currently: "bootstrap") keep the warning at a level below the default for reporting. --- src/other_tools/just_mr/setup_utils.cpp | 27 +++++++++++++++++++++++++++ src/other_tools/just_mr/setup_utils.hpp | 17 +++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/other_tools/just_mr/setup_utils.cpp b/src/other_tools/just_mr/setup_utils.cpp index 4e5e5ad3..4aa710c5 100644 --- a/src/other_tools/just_mr/setup_utils.cpp +++ b/src/other_tools/just_mr/setup_utils.cpp @@ -14,6 +14,7 @@ #include "src/other_tools/just_mr/setup_utils.hpp" +#include #include #include #include @@ -26,6 +27,31 @@ #include "src/buildtool/logging/logger.hpp" #include "src/other_tools/just_mr/exit_codes.hpp" +namespace { + +void WarnUnknownKeys(std::string const& name, ExpressionPtr const& repo_def) { + if (not repo_def->IsMap()) { + return; + } + for (auto const& [key, value] : repo_def->Map()) { + if (not kRepositoryExpectedFields.contains(key)) { + Logger::Log(std::any_of(kRepositoryPossibleFieldTrunks.begin(), + kRepositoryPossibleFieldTrunks.end(), + [k = key](auto const& trunk) { + return k.find(trunk) != + std::string::npos; + }) + ? LogLevel::Debug + : LogLevel::Warning, + "Ignoring unknown field {} in repository {}", + key, + name); + } + } +} + +} // namespace + namespace JustMR::Utils { void ReachableRepositories( @@ -46,6 +72,7 @@ void ReachableRepositories( if (not repos_repo_name.IsNotNull()) { return; } + WarnUnknownKeys(repo_name, repos_repo_name); auto bindings = repos_repo_name->Get("bindings", Expression::none_t{}); if (bindings.IsNotNull() and bindings->IsMap()) { diff --git a/src/other_tools/just_mr/setup_utils.hpp b/src/other_tools/just_mr/setup_utils.hpp index 66691441..e29df4a6 100644 --- a/src/other_tools/just_mr/setup_utils.hpp +++ b/src/other_tools/just_mr/setup_utils.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -35,6 +36,22 @@ std::vector const kAltDirs = {"target_root", "rule_root", "expression_root"}; +auto const kRepositoryExpectedFields = + std::unordered_set{"bindings", + "expression_file_name", + "expression_root", + "repository", + "rule_file_name", + "rule_root", + "target_file_name", + "target_root"}; + +// Substrings in repository field names that indicate commonly-used +// additional keys not used by just-mr but deliberately added by the +// author of the repository configuration. +auto const kRepositoryPossibleFieldTrunks = + std::vector{"bootstrap", "doc", "extra"}; + namespace JustMR { struct SetupRepos { -- cgit v1.2.3