From 326463142b42b03c0e4c59069e099d6fd27212ce Mon Sep 17 00:00:00 2001 From: Topi Reinio Date: Fri, 24 May 2019 14:46:39 +0200 Subject: qdoc: Drop '-I' prefix from module header path Under certain conditions the '-I' prefixes survive in the list of resolved include paths. Fixes: QTBUG-76026 Change-Id: Ie3543b5aa8b88d8021175b3168ab8de8a4497878 Reviewed-by: Martin Smith Reviewed-by: Paul Wicking --- src/qdoc/clangcodeparser.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/qdoc/clangcodeparser.cpp') diff --git a/src/qdoc/clangcodeparser.cpp b/src/qdoc/clangcodeparser.cpp index 5bda5296b..87c9282ce 100644 --- a/src/qdoc/clangcodeparser.cpp +++ b/src/qdoc/clangcodeparser.cpp @@ -1226,6 +1226,8 @@ void ClangCodeParser::buildPCH() for (const auto &p : qAsConst(includePaths_)) { if (p.endsWith(module)) { QByteArray candidate = p + "/" + module; + if (p.startsWith("-I")) + candidate = candidate.mid(2); if (QFile::exists(QString::fromUtf8(candidate))) { header = candidate; break; -- cgit v1.2.1 From 50a172f8ad2891fe2e00e3d2ccd4f4536a73f9e4 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Fri, 31 May 2019 13:25:47 +0200 Subject: qdoc: Accept include paths without -I This update lets qdoc accept include paths with or without the -I and with or without a space between the -I and the path. Without the space is preferred. Task-number: QTBUG-74675 Change-Id: I4a1dcc04a3c9a6586e24b50bccf0f1f37d02ed4c Reviewed-by: Paul Wicking (cherry picked from commit e33ac6f1b1ebb882684f24f7d026267584d9393a) --- src/qdoc/clangcodeparser.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/qdoc/clangcodeparser.cpp') diff --git a/src/qdoc/clangcodeparser.cpp b/src/qdoc/clangcodeparser.cpp index 87c9282ce..407f67604 100644 --- a/src/qdoc/clangcodeparser.cpp +++ b/src/qdoc/clangcodeparser.cpp @@ -1021,8 +1021,19 @@ void ClangCodeParser::initializeParser(const Config &config) printParsingErrors_ = 1; version_ = config.getString(CONFIG_VERSION); const auto args = config.getStringList(CONFIG_INCLUDEPATHS); - includePaths_.resize(args.size()); - std::transform(args.begin(), args.end(), includePaths_.begin(), + QStringList squeezedArgs; + int i = 0; + while (i < args.size()) { + if (args.at(i) != QLatin1String("-I")) { + if (args.at(i).startsWith(QLatin1String("-I"))) + squeezedArgs << args.at(i); + else + squeezedArgs << QLatin1String("-I") + args.at(i); + } + i++; + } + includePaths_.resize(squeezedArgs.size()); + std::transform(squeezedArgs.begin(), squeezedArgs.end(), includePaths_.begin(), [](const QString &s) { return s.toUtf8(); }); CppCodeParser::initializeParser(config); pchFileDir_.reset(nullptr); -- cgit v1.2.1 From c7c3e2f26af0842631c95f054600b6b90ef3675b Mon Sep 17 00:00:00 2001 From: Topi Reinio Date: Fri, 7 Jun 2019 15:12:54 +0200 Subject: qdoc: Fix regressions in include path handling Commit 50a172f8 broke the way QDoc parses include paths passed from qdocconf files by always prepending them with '-I'. While this ensured that Clang uses them as include paths, QDoc no longer found module headers local to the documentation project as '-I/path/to/module' is never a valid file system path. This change fixes the issue and removes duplicated and unnecessary code. Fixes: QTBUG-76279 Change-Id: I7006000ec6be823afd10bae59eb88780ccf32b23 Reviewed-by: Martin Smith Reviewed-by: Paul Wicking --- src/qdoc/clangcodeparser.cpp | 115 +++++++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 54 deletions(-) (limited to 'src/qdoc/clangcodeparser.cpp') diff --git a/src/qdoc/clangcodeparser.cpp b/src/qdoc/clangcodeparser.cpp index 407f67604..76ac62897 100644 --- a/src/qdoc/clangcodeparser.cpp +++ b/src/qdoc/clangcodeparser.cpp @@ -1022,19 +1022,24 @@ void ClangCodeParser::initializeParser(const Config &config) version_ = config.getString(CONFIG_VERSION); const auto args = config.getStringList(CONFIG_INCLUDEPATHS); QStringList squeezedArgs; - int i = 0; - while (i < args.size()) { - if (args.at(i) != QLatin1String("-I")) { - if (args.at(i).startsWith(QLatin1String("-I"))) - squeezedArgs << args.at(i); - else - squeezedArgs << QLatin1String("-I") + args.at(i); - } - i++; + for (const auto &p : args) { + if (p.startsWith(QLatin1String("-I"))) + squeezedArgs << p.mid(2).trimmed(); + else + squeezedArgs << p; } + // Remove empty paths and duplicates + squeezedArgs.removeAll({}); + squeezedArgs.removeDuplicates(); includePaths_.resize(squeezedArgs.size()); std::transform(squeezedArgs.begin(), squeezedArgs.end(), includePaths_.begin(), - [](const QString &s) { return s.toUtf8(); }); + [](const QString &s) { + QByteArray path(s.toUtf8()); + QFileInfo fi(QDir::current(), s); + if (fi.exists()) + path = fi.canonicalFilePath().toUtf8(); + return path.prepend("-I"); + }); CppCodeParser::initializeParser(config); pchFileDir_.reset(nullptr); allHeaders_.clear(); @@ -1206,14 +1211,6 @@ bool ClangCodeParser::getMoreArgs() moreArgs_ = includePaths_; } - // Canonicalize include paths - for (int i = 0; i < moreArgs_.size(); ++i) { - if (!moreArgs_.at(i).startsWith("-")) { - QFileInfo fi(QDir::current(), moreArgs_[i]); - if (fi.exists()) - moreArgs_[i] = fi.canonicalFilePath().toLatin1(); - } - } return guessedIncludePaths; } @@ -1232,49 +1229,59 @@ void ClangCodeParser::buildPCH() QByteArray header; QByteArray privateHeaderDir; Location::logToStdErrAlways("Build & visit PCH for " + moduleHeader()); - // Find the path to the module's header (e.g. QtGui/QtGui) to be used - // as pre-compiled header - for (const auto &p : qAsConst(includePaths_)) { - if (p.endsWith(module)) { - QByteArray candidate = p + "/" + module; - if (p.startsWith("-I")) - candidate = candidate.mid(2); - if (QFile::exists(QString::fromUtf8(candidate))) { - header = candidate; + // A predicate for std::find_if() to locate a path to the module's header + // (e.g. QtGui/QtGui) to be used as pre-compiled header + struct FindPredicate { + enum SearchType { Any, Module, Private }; + QByteArray &candidate_; + const QByteArray &module_; + SearchType type_; + FindPredicate(QByteArray &candidate, const QByteArray &module, SearchType type = Any) + : candidate_(candidate), module_(module), type_(type) {} + + bool operator()(const QByteArray &p) const { + if (type_ != Any && !p.endsWith(module_)) + return false; + candidate_ = p + "/"; + switch (type_) { + case Any: + case Module: + candidate_.append(module_); break; - } - } - } - if (header.isEmpty()) { - for (const auto &p : qAsConst(includePaths_)) { - QByteArray candidate = p + "/" + module; - if (QFile::exists(QString::fromUtf8(candidate))) { - header = candidate; + case Private: + candidate_.append("private"); break; - } - } - } - // Find the path to the module's private header directory (e.g. - // include/QtGui/5.8.0/QtGui/private) to use for including all - // the private headers in the PCH. - for (const auto &p : qAsConst(includePaths_)) { - if (p.endsWith(module)) { - QByteArray candidate = p + "/private"; - if (QFile::exists(QString::fromUtf8(candidate))) { - privateHeaderDir = candidate; + default: break; } + if (p.startsWith("-I")) + candidate_ = candidate_.mid(2); + return QFile::exists(QString::fromUtf8(candidate_)); } - } - if (header.isEmpty()) { - QByteArray installDocDir = Config::installDir.toUtf8(); - const QByteArray candidate = installDocDir + "/../include/" + module + "/" + module; - if (QFile::exists(QString::fromUtf8(candidate))) - header = candidate; - } + }; + + // First, search for an include path that contains the module name, then any path + QByteArray candidate; + auto it = std::find_if(includePaths_.begin(), + includePaths_.end(), + FindPredicate(candidate, module, FindPredicate::Module)); + if (it == includePaths_.end()) + it = std::find_if(includePaths_.begin(), + includePaths_.end(), + FindPredicate(candidate, module, FindPredicate::Any)); + if (it != includePaths_.end()) + header = candidate; + + // Find the path to module's private headers - currently unused + it = std::find_if(includePaths_.begin(), + includePaths_.end(), + FindPredicate(candidate, module, FindPredicate::Private)); + if (it != includePaths_.end()) + privateHeaderDir = candidate; + if (header.isEmpty()) { qWarning() << "(qdoc) Could not find the module header in the include path for module" - << module << " (include paths: "<< includePaths_ << ")"; + << module << " (include paths: " << includePaths_ << ")"; } else { args_.push_back("-xc++"); CXTranslationUnit tu; -- cgit v1.2.1 From cc9250477eaa71a3f3ffd050591d4a9d835288ca Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Thu, 6 Jun 2019 13:56:02 +0200 Subject: qdoc: Don't log guessed include paths A complaint about excessive logging was received because of the logging of each guessed include path when qdoc is not given any include paths at all. This update removes the logging of those lines and changes the remaining single log line to: No include paths passed to qdoc; guessing reasonable include paths Task-number: QTBUG-76204 Change-Id: I000ee7959f00f654e750ac1b68a0c2b6dcccd472 Reviewed-by: Fabian Vogt Reviewed-by: Paul Wicking (cherry picked from commit 8e3c53a196f66a1c9a370cda1dfde51792f92364) Reviewed-by: Martin Smith --- src/qdoc/clangcodeparser.cpp | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'src/qdoc/clangcodeparser.cpp') diff --git a/src/qdoc/clangcodeparser.cpp b/src/qdoc/clangcodeparser.cpp index 76ac62897..091df221e 100644 --- a/src/qdoc/clangcodeparser.cpp +++ b/src/qdoc/clangcodeparser.cpp @@ -1181,13 +1181,12 @@ bool ClangCodeParser::getMoreArgs() { bool guessedIncludePaths = false; if (includePaths_.isEmpty()) { - Location::logToStdErrAlways("No include paths passed to qdoc"); - Location::logToStdErrAlways("Guess reasonable include paths:"); /* The include paths provided are inadequate. Make a list of reasonable places to look for include files and use that list instead. */ + Location::logToStdErrAlways("No include paths passed to qdoc; guessing reasonable include paths"); guessedIncludePaths = true; auto forest = qdb_->searchOrder(); @@ -1195,17 +1194,6 @@ bool ClangCodeParser::getMoreArgs() QString basicIncludeDir = QDir::cleanPath(QString(Config::installDir + "/../include")); moreArgs_ += "-I" + basicIncludeDir.toLatin1(); moreArgs_ += includePathsFromHeaders(allHeaders_); - for (const auto p : moreArgs_) { - Location::logToStdErrAlways(p); - } -#if 0 - for (const auto &s : forest) { - QString module = basicIncludeDir +"/" + s->camelCaseModuleName(); - moreArgs_ += QString("-I" + module).toLatin1(); - moreArgs_ += QString("-I" + module + "/" + qdb_->version()).toLatin1(); - moreArgs_ += QString("-I" + module + "/" + qdb_->version() + "/" + module).toLatin1(); - } -#endif } else { moreArgs_ = includePaths_; -- cgit v1.2.1