From 99fcb5c14b6cb29e3d6ac64eec9b5239951795ec Mon Sep 17 00:00:00 2001 From: Burak Hancerli Date: Fri, 10 May 2024 13:31:01 +0200 Subject: [PATCH] QmlPuppet: Fix the debug messages Change-Id: I2b1d969a665863232a8d60a943fce87b6bb4dd3c Reviewed-by: Qt CI Patch Build Bot Reviewed-by: Tim Jenssen --- src/tools/qml2puppet/CMakeLists.txt | 25 +-------- .../qml2puppet/qml2puppet/appmetadata.cpp | 51 ----------------- src/tools/qml2puppet/qml2puppet/appmetadata.h | 55 ------------------- .../qml2puppet/qml2puppet/qml2puppetmain.cpp | 31 ++++++++++- src/tools/qml2puppet/qml2puppet/qmlbase.h | 25 +-------- src/tools/qml2puppet/qml2puppet/qmlpuppet.cpp | 1 - .../qml2puppet/runner/qmlruntime.cpp | 48 +++++++++------- 7 files changed, 61 insertions(+), 175 deletions(-) delete mode 100644 src/tools/qml2puppet/qml2puppet/appmetadata.cpp delete mode 100644 src/tools/qml2puppet/qml2puppet/appmetadata.h diff --git a/src/tools/qml2puppet/CMakeLists.txt b/src/tools/qml2puppet/CMakeLists.txt index b9f1a1544cc..36ca6293d43 100644 --- a/src/tools/qml2puppet/CMakeLists.txt +++ b/src/tools/qml2puppet/CMakeLists.txt @@ -38,39 +38,20 @@ add_qtc_executable(qml2puppet DEPENDS Qt::CorePrivate Qt::Widgets Qt::QmlPrivate Qt::QuickPrivate Qt::Network Qt::GuiPrivate + app_version QmlPuppetCommunication INCLUDES ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} SOURCES qml2puppet/qml2puppetmain.cpp qml2puppet/qmlbase.h - qml2puppet/appmetadata.cpp qml2puppet/appmetadata.h - qml2puppet/qmlpuppet.h qml2puppet/qmlpuppet.cpp qml2puppet/configcrashpad.h + qml2puppet/qmlpuppet.h qml2puppet/qmlpuppet.cpp + qml2puppet/configcrashpad.h qmlpuppet.qrc PROPERTIES OUTPUT_NAME qml2puppet-${IDE_VERSION} ) -if (TARGET qml2puppet) - execute_process( - COMMAND git describe --tags --always --dirty=+ - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - RESULT_VARIABLE GIT_SHA_RESULT - OUTPUT_VARIABLE GIT_SHA - ERROR_VARIABLE GIT_SHA_ERROR - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - - #if we are not a git repository use the .tag file - if(NOT GIT_SHA) - file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/../../../.tag GIT_SHA LIMIT_COUNT 1) - endif() - - set(IDE_REVISION_STR ${GIT_SHA}) - - configure_file(../../app/app_version.h.cmakein app/app_version.h ESCAPE_QUOTES) -endif() - extend_qtc_executable(qml2puppet CONDITION Qt6_VERSION SOURCES diff --git a/src/tools/qml2puppet/qml2puppet/appmetadata.cpp b/src/tools/qml2puppet/qml2puppet/appmetadata.cpp deleted file mode 100644 index 1896e4db926..00000000000 --- a/src/tools/qml2puppet/qml2puppet/appmetadata.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0 - -#include "appmetadata.h" - -#include - -namespace QDSMeta::AppInfo { - -void printAppInfo() -{ - qInfo() << Qt::endl - << "<< QDS Meta Info >>" << Qt::endl - << "App Info" << Qt::endl - << " - Name :" << Core::Constants::IDE_ID << Qt::endl - << " - Version :" << Core::Constants::IDE_VERSION_DISPLAY << Qt::endl - << " - Author :" << Core::Constants::IDE_AUTHOR << Qt::endl - << " - Year :" << Core::Constants::IDE_YEAR << Qt::endl - << " - App :" << QCoreApplication::applicationName() << Qt::endl - << "Build Info " << Qt::endl - << " - Date :" << __DATE__ << Qt::endl - << " - Commit :" << QStringLiteral(QDS_STRINGIFY(IDE_REVISION_STR)) << Qt::endl - << " - Qt Version :" << QT_VERSION_STR << Qt::endl - << "Compiler Info " << Qt::endl -#if defined(__GNUC__) - << " - GCC :" << __GNUC__ << Qt::endl - << " - GCC Minor :" << __GNUC_MINOR__ << Qt::endl - << " - GCC Patch :" << __GNUC_PATCHLEVEL__ << Qt::endl -#endif -#if defined(_MSC_VER) - << " - MSC Short :" << _MSC_VER << Qt::endl - << " - MSC Full :" << _MSC_FULL_VER << Qt::endl -#endif -#if defined(__clang__) - << " - clang maj :" << __clang_major__ << Qt::endl - << " - clang min :" << __clang_minor__ << Qt::endl - << " - clang patch :" << __clang_patchlevel__ << Qt::endl -#endif - << "<< End Of QDS Meta Info >>" << Qt::endl; - exit(0); -} - -void registerAppInfo(const QString &appName) -{ - QCoreApplication::setOrganizationName(Core::Constants::IDE_AUTHOR); - QCoreApplication::setOrganizationDomain("qt-project.org"); - QCoreApplication::setApplicationName(appName); - QCoreApplication::setApplicationVersion(Core::Constants::IDE_VERSION_LONG); -} - -} // namespace QDSMeta::AppInfo diff --git a/src/tools/qml2puppet/qml2puppet/appmetadata.h b/src/tools/qml2puppet/qml2puppet/appmetadata.h deleted file mode 100644 index 18eb650461e..00000000000 --- a/src/tools/qml2puppet/qml2puppet/appmetadata.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -#pragma once - -#include -#include - -// Common functions can be used in all QDS apps -namespace QDSMeta { - -namespace Logging { -inline Q_LOGGING_CATEGORY(deprecated, "qt.tools.qds.deprecated"); -inline Q_LOGGING_CATEGORY(verbose1, "qt.tools.qds.verbose1"); -inline Q_LOGGING_CATEGORY(verbose2, "qt.tools.qds.verbose2"); - -inline void registerMessageHandler() -{ - qInstallMessageHandler( - [](QtMsgType type, const QMessageLogContext &context, const QString &msg) { - auto tPrinter = [&](const QString &msgPrefix) { - fprintf(stderr, - "%s: %s (%s:%u, %s)\n", - msgPrefix.toLocal8Bit().constData(), - msg.toLocal8Bit().constData(), - context.file, - context.line, - context.function); - }; - - if (type == QtDebugMsg) - tPrinter("Debug"); - else if (type == QtInfoMsg) - tPrinter("Info"); - else if (type == QtWarningMsg) - tPrinter("Warning"); - else if (type == QtCriticalMsg) - tPrinter("Critical"); - else if (type == QtFatalMsg) { - tPrinter("Fatal"); - abort(); - } - }); -} -} // namespace Logging - -namespace AppInfo { - -#define STRINGIFY_INTERNAL(x) #x -#define QDS_STRINGIFY(x) STRINGIFY_INTERNAL(x) - -void printAppInfo(); -void registerAppInfo(const QString &appName); - -} // namespace AppInfo -} // namespace QDSMeta diff --git a/src/tools/qml2puppet/qml2puppet/qml2puppetmain.cpp b/src/tools/qml2puppet/qml2puppet/qml2puppetmain.cpp index 5896df39e1f..937bb36d8eb 100644 --- a/src/tools/qml2puppet/qml2puppet/qml2puppetmain.cpp +++ b/src/tools/qml2puppet/qml2puppet/qml2puppetmain.cpp @@ -7,6 +7,34 @@ #include "runner/qmlruntime.h" #endif +#include + +inline Q_LOGGING_CATEGORY(deprecated, "qt.tools.qds.deprecated"); +inline Q_LOGGING_CATEGORY(verbose1, "qt.tools.qds.verbose1"); +inline Q_LOGGING_CATEGORY(verbose2, "qt.tools.qds.verbose2"); + +void registerMessageHandler( + QtMsgType type, [[maybe_unused]] const QMessageLogContext &context, const QString &msg) +{ + auto tPrinter = [&](const QString &msgPrefix) { + fprintf( + stderr, "%s: %s\n", msgPrefix.toLocal8Bit().constData(), msg.toLocal8Bit().constData()); + }; + + if (type == QtDebugMsg) + tPrinter("Debug"); + else if (type == QtInfoMsg) + tPrinter("Info"); + else if (type == QtWarningMsg) + tPrinter("Warning"); + else if (type == QtCriticalMsg) + tPrinter("Critical"); + else if (type == QtFatalMsg) { + tPrinter("Fatal"); + abort(); + } +} + auto getQmlRunner(int &argc, char **argv) { #ifdef ENABLE_INTERNAL_QML_RUNTIME @@ -24,7 +52,6 @@ auto getQmlRunner(int &argc, char **argv) int main(int argc, char *argv[]) { - QDSMeta::Logging::registerMessageHandler(); - QDSMeta::AppInfo::registerAppInfo("Qml2Puppet"); + qInstallMessageHandler(registerMessageHandler); return getQmlRunner(argc, argv)->run(); } diff --git a/src/tools/qml2puppet/qml2puppet/qmlbase.h b/src/tools/qml2puppet/qml2puppet/qmlbase.h index ae8995f4893..45be0cae71d 100644 --- a/src/tools/qml2puppet/qml2puppet/qmlbase.h +++ b/src/tools/qml2puppet/qml2puppet/qmlbase.h @@ -3,27 +3,12 @@ #pragma once -#include -#include -#include -#include - -#include -#include -#include -#include - +#include #include +#include -#include -#include - -#include - -#include "appmetadata.h" #include -#include class QmlBase : public QObject { Q_OBJECT @@ -44,7 +29,6 @@ public: #ifdef ENABLE_INTERNAL_QML_RUNTIME m_argParser.addOption({"qml-runtime", "Run QML Runtime"}); #endif - m_argParser.addOption({"appinfo", "Print build information"}); m_argParser.addOption({"test", "Run test mode"}); } @@ -92,7 +76,6 @@ private: void initParser() { QCommandLineOption optHelp = m_argParser.addHelpOption(); - QCommandLineOption optVers = m_argParser.addVersionOption(); if (!m_argParser.parse(m_coreApp->arguments())) { std::cout << "Error: " << m_argParser.errorText().toStdString() << std::endl; @@ -103,12 +86,8 @@ private: std::cout << std::endl; m_argParser.showHelp(1); - } else if (m_argParser.isSet(optVers)) { - m_argParser.showVersion(); } else if (m_argParser.isSet(optHelp)) { m_argParser.showHelp(0); - } else if (m_argParser.isSet("appinfo")) { - QDSMeta::AppInfo::printAppInfo(); } else if (m_argParser.isSet("test")) { exit(startTestMode()); } diff --git a/src/tools/qml2puppet/qml2puppet/qmlpuppet.cpp b/src/tools/qml2puppet/qml2puppet/qmlpuppet.cpp index 86dce8cb90d..332def504ee 100644 --- a/src/tools/qml2puppet/qml2puppet/qmlpuppet.cpp +++ b/src/tools/qml2puppet/qml2puppet/qmlpuppet.cpp @@ -10,7 +10,6 @@ #include #include - #include #include diff --git a/src/tools/qml2puppet/qml2puppet/runner/qmlruntime.cpp b/src/tools/qml2puppet/qml2puppet/runner/qmlruntime.cpp index 4435d0e9f42..2876339a903 100644 --- a/src/tools/qml2puppet/qml2puppet/runner/qmlruntime.cpp +++ b/src/tools/qml2puppet/qml2puppet/runner/qmlruntime.cpp @@ -13,6 +13,10 @@ #include #include #include +#include +#include +#include +#include #define FILE_OPEN_EVENT_WAIT_TIME 3000 // ms #define QSL QStringLiteral @@ -242,12 +246,12 @@ void QmlRuntime::initQmlRunner() if (translator.load(translationFile)) { m_coreApp->installTranslator(&translator); if (m_verboseMode) - qInfo() << "qml: Loaded translation file %s\n", - qPrintable(QDir::toNativeSeparators(translationFile)); + qInfo() << "qml: Loaded translation file " + << qPrintable(QDir::toNativeSeparators(translationFile)); } else { if (!m_quietMode) - qInfo() << "qml: Could not load the translation file %s\n", - qPrintable(QDir::toNativeSeparators(translationFile)); + qInfo() << "qml: Could not load the translation file " + << qPrintable(QDir::toNativeSeparators(translationFile)); } } #else @@ -278,7 +282,7 @@ void QmlRuntime::initQmlRunner() for (const QString &path : std::as_const(files)) { QUrl url = QUrl::fromUserInput(path, QDir::currentPath(), QUrl::AssumeLocalFile); if (m_verboseMode) - qInfo() << "qml: loading %s\n", qPrintable(url.toString()); + qInfo() << "qml: loading " << qPrintable(url.toString()); m_qmlEngine->load(url); } @@ -318,8 +322,8 @@ void QmlRuntime::loadConf(const QString &override, bool quiet) // Terminates app else fi.setFile(override); if (!fi.exists()) { - qCritical() << "qml: Couldn't find required configuration file: %s\n", - qPrintable(QDir::toNativeSeparators(fi.absoluteFilePath())); + qCritical() << "qml: Couldn't find required configuration file:" + << qPrintable(QDir::toNativeSeparators(fi.absoluteFilePath())); exit(1); } settingsUrl = QQmlImports::urlFromLocalFileOrQrcOrUrl(fi.absoluteFilePath()); @@ -327,13 +331,14 @@ void QmlRuntime::loadConf(const QString &override, bool quiet) // Terminates app } if (!quiet) { - qInfo() << "qml: %s\n", QLibraryInfo::build(); + qInfo() << "qml:" << QLibraryInfo::build(); if (builtIn) { - qInfo() << "qml: Using built-in configuration: %s\n", - qPrintable(override.isEmpty() ? defaultFileName : override); + qInfo() << "qml: Using built-in configuration:" + << qPrintable(override.isEmpty() ? defaultFileName : override); } else { - qInfo() << "qml: Using configuration: %s\n", - qPrintable(settingsUrl.isLocalFile() + qInfo() << "qml: Using configuration:" + << qPrintable( + settingsUrl.isLocalFile() ? QDir::toNativeSeparators(settingsUrl.toLocalFile()) : settingsUrl.toString()); } @@ -345,18 +350,19 @@ void QmlRuntime::loadConf(const QString &override, bool quiet) // Terminates app m_conf.reset(qobject_cast(c2.create())); if (!m_conf) { - qCritical() << "qml: Error loading configuration file: %s\n", qPrintable(c2.errorString()); + qCritical() << "qml: Error loading configuration file:" << qPrintable(c2.errorString()); exit(1); } } void QmlRuntime::listConfFiles() { + qDebug() << "qml: Built-in configurations:"; const QDir confResourceDir(m_confResourcePath); - qInfo() << "%s\n", qPrintable(QCoreApplication::translate("main", "Built-in configurations:")); + qInfo() << qPrintable(QCoreApplication::translate("main", "Built-in configurations:")); for (const QFileInfo &fi : confResourceDir.entryInfoList(QDir::Files)) - qInfo() << " %s\n", qPrintable(fi.baseName()); - qInfo() << "%s\n", qPrintable(QCoreApplication::translate("main", "Other configurations:")); + qInfo() << qPrintable(fi.baseName()); + qInfo() << qPrintable(QCoreApplication::translate("main", "Other configurations:")); bool foundOther = false; const QStringList otherLocations = QStandardPaths::standardLocations( QStandardPaths::AppConfigLocation); @@ -365,16 +371,16 @@ void QmlRuntime::listConfFiles() for (const QFileInfo &fi : confDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) { foundOther = true; if (m_verboseMode) - qInfo() << " %s\n", qPrintable(fi.absoluteFilePath()); + qInfo() << qPrintable(fi.absoluteFilePath()); else - qInfo() << " %s\n", qPrintable(fi.baseName()); + qInfo() << qPrintable(fi.baseName()); } } if (!foundOther) - qInfo() << " %s\n", qPrintable(QCoreApplication::translate("main", "none")); + qInfo() << qPrintable(QCoreApplication::translate("main", "none")); if (m_verboseMode) { - qInfo() << "%s\n", qPrintable(QCoreApplication::translate("main", "Checked in:")); + qInfo() << qPrintable(QCoreApplication::translate("main", "Checked in:")); for (const auto &confDirPath : otherLocations) - qInfo() << " %s\n", qPrintable(confDirPath); + qInfo() << qPrintable(confDirPath); } }