diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-09-24 10:04:03 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-09-24 11:13:14 +0200 |
commit | f0d5b0423de0eb72cda0b5624ac28d72bf65cffd (patch) | |
tree | 3d5dae98188f81b07266aa81a450f5c87e9d7f29 /src | |
parent | 1f99796d6f808f006dff6dc6576910bef493e244 (diff) | |
download | justbuild-f0d5b0423de0eb72cda0b5624ac28d72bf65cffd.tar.gz |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/other_tools/just_mr/setup_utils.cpp | 27 | ||||
-rw-r--r-- | src/other_tools/just_mr/setup_utils.hpp | 17 |
2 files changed, 44 insertions, 0 deletions
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 <algorithm> #include <fstream> #include <unordered_set> #include <variant> @@ -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 <filesystem> #include <memory> #include <optional> +#include <set> #include <string> #include <vector> @@ -35,6 +36,22 @@ std::vector<std::string> const kAltDirs = {"target_root", "rule_root", "expression_root"}; +auto const kRepositoryExpectedFields = + std::unordered_set<std::string>{"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<std::string>{"bootstrap", "doc", "extra"}; + namespace JustMR { struct SetupRepos { |