diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2022-03-29 19:40:23 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2022-04-05 19:40:17 +0200 |
commit | da97bc5f53f433d68fa1a020f56fb5484d7cf519 (patch) | |
tree | 158e8b6d52181a96cdd09d588180d75275be4363 /src/tools/moc/preprocessor.cpp | |
parent | 7db6aa4395541288ba790e5acdfad4a5cc5d4cd2 (diff) |
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 <fabian.kosmale@qt.io>
Diffstat (limited to 'src/tools/moc/preprocessor.cpp')
-rw-r--r-- | src/tools/moc/preprocessor.cpp | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp index f6d738aa56..45a7f72751 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<Parser::IncludePath> &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<Parser::IncludePath> &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<Parser::IncludePath> &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 |