From f332f2e8e66a5fa67b302893a13f0be3687ccc38 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 25 Apr 2019 14:57:12 +0200 Subject: shiboken: Refactor progress message output handling In class ReportHandler, replace the step counting by a simple pair of startProgress()/endProgress() functions that check for warnings and print the appropriate terminator. Module name and timestamp are now also printed. Add a few more messages and give proper names to the generators. Change-Id: I92b4ef2854b824fbba3d371417edc1f88561a2cb Reviewed-by: Cristian Maureira-Fredes --- .../shiboken2/ApiExtractor/abstractmetabuilder.cpp | 39 ++++++------ sources/shiboken2/ApiExtractor/reporthandler.cpp | 72 ++++++++++------------ sources/shiboken2/ApiExtractor/reporthandler.h | 11 +--- sources/shiboken2/generator/main.cpp | 5 +- .../shiboken2/generator/shiboken2/cppgenerator.h | 3 + .../generator/shiboken2/headergenerator.h | 3 + 6 files changed, 65 insertions(+), 68 deletions(-) (limited to 'sources') diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp index 6e95e79e7..7e998d315 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp @@ -428,20 +428,20 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom) // Start the generation... const ClassList &typeValues = dom->classes(); - ReportHandler::setProgressReference(typeValues); + + ReportHandler::startProgress("Generating class model (" + + QByteArray::number(typeValues.size()) + ")..."); for (const ClassModelItem &item : typeValues) { - ReportHandler::progress(QStringLiteral("Generating class model (%1)...") - .arg(typeValues.size())); if (AbstractMetaClass *cls = traverseClass(dom, item, nullptr)) addAbstractMetaClass(cls, item.data()); } // We need to know all global enums const EnumList &enums = dom->enums(); - ReportHandler::setProgressReference(enums); + + ReportHandler::startProgress("Generating enum model (" + + QByteArray::number(enums.size()) + ")..."); for (const EnumModelItem &item : enums) { - ReportHandler::progress(QStringLiteral("Generating enum model (%1)...") - .arg(enums.size())); AbstractMetaEnum *metaEnum = traverseEnum(item, 0, QSet()); if (metaEnum) { if (metaEnum->typeEntry()->generateCode()) @@ -450,10 +450,9 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom) } const auto &namespaceTypeValues = dom->namespaces(); - ReportHandler::setProgressReference(namespaceTypeValues); + ReportHandler::startProgress("Generating namespace model (" + + QByteArray::number(namespaceTypeValues.size()) + ")..."); for (const NamespaceModelItem &item : namespaceTypeValues) { - ReportHandler::progress(QStringLiteral("Generating namespace model (%1)...") - .arg(namespaceTypeValues.size())); if (AbstractMetaClass *metaClass = traverseNamespace(dom, item)) addAbstractMetaClass(metaClass, item.data()); } @@ -461,10 +460,9 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom) // Go through all typedefs to see if we have defined any // specific typedefs to be used as classes. const TypeDefList typeDefs = dom->typeDefs(); - ReportHandler::setProgressReference(typeDefs); + ReportHandler::startProgress("Resolving typedefs (" + + QByteArray::number(typeDefs.size()) + ")..."); for (const TypeDefModelItem &typeDef : typeDefs) { - ReportHandler::progress(QStringLiteral("Resolving typedefs (%1)...") - .arg(typeDefs.size())); if (AbstractMetaClass *cls = traverseTypeDef(dom, typeDef, nullptr)) addAbstractMetaClass(cls, typeDef.data()); } @@ -506,16 +504,14 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom) m_globalFunctions << metaFunc; } - ReportHandler::setProgressReference(m_metaClasses); + ReportHandler::startProgress("Fixing class inheritance..."); for (AbstractMetaClass *cls : qAsConst(m_metaClasses)) { - ReportHandler::progress(QLatin1String("Fixing class inheritance...")); if (!cls->isInterface() && !cls->isNamespace()) setupInheritance(cls); } - ReportHandler::setProgressReference(m_metaClasses); + ReportHandler::startProgress("Detecting inconsistencies in class model..."); for (AbstractMetaClass *cls : qAsConst(m_metaClasses)) { - ReportHandler::progress(QLatin1String("Detecting inconsistencies in class model...")); cls->fixFunctions(); if (!cls->typeEntry()) { @@ -538,8 +534,9 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom) cls->typeEntry()->setLookupName(cls->typeEntry()->targetLangName() + QLatin1String("$ConcreteWrapper")); } const auto &allEntries = types->entries(); - ReportHandler::progress(QStringLiteral("Detecting inconsistencies in typesystem (%1)...") - .arg(allEntries.size())); + + ReportHandler::startProgress("Detecting inconsistencies in typesystem (" + + QByteArray::number(allEntries.size()) + ")..."); for (auto it = allEntries.cbegin(), end = allEntries.cend(); it != end; ++it) { TypeEntry *entry = it.value(); if (!entry->isPrimitive()) { @@ -638,8 +635,12 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom) traverseStreamOperator(item, nullptr); } + ReportHandler::startProgress("Checking inconsistencies in function modifications..."); + checkFunctionModifications(); + ReportHandler::startProgress("Writing log files..."); + // sort all classes topologically m_metaClasses = classesTopologicalSorted(m_metaClasses); @@ -673,6 +674,8 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom) } m_itemToClass.clear(); + + ReportHandler::endProgress(); } static bool metaEnumLessThan(const AbstractMetaEnum *e1, const AbstractMetaEnum *e2) diff --git a/sources/shiboken2/ApiExtractor/reporthandler.cpp b/sources/shiboken2/ApiExtractor/reporthandler.cpp index 6ff5b8d03..c0c323029 100644 --- a/sources/shiboken2/ApiExtractor/reporthandler.cpp +++ b/sources/shiboken2/ApiExtractor/reporthandler.cpp @@ -52,22 +52,13 @@ static int m_warningCount = 0; static int m_suppressedCount = 0; static ReportHandler::DebugLevel m_debugLevel = ReportHandler::NoDebug; static QSet m_reportedWarnings; -static QString m_progressBuffer; static QString m_prefix; -static int m_step_size = 0; -static int m_step = -1; +static bool m_withinProgress = false; static int m_step_warning = 0; static QElapsedTimer m_timer; Q_LOGGING_CATEGORY(lcShiboken, "qt.shiboken") -static void printProgress() -{ - std::printf("%s", m_progressBuffer.toUtf8().data()); - std::fflush(stdout); - m_progressBuffer.clear(); -} - void ReportHandler::install() { qInstallMessageHandler(ReportHandler::messageOutput); @@ -94,12 +85,6 @@ int ReportHandler::warningCount() return m_warningCount; } -void ReportHandler::setProgressReference(int max) -{ - m_step_size = max; - m_step = -1; -} - bool ReportHandler::isSilent() { return m_silent; @@ -136,38 +121,45 @@ void ReportHandler::messageOutput(QtMsgType type, const QMessageLogContext &cont fprintf(stderr, "%s\n", qPrintable(qFormatLogMessage(type, context, message))); } -void ReportHandler::progress(const QString& str, ...) +static QByteArray timeStamp() +{ + const qint64 elapsed = m_timer.elapsed(); + return elapsed > 5000 + ? QByteArray::number(elapsed / 1000) + 's' + : QByteArray::number(elapsed) + "ms"; +} + +void ReportHandler::startProgress(const QByteArray& str) { if (m_silent) return; - if (m_step == -1) { - QTextStream buf(&m_progressBuffer); - buf.setFieldWidth(45); - buf.setFieldAlignment(QTextStream::AlignLeft); - buf << str; - printProgress(); - m_step = 0; - } - m_step++; - if (m_step >= m_step_size) { - if (m_step_warning == 0) { - m_progressBuffer = QLatin1String("[" COLOR_GREEN "OK" COLOR_END "]\n"); - } else { - m_progressBuffer = QLatin1String("[" COLOR_YELLOW "WARNING" COLOR_END "]\n"); - } - printProgress(); - m_step_warning = 0; - } + if (m_withinProgress) + endProgress(); + + m_withinProgress = true; + const auto ts = '[' + timeStamp() + ']'; + std::printf("%s %8s %-60s", qPrintable(m_prefix), ts.constData(), str.constData()); + std::fflush(stdout); +} + +void ReportHandler::endProgress() +{ + if (m_silent) + return; + + m_withinProgress = false; + const char *endMessage = m_step_warning == 0 + ? "[" COLOR_GREEN "OK" COLOR_END "]\n" + : "[" COLOR_YELLOW "WARNING" COLOR_END "]\n"; + std::fputs(endMessage, stdout); + std::fflush(stdout); + m_step_warning = 0; } QByteArray ReportHandler::doneMessage() { - QByteArray result = "Done, " + m_prefix.toUtf8() + ' '; - const qint64 elapsed = m_timer.elapsed(); - result += elapsed > 5000 - ? QByteArray::number(elapsed / 1000) + 's' - : QByteArray::number(elapsed) + "ms"; + QByteArray result = "Done, " + m_prefix.toUtf8() + ' ' + timeStamp(); if (m_warningCount) result += ", " + QByteArray::number(m_warningCount) + " warnings"; if (m_suppressedCount) diff --git a/sources/shiboken2/ApiExtractor/reporthandler.h b/sources/shiboken2/ApiExtractor/reporthandler.h index 8f97cb506..08ab7d23c 100644 --- a/sources/shiboken2/ApiExtractor/reporthandler.h +++ b/sources/shiboken2/ApiExtractor/reporthandler.h @@ -48,15 +48,8 @@ public: static int suppressedCount(); - template - static void setProgressReference(T collection) - { - setProgressReference(collection.count()); - } - - static void setProgressReference(int max); - - static void progress(const QString &str, ...); + static void startProgress(const QByteArray &str); + static void endProgress(); static bool isDebug(DebugLevel level) { return debugLevel() >= level; } diff --git a/sources/shiboken2/generator/main.cpp b/sources/shiboken2/generator/main.cpp index 9beaf47c7..ac576d657 100644 --- a/sources/shiboken2/generator/main.cpp +++ b/sources/shiboken2/generator/main.cpp @@ -624,7 +624,10 @@ int main(int argc, char *argv[]) for (const GeneratorPtr &g : qAsConst(generators)) { g->setOutputDirectory(outputDirectory); g->setLicenseComment(licenseComment); - if (!g->setup(extractor) || !g->generate()) { + ReportHandler::startProgress(QByteArray("Running ") + g->name() + "..."); + const bool ok = g->setup(extractor) && g->generate(); + ReportHandler::endProgress(); + if (!ok) { errorPrint(QLatin1String("Error running generator: ") + QLatin1String(g->name()) + QLatin1Char('.')); return EXIT_FAILURE; diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.h b/sources/shiboken2/generator/shiboken2/cppgenerator.h index d2e04dba2..519e12b7b 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.h +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.h @@ -38,6 +38,9 @@ class CppGenerator : public ShibokenGenerator { public: CppGenerator(); + + const char *name() const override { return "Source generator"; } + protected: QString fileNameSuffix() const override; QString fileNameForContext(GeneratorContext &context) const override; diff --git a/sources/shiboken2/generator/shiboken2/headergenerator.h b/sources/shiboken2/generator/shiboken2/headergenerator.h index 821531aab..f59e0fd9a 100644 --- a/sources/shiboken2/generator/shiboken2/headergenerator.h +++ b/sources/shiboken2/generator/shiboken2/headergenerator.h @@ -42,6 +42,9 @@ class HeaderGenerator : public ShibokenGenerator { public: OptionDescriptions options() const override { return OptionDescriptions(); } + + const char *name() const override { return "Header generator"; } + protected: QString fileNameSuffix() const override; QString fileNameForContext(GeneratorContext &context) const override; -- cgit v1.2.3