mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
Diagnostics: Fix order in which presets are applied
Rewrite the function that updates the diagnostic state from presets to apply all modifications concurrently. Previously, we applied all warnings, then all errors, which (because changes are recursive) could result in an enabled error for a parent diagnostic overriding a disabled warning for a child diagnostic.
This commit is contained in:
+22
-16
@@ -496,23 +496,29 @@ void cmake::SetDiagnosticsFromPreset(
|
||||
std::map<cmDiagnosticCategory, bool> const& warnings,
|
||||
std::map<cmDiagnosticCategory, bool> const& errors)
|
||||
{
|
||||
for (auto const& wi : warnings) {
|
||||
if (wi.second) {
|
||||
this->CurrentSnapshot.PromoteDiagnostic( // clang-format: break
|
||||
wi.first, cmDiagnostics::Warn, true);
|
||||
} else {
|
||||
this->CurrentSnapshot.DemoteDiagnostic( // clang-format: break
|
||||
wi.first, cmDiagnostics::Ignore, true);
|
||||
}
|
||||
}
|
||||
for (unsigned i = 1; i < cmDiagnostics::CategoryCount; ++i) {
|
||||
auto const category = static_cast<cmDiagnosticCategory>(i);
|
||||
|
||||
for (auto const& ei : errors) {
|
||||
if (ei.second) {
|
||||
this->CurrentSnapshot.PromoteDiagnostic( // clang-format: break
|
||||
ei.first, cmDiagnostics::SendError, true);
|
||||
} else {
|
||||
this->CurrentSnapshot.DemoteDiagnostic( // clang-format: break
|
||||
ei.first, cmDiagnostics::Warn, true);
|
||||
auto const wi = warnings.find(category);
|
||||
if (wi != warnings.end()) {
|
||||
if (wi->second) {
|
||||
this->CurrentSnapshot.PromoteDiagnostic( // clang-format: break
|
||||
category, cmDiagnostics::Warn, true);
|
||||
} else {
|
||||
this->CurrentSnapshot.DemoteDiagnostic( // clang-format: break
|
||||
category, cmDiagnostics::Ignore, true);
|
||||
}
|
||||
}
|
||||
|
||||
auto const ei = errors.find(category);
|
||||
if (ei != errors.end()) {
|
||||
if (ei->second) {
|
||||
this->CurrentSnapshot.PromoteDiagnostic( // clang-format: break
|
||||
category, cmDiagnostics::SendError, true);
|
||||
} else {
|
||||
this->CurrentSnapshot.DemoteDiagnostic( // clang-format: break
|
||||
category, cmDiagnostics::Warn, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
cmake_diagnostic(GET CMD_DEPRECATED action)
|
||||
if(NOT "${action}" STREQUAL IGNORE)
|
||||
message(SEND_ERROR
|
||||
"wrong action for diagnostic CMD_DEPRECATED"
|
||||
" (expected 'IGNORE', actual '${action}')")
|
||||
endif()
|
||||
@@ -365,6 +365,7 @@ run_cmake_presets(DisableWarningFlags)
|
||||
run_cmake_presets(ErrorDev)
|
||||
run_cmake_presets(ErrorUninitialized)
|
||||
run_cmake_presets(ErrorUnusedCli)
|
||||
run_cmake_presets(DiagnosticOrder)
|
||||
unset(CMakePresets_WARN_UNUSED_CLI)
|
||||
|
||||
# Test debug
|
||||
|
||||
@@ -65,6 +65,17 @@
|
||||
"errors": {
|
||||
"unusedCli": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "DiagnosticOrder",
|
||||
"inherits": "NoWarningFlags",
|
||||
"warnings": {
|
||||
"deprecated": false,
|
||||
"unusedCli": false
|
||||
},
|
||||
"errors": {
|
||||
"author": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user