From f037e85dc29f69ae747c3f446751ae39b70f9ff1 Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Tue, 11 Oct 2022 14:38:11 +0200 Subject: [PATCH] syncqt: Use "ERROR:" preamble for warnings that are treated as errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the "ERROR:" preamble for all syncqt warnings if warningsAreErrors flag is set. Amends 658c166f966a6081d424a3f30c6769c28134b52a Task-number: QTBUG-107088 Change-Id: Idc4a0e9196dce9788fd5a25bdac6783779c1bc85 Reviewed-by: Jörg Bornemann --- src/tools/syncqt/main.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/tools/syncqt/main.cpp b/src/tools/syncqt/main.cpp index b4c37ec626a..571d850d4c1 100644 --- a/src/tools/syncqt/main.cpp +++ b/src/tools/syncqt/main.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -51,6 +52,9 @@ constexpr int LinkerScriptCommentAlignment = 55; static const std::regex GlobalHeaderRegex("^q(.*)global\\.h$"); +constexpr std::string_view ErrorMessagePreamble = "ERROR: "; +constexpr std::string_view WarningMessagePreamble = "WARNING: "; + // This comparator is used to sort include records in master header. // It's used to put q.*global.h file to the top of the list and sort all other files alphabetically. bool MasterHeaderIncludeComparator(const std::string &a, const std::string &b) @@ -511,10 +515,13 @@ class SyncScanner unsigned int m_currentFileType = PublicHeader; int m_criticalChecks = CriticalChecks; + std::string_view m_warningMessagePreamble; public: SyncScanner(CommandLineOptions *commandLineArgs) - : m_commandLineArgs(commandLineArgs), m_masterHeaderContents(MasterHeaderIncludeComparator) + : m_commandLineArgs(commandLineArgs), + m_masterHeaderContents(MasterHeaderIncludeComparator), + m_warningMessagePreamble(WarningMessagePreamble) { } @@ -526,7 +533,11 @@ public: ErrorCodes sync() { - m_criticalChecks = m_commandLineArgs->warningsAreErrors() ? AllChecks : CriticalChecks; + if (m_commandLineArgs->warningsAreErrors()) { + m_criticalChecks = AllChecks; + m_warningMessagePreamble = ErrorMessagePreamble; + } + m_versionScriptGeneratorState = m_commandLineArgs->versionScriptFile().empty() ? Stopped : Active; auto error = NoError; @@ -1126,7 +1137,7 @@ public: .filename() .generic_string())) { faults |= PrivateHeaderChecks; - std::cerr << "ERROR: " << m_currentFileString + std::cerr << ErrorMessagePreamble << m_currentFileString << ":" << m_currentFileLineNumber << " includes private header " << includedHeader << std::endl; } @@ -1135,7 +1146,7 @@ public: if (std::filesystem::exists(m_commandLineArgs->includeDir() + "/../" + suggestedHeader)) { faults |= IncludeChecks; - std::cerr << "WARNING: " << m_currentFileString + std::cerr << m_warningMessagePreamble << m_currentFileString << ":" << m_currentFileLineNumber << " includes " << includedHeader << " when it should include " @@ -1193,21 +1204,21 @@ public: if (hasQtBeginNamespace) { if (qtBeginNamespace != qtEndNamespace) { faults |= NamespaceChecks; - std::cerr << "WARNING: " << m_currentFileString + std::cerr << m_warningMessagePreamble << m_currentFileString << " the begin namespace macro QT_BEGIN_NAMESPACE" << qtBeginNamespace << " doesn't match the end namespace macro QT_END_NAMESPACE" << qtEndNamespace << std::endl; } } else { faults |= NamespaceChecks; - std::cerr << "WARNING: " << m_currentFileString + std::cerr << m_warningMessagePreamble << m_currentFileString << " does not include QT_BEGIN_NAMESPACE" << std::endl; } } if (!(skipChecks & WeMeantItChecks) && !hasWeMeantIt) { faults |= WeMeantItChecks; - std::cerr << "WARNING: " << m_currentFileString + std::cerr << m_warningMessagePreamble << m_currentFileString << " does not have the \"We mean it.\" warning" << std::endl; }