From 1a55fe5440b7a96d5d79349b816f25c44b99da87 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 13 Oct 2022 09:19:56 +0200 Subject: QmlCompiler: Add a separate flag for the "pragma Strict" check We want to trigger the qFatal() when running qmlcachegen or qmlsc, but we don't want to trigger it in qmllint, even if we are using the same QtMsgType for the severity of the messages. In turn, demote qmlCompiler messages to QtWarningMsg in qmlcachegen. Task-number: QTBUG-107168 Change-Id: Ib660df41742b2d426241eb29ac4c91f4933c5ba1 Reviewed-by: Fabian Kosmale (cherry picked from commit bc528a0770150e3fde1fdab7b699379bc736b9e1) --- src/qmlcompiler/qqmljscompiler.cpp | 5 ++--- src/qmlcompiler/qqmljslogger_p.h | 14 ++++++++++++++ tools/qmlcachegen/qmlcachegen.cpp | 1 + 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/qmlcompiler/qqmljscompiler.cpp b/src/qmlcompiler/qqmljscompiler.cpp index 76a7ed80e2..9e4c3a1cbb 100644 --- a/src/qmlcompiler/qqmljscompiler.cpp +++ b/src/qmlcompiler/qqmljscompiler.cpp @@ -648,9 +648,8 @@ QQmlJS::DiagnosticMessage QQmlJSAotCompiler::diagnose( const QString &message, QtMsgType type, const QQmlJS::SourceLocation &location) const { if (isStrict(m_document) - && (type == QtWarningMsg || type == QtCriticalMsg || type == QtFatalMsg) - && !m_logger->isCategoryIgnored(Log_Compiler) - && m_logger->categoryLevel(Log_Compiler) == QtCriticalMsg) { + && (type == QtWarningMsg || type == QtCriticalMsg || type == QtFatalMsg) + && m_logger->isCategoryFatal(Log_Compiler)) { qFatal("%s:%d: (strict mode) %s", qPrintable(QFileInfo(m_resourcePath).fileName()), location.startLine, qPrintable(message)); diff --git a/src/qmlcompiler/qqmljslogger_p.h b/src/qmlcompiler/qqmljslogger_p.h index 0302201eaf..9c89fd754a 100644 --- a/src/qmlcompiler/qqmljslogger_p.h +++ b/src/qmlcompiler/qqmljslogger_p.h @@ -201,6 +201,16 @@ public: m_categoryChanged[category] = true; } + bool isCategoryFatal(QQmlJSLoggerCategory category) const + { + return m_categoryFatal[category]; + } + void setCategoryFatal(QQmlJSLoggerCategory category, bool error) + { + m_categoryFatal[category] = error; + m_categoryChanged[category] = true; + } + bool wasCategoryChanged(QQmlJSLoggerCategory category) const { return m_categoryChanged[category]; @@ -257,6 +267,10 @@ private: bool m_categoryIgnored[QQmlJSLoggerCategory_Last + 1] = {}; bool m_categoryChanged[QQmlJSLoggerCategory_Last + 1] = {}; + // If true, triggers qFatal on documents with "pragma Strict" + // TODO: Works only for qmlCompiler category so far. + bool m_categoryFatal[QQmlJSLoggerCategory_Last + 1] = {}; + QList m_infos; QList m_warnings; QList m_errors; diff --git a/tools/qmlcachegen/qmlcachegen.cpp b/tools/qmlcachegen/qmlcachegen.cpp index 3a74f587e9..141c010272 100644 --- a/tools/qmlcachegen/qmlcachegen.cpp +++ b/tools/qmlcachegen/qmlcachegen.cpp @@ -246,6 +246,7 @@ int main(int argc, char **argv) // Always trigger the qFatal() on "pragma Strict" violations. logger.setCategoryLevel(Log_Compiler, QtCriticalMsg); logger.setCategoryIgnored(Log_Compiler, false); + logger.setCategoryFatal(Log_Compiler, true); // By default, we're completely silent, // as the lcAotCompiler category default is QtFatalMsg -- cgit v1.2.3