syncqt: Use "ERROR:" preamble for warnings that are treated as errors

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 <joerg.bornemann@qt.io>
This commit is contained in:
Alexey Edelev 2022-10-11 14:38:11 +02:00
parent 6f418df9cc
commit f037e85dc2

View File

@ -19,6 +19,7 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <string> #include <string>
#include <string_view>
#include <cstring> #include <cstring>
#include <sstream> #include <sstream>
#include <filesystem> #include <filesystem>
@ -51,6 +52,9 @@ constexpr int LinkerScriptCommentAlignment = 55;
static const std::regex GlobalHeaderRegex("^q(.*)global\\.h$"); 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. // 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. // 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) bool MasterHeaderIncludeComparator(const std::string &a, const std::string &b)
@ -511,10 +515,13 @@ class SyncScanner
unsigned int m_currentFileType = PublicHeader; unsigned int m_currentFileType = PublicHeader;
int m_criticalChecks = CriticalChecks; int m_criticalChecks = CriticalChecks;
std::string_view m_warningMessagePreamble;
public: public:
SyncScanner(CommandLineOptions *commandLineArgs) 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() ErrorCodes sync()
{ {
m_criticalChecks = m_commandLineArgs->warningsAreErrors() ? AllChecks : CriticalChecks; if (m_commandLineArgs->warningsAreErrors()) {
m_criticalChecks = AllChecks;
m_warningMessagePreamble = ErrorMessagePreamble;
}
m_versionScriptGeneratorState = m_versionScriptGeneratorState =
m_commandLineArgs->versionScriptFile().empty() ? Stopped : Active; m_commandLineArgs->versionScriptFile().empty() ? Stopped : Active;
auto error = NoError; auto error = NoError;
@ -1126,7 +1137,7 @@ public:
.filename() .filename()
.generic_string())) { .generic_string())) {
faults |= PrivateHeaderChecks; faults |= PrivateHeaderChecks;
std::cerr << "ERROR: " << m_currentFileString std::cerr << ErrorMessagePreamble << m_currentFileString
<< ":" << m_currentFileLineNumber << ":" << m_currentFileLineNumber
<< " includes private header " << includedHeader << std::endl; << " includes private header " << includedHeader << std::endl;
} }
@ -1135,7 +1146,7 @@ public:
if (std::filesystem::exists(m_commandLineArgs->includeDir() + "/../" if (std::filesystem::exists(m_commandLineArgs->includeDir() + "/../"
+ suggestedHeader)) { + suggestedHeader)) {
faults |= IncludeChecks; faults |= IncludeChecks;
std::cerr << "WARNING: " << m_currentFileString std::cerr << m_warningMessagePreamble << m_currentFileString
<< ":" << m_currentFileLineNumber << ":" << m_currentFileLineNumber
<< " includes " << includedHeader << " includes " << includedHeader
<< " when it should include " << " when it should include "
@ -1193,21 +1204,21 @@ public:
if (hasQtBeginNamespace) { if (hasQtBeginNamespace) {
if (qtBeginNamespace != qtEndNamespace) { if (qtBeginNamespace != qtEndNamespace) {
faults |= NamespaceChecks; faults |= NamespaceChecks;
std::cerr << "WARNING: " << m_currentFileString std::cerr << m_warningMessagePreamble << m_currentFileString
<< " the begin namespace macro QT_BEGIN_NAMESPACE" << qtBeginNamespace << " the begin namespace macro QT_BEGIN_NAMESPACE" << qtBeginNamespace
<< " doesn't match the end namespace macro QT_END_NAMESPACE" << " doesn't match the end namespace macro QT_END_NAMESPACE"
<< qtEndNamespace << std::endl; << qtEndNamespace << std::endl;
} }
} else { } else {
faults |= NamespaceChecks; faults |= NamespaceChecks;
std::cerr << "WARNING: " << m_currentFileString std::cerr << m_warningMessagePreamble << m_currentFileString
<< " does not include QT_BEGIN_NAMESPACE" << std::endl; << " does not include QT_BEGIN_NAMESPACE" << std::endl;
} }
} }
if (!(skipChecks & WeMeantItChecks) && !hasWeMeantIt) { if (!(skipChecks & WeMeantItChecks) && !hasWeMeantIt) {
faults |= WeMeantItChecks; faults |= WeMeantItChecks;
std::cerr << "WARNING: " << m_currentFileString std::cerr << m_warningMessagePreamble << m_currentFileString
<< " does not have the \"We mean it.\" warning" << " does not have the \"We mean it.\" warning"
<< std::endl; << std::endl;
} }