From da97bc5f53f433d68fa1a020f56fb5484d7cf519 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 29 Mar 2022 19:40:23 +0200 Subject: moc: Add --debug-includes option to moc Because moc silently ignores missing headers, or sometimes includes the wrong header, it is useful to have a facility to print which header paths were considered and found. Add a new --debug-includes option that does that. Task-number: QTBUG-101775 Change-Id: I72b294ae53d6e47252c7d8afe0f2245da78bfadb Reviewed-by: Fabian Kosmale --- src/tools/moc/preprocessor.cpp | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'src/tools/moc/preprocessor.cpp') diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp index f6d738aa56b..45a7f727511 100644 --- a/src/tools/moc/preprocessor.cpp +++ b/src/tools/moc/preprocessor.cpp @@ -1016,9 +1016,15 @@ static void mergeStringLiterals(Symbols *_symbols) } static QByteArray searchIncludePaths(const QList &includepaths, - const QByteArray &include) + const QByteArray &include, + const bool debugIncludes) { QFileInfo fi; + + if (Q_UNLIKELY(debugIncludes)) { + fprintf(stderr, "debug-includes: searching for '%s'\n", include.constData()); + } + for (int j = 0; j < includepaths.size() && !fi.exists(); ++j) { const Parser::IncludePath &p = includepaths.at(j); if (p.isFrameworkPath) { @@ -1030,6 +1036,12 @@ static QByteArray searchIncludePaths(const QList &includepa } else { fi.setFile(QString::fromLocal8Bit(p.path), QString::fromLocal8Bit(include)); } + + if (Q_UNLIKELY(debugIncludes)) { + const auto candidate = fi.filePath().toLocal8Bit(); + fprintf(stderr, "debug-includes: considering '%s'\n", candidate.constData()); + } + // try again, maybe there's a file later in the include paths with the same name // (186067) if (fi.isDir()) { @@ -1038,9 +1050,20 @@ static QByteArray searchIncludePaths(const QList &includepa } } - if (!fi.exists() || fi.isDir()) + if (!fi.exists() || fi.isDir()) { + if (Q_UNLIKELY(debugIncludes)) { + fprintf(stderr, "debug-includes: can't find '%s'\n", include.constData()); + } return QByteArray(); - return fi.canonicalFilePath().toLocal8Bit(); + } + + const auto result = fi.canonicalFilePath().toLocal8Bit(); + + if (Q_UNLIKELY(debugIncludes)) { + fprintf(stderr, "debug-includes: found '%s'\n", result.constData()); + } + + return result; } QByteArray Preprocessor::resolveInclude(const QByteArray &include, const QByteArray &relativeTo) @@ -1054,7 +1077,11 @@ QByteArray Preprocessor::resolveInclude(const QByteArray &include, const QByteAr auto it = nonlocalIncludePathResolutionCache.find(include); if (it == nonlocalIncludePathResolutionCache.end()) - it = nonlocalIncludePathResolutionCache.insert(include, searchIncludePaths(includes, include)); + it = nonlocalIncludePathResolutionCache.insert(include, + searchIncludePaths( + includes, + include, + debugIncludes)); return it.value(); } @@ -1319,4 +1346,10 @@ void Preprocessor::until(Token t) ; } +void Preprocessor::setDebugIncludes(bool value) +{ + debugIncludes = value; +} + + QT_END_NAMESPACE -- cgit v1.2.3