diff options
author | Martin Smith <martin.smith@qt.io> | 2018-10-19 12:09:45 +0200 |
---|---|---|
committer | Martin Smith <martin.smith@qt.io> | 2018-10-23 14:15:44 +0000 |
commit | 76cdf802b7333b037d005b75a2cb7f3623359335 (patch) | |
tree | cef28c00abec30e0253ab4d917b6e89ba6fe1d6a | |
parent | 876ded011508fff3cb029f3a4b7545364c9eaeff (diff) |
qdoc: Accept all #include lines in module header
qdoc was building a temporary module header by copying in the actual
module header and then following it with includes for all the private
headers in the module's private include directory. But this attempt
to include headers that end in "_p.h" didn't include any headers at
all, so that code is removed in this update.
The problem with just copying the entire module heaqder into the
temporary module header was that some of the #include lines that
qdoc needed to see were not parsed by clang because they were
surreounded by #if QT_CONFIG(feature) if the feature wasn't
present for the Qt build.
Instead of copying the module header to the tempory module header,
this update changes it to read the module header line by line and
write each #include to the temporary module header, including the
ones that are surrounded by QT_CONFIG(feature):
_#if QT_CONFIG(dtls)
_#include "qdtls.h"
_#endif
This reduces the qdoc error count, but the example above causes a
static assert when the dtls feature is not present. So this must
be added as well:
_#ifndef Q_CLANG_QDOC
QT_REQUIRE_CONFIG(dtls);
_#endif
Change-Id: I7fe26b5b714d41654a2cfdda19b8fe4b31999b91
Reviewed-by: Martin Smith <martin.smith@qt.io>
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
-rw-r--r-- | src/qdoc/clangcodeparser.cpp | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/src/qdoc/clangcodeparser.cpp b/src/qdoc/clangcodeparser.cpp index fdf56d073..e3ebece2e 100644 --- a/src/qdoc/clangcodeparser.cpp +++ b/src/qdoc/clangcodeparser.cpp @@ -1245,23 +1245,19 @@ void ClangCodeParser::buildPCH() args_.push_back("-xc++"); CXTranslationUnit tu; QString tmpHeader = pchFileDir_->path() + "/" + module; - if (QFile::copy(header, tmpHeader) && !privateHeaderDir.isEmpty()) { - privateHeaderDir = QDir::cleanPath(privateHeaderDir.constData()).toLatin1(); - const char *const headerPath = privateHeaderDir.constData(); - const QStringList pheaders = QDir(headerPath).entryList(); - QFile tmpHeaderFile(tmpHeader); - if (tmpHeaderFile.open(QIODevice::Text | QIODevice::Append)) { - for (const QString &phead : pheaders) { - if (phead.endsWith("_p.h")) { - QByteArray entry; - entry = "#include \""; - entry += headerPath; - entry += '/'; - entry += phead.toLatin1(); - entry += "\"\n"; - tmpHeaderFile.write(entry); - } - } + QFile tmpHeaderFile(tmpHeader); + if (tmpHeaderFile.open(QIODevice::Text | QIODevice::WriteOnly)) { + QFile headerFile(header); + if (!headerFile.open(QFile::ReadOnly)) { + qWarning() << "Could not read module header file" << header; + return; + } + QTextStream in(&headerFile); + QTextStream out(&tmpHeaderFile); + while (!in.atEnd()) { + QString line = in.readLine().simplified(); + if (line.startsWith(QLatin1String("#include"))) + out << line << "\n"; } } if (printParsingErrors_ == 0) |