Add 'warnings are errors' functionality to syncqt.cpp

Add the -warningsAreErrors command line argument to syncqt.cpp that
causes a fail at build step if any of header files doesn't fit the
syncqt standards. The argument reflects the WARNIGS_ARE_ERRORS CMake
variable state.

Output the syncqt.cpp warnings at configure time.

Fix the faulty positive IncludeChecks failure flag.

Task-number: QTBUG-107088
Change-Id: Id30af4c7b78fd44c1c99c7e9306965d03a0f992d
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Alexey Edelev 2022-09-30 12:46:18 +02:00
parent fee7844759
commit 658c166f96
2 changed files with 19 additions and 3 deletions

View File

@ -319,6 +319,10 @@ function(qt_internal_target_sync_headers target module_headers module_headers_ge
list(APPEND common_syncqt_arguments -debug) list(APPEND common_syncqt_arguments -debug)
endif() endif()
set(build_time_syncqt_arguments "")
if(WARNINGS_ARE_ERRORS)
list(APPEND build_time_syncqt_arguments -warningsAreErrors)
endif()
if(is_framework) if(is_framework)
list(REMOVE_ITEM module_headers "${CMAKE_CURRENT_BINARY_DIR}/${target}_fake_header.h") list(REMOVE_ITEM module_headers "${CMAKE_CURRENT_BINARY_DIR}/${target}_fake_header.h")
@ -344,6 +348,7 @@ function(qt_internal_target_sync_headers target module_headers module_headers_ge
COMMAND COMMAND
${QT_CMAKE_EXPORT_NAMESPACE}::syncqt ${QT_CMAKE_EXPORT_NAMESPACE}::syncqt
${common_syncqt_arguments} ${common_syncqt_arguments}
${build_time_syncqt_arguments}
-headers "@${module_headers_rsp}" -headers "@${module_headers_rsp}"
-generatedHeaders "@${module_headers_generated_rsp}" -generatedHeaders "@${module_headers_generated_rsp}"
-stagingDir "${syncqt_staging_dir}" -stagingDir "${syncqt_staging_dir}"
@ -428,7 +433,10 @@ function(qt_internal_target_sync_headers target module_headers module_headers_ge
) )
if(NOT syncqt_result EQUAL 0) if(NOT syncqt_result EQUAL 0)
message(FATAL_ERROR message(FATAL_ERROR
"Unable to execute syncqt.cpp for module ${target}: ${syncqt_output}") "syncqt.cpp failed for module ${module}:\n${syncqt_output}")
endif()
if(syncqt_output)
message("${syncqt_output}")
endif() endif()
set_property(GLOBAL APPEND PROPERTY _qt_synced_modules ${module}) set_property(GLOBAL APPEND PROPERTY _qt_synced_modules ${module})
endif() endif()

View File

@ -179,6 +179,8 @@ public:
bool showOnly() const { return m_showOnly; } bool showOnly() const { return m_showOnly; }
bool warningsAreErrors() const { return m_warningsAreErrors; }
void printHelp() const void printHelp() const
{ {
std::cout << "Usage: syncqt -sourceDir <dir> -binaryDir <dir> -module <module name>" std::cout << "Usage: syncqt -sourceDir <dir> -binaryDir <dir> -module <module name>"
@ -234,6 +236,7 @@ public:
" -minimal Do not create CaMeL case headers for the\n" " -minimal Do not create CaMeL case headers for the\n"
" public C++ symbols.\n" " public C++ symbols.\n"
" -showonly Show actions, but not perform them.\n" " -showonly Show actions, but not perform them.\n"
" -warningsAreErrors Treat all warnings as errors.\n"
" -help Print this help.\n"; " -help Print this help.\n";
} }
@ -286,6 +289,7 @@ private:
{ "-internal", { &m_isInternal, true } }, { "-all", { &m_scanAllMode, true } }, { "-internal", { &m_isInternal, true } }, { "-all", { &m_scanAllMode, true } },
{ "-copy", { &m_copy, true } }, { "-minimal", { &m_minimal, true } }, { "-copy", { &m_copy, true } }, { "-minimal", { &m_minimal, true } },
{ "-showonly", { &m_showOnly, true } }, { "-showOnly", { &m_showOnly, true } }, { "-showonly", { &m_showOnly, true } }, { "-showOnly", { &m_showOnly, true } },
{ "-warningsAreErrors", { &m_warningsAreErrors, true } }
}; };
std::string *currentValue = nullptr; std::string *currentValue = nullptr;
@ -431,6 +435,7 @@ private:
bool m_debug = false; bool m_debug = false;
bool m_minimal = false; bool m_minimal = false;
bool m_showOnly = false; bool m_showOnly = false;
bool m_warningsAreErrors = false;
std::regex m_qpaHeadersRegex; std::regex m_qpaHeadersRegex;
std::regex m_privateHeadersRegex; std::regex m_privateHeadersRegex;
std::regex m_publicNamespaceRegex; std::regex m_publicNamespaceRegex;
@ -505,6 +510,8 @@ class SyncScanner
enum FileType { PublicHeader = 0, PrivateHeader = 1, QpaHeader = 2, ExportHeader = 4 }; enum FileType { PublicHeader = 0, PrivateHeader = 1, QpaHeader = 2, ExportHeader = 4 };
unsigned int m_currentFileType = PublicHeader; unsigned int m_currentFileType = PublicHeader;
int m_criticalChecks = CriticalChecks;
public: public:
SyncScanner(CommandLineOptions *commandLineArgs) SyncScanner(CommandLineOptions *commandLineArgs)
: m_commandLineArgs(commandLineArgs), m_masterHeaderContents(MasterHeaderIncludeComparator) : m_commandLineArgs(commandLineArgs), m_masterHeaderContents(MasterHeaderIncludeComparator)
@ -519,6 +526,7 @@ public:
ErrorCodes sync() ErrorCodes sync()
{ {
m_criticalChecks = m_commandLineArgs->warningsAreErrors() ? AllChecks : CriticalChecks;
m_versionScriptGeneratorState = m_versionScriptGeneratorState =
m_commandLineArgs->versionScriptFile().empty() ? Stopped : Active; m_commandLineArgs->versionScriptFile().empty() ? Stopped : Active;
auto error = NoError; auto error = NoError;
@ -1123,10 +1131,10 @@ public:
<< " includes private header " << includedHeader << std::endl; << " includes private header " << includedHeader << std::endl;
} }
for (const auto &module : m_commandLineArgs->knownModules()) { for (const auto &module : m_commandLineArgs->knownModules()) {
faults |= IncludeChecks;
std::string suggestedHeader = "Qt" + module + '/' + includedHeader; std::string suggestedHeader = "Qt" + module + '/' + includedHeader;
if (std::filesystem::exists(m_commandLineArgs->includeDir() + "/../" if (std::filesystem::exists(m_commandLineArgs->includeDir() + "/../"
+ suggestedHeader)) { + suggestedHeader)) {
faults |= IncludeChecks;
std::cerr << m_commandLineArgs->moduleName() std::cerr << m_commandLineArgs->moduleName()
<< ": WARNING: " << m_currentFilename << " includes " << ": WARNING: " << m_currentFilename << " includes "
<< includedHeader << " when it should include " << includedHeader << " when it should include "
@ -1211,7 +1219,7 @@ public:
m_headerCheckExceptions.push_back(m_currentFileString); m_headerCheckExceptions.push_back(m_currentFileString);
// Exit with an error if any of critical checks are present. // Exit with an error if any of critical checks are present.
return !(faults & CriticalChecks); return !(faults & m_criticalChecks);
} }
// The function checks if line contains the symbol that needs to have a CaMeL-style alias. // The function checks if line contains the symbol that needs to have a CaMeL-style alias.