From 02265f9bbc213d219afc345594307affb900e07e Mon Sep 17 00:00:00 2001 From: Venugopal Shivashankar Date: Mon, 16 Mar 2020 15:08:20 +0100 Subject: qdoc: Extend \example command to consider CMake projects QDoc looks for project file(s) in the example directories before generating docs for the example. Now that we are moving towards CMake, it's ideal that qdoc is aware of this new project file type. Refactor the code that looks for project files - add a new function to Config for this purpose, and store the project file name into ExampleNode. This allows removal of duplicated logic when generating the example-manifest.xml file. Add a unit test for Config::getExampleProjectFile(), and modify the generatedoutput test to cover output for a CMake-based example. [ChangeLog][qdoc] Added support for CMake-based example projects. Fixes: QTBUG-82908 Change-Id: If9f061c613fee94b35df277043c2f4df93da7ec0 Reviewed-by: Paul Wicking --- src/qdoc/cppcodeparser.cpp | 74 ++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 52 deletions(-) (limited to 'src/qdoc/cppcodeparser.cpp') diff --git a/src/qdoc/cppcodeparser.cpp b/src/qdoc/cppcodeparser.cpp index 647631c27..ed12f64c2 100644 --- a/src/qdoc/cppcodeparser.cpp +++ b/src/qdoc/cppcodeparser.cpp @@ -48,8 +48,6 @@ QT_BEGIN_NAMESPACE /* qmake ignore Q_OBJECT */ -QStringList CppCodeParser::exampleFiles; -QStringList CppCodeParser::exampleDirs; QSet CppCodeParser::excludeDirs; QSet CppCodeParser::excludeFiles; @@ -120,8 +118,6 @@ void CppCodeParser::initializeParser() nodeTypeTestFuncMap_.insert(COMMAND_VARIABLE, &Node::isVariable); Config &config = Config::instance(); - exampleFiles = config.getCanonicalPathList(CONFIG_EXAMPLES); - exampleDirs = config.getCanonicalPathList(CONFIG_EXAMPLEDIRS); QStringList exampleFilePatterns = config.getStringList(CONFIG_EXAMPLES + Config::dot + CONFIG_FILEEXTENSIONS); @@ -771,58 +767,29 @@ FunctionNode *CppCodeParser::parseMacroArg(const Location &location, const QStri return macro; } -void CppCodeParser::setExampleFileLists(PageNode *pn) +void CppCodeParser::setExampleFileLists(ExampleNode *en) { - QString examplePath = pn->name(); - QString proFileName = - examplePath + QLatin1Char('/') + examplePath.split(QLatin1Char('/')).last() + ".pro"; - QString fullPath = - Config::findFile(pn->doc().location(), exampleFiles, exampleDirs, proFileName); - + Config &config = Config::instance(); + QString fullPath = config.getExampleProjectFile(en->name()); if (fullPath.isEmpty()) { - QString tmp = proFileName; - proFileName = examplePath + QLatin1Char('/') + "qbuild.pro"; - fullPath = Config::findFile(pn->doc().location(), exampleFiles, exampleDirs, proFileName); - if (fullPath.isEmpty()) { - proFileName = examplePath + QLatin1Char('/') - + examplePath.split(QLatin1Char('/')).last() + ".qmlproject"; - fullPath = - Config::findFile(pn->doc().location(), exampleFiles, exampleDirs, proFileName); - if (fullPath.isEmpty()) { - proFileName = examplePath + QLatin1Char('/') - + examplePath.split(QLatin1Char('/')).last() + ".pyproject"; - fullPath = Config::findFile(pn->doc().location(), exampleFiles, exampleDirs, - proFileName); - if (fullPath.isEmpty()) { - QString details = QLatin1String("Example directories: ") - + exampleDirs.join(QLatin1Char(' ')); - if (!exampleFiles.isEmpty()) - details += QLatin1String(", example files: ") - + exampleFiles.join(QLatin1Char(' ')); - pn->location().warning( - tr("Cannot find file '%1' or '%2'").arg(tmp).arg(proFileName), details); - pn->location().warning(tr(" EXAMPLE PATH DOES NOT EXIST: %1").arg(examplePath), - details); - return; - } - } - } + QString details = QLatin1String("Example directories: ") + + config.getCanonicalPathList(CONFIG_EXAMPLEDIRS).join(QLatin1Char(' ')); + en->location().warning( + tr("Cannot find project file for example '%1'").arg(en->name()), details); + return; } - int sizeOfBoringPartOfName = fullPath.size() - proFileName.size(); - if (fullPath.startsWith("./")) - sizeOfBoringPartOfName = sizeOfBoringPartOfName - 2; - fullPath.truncate(fullPath.lastIndexOf('/')); + QDir exampleDir(QFileInfo(fullPath).dir()); - QStringList exampleFiles = Config::getFilesHere(fullPath, exampleNameFilter, Location(), + QStringList exampleFiles = Config::getFilesHere(exampleDir.path(), exampleNameFilter, Location(), excludeDirs, excludeFiles); // Search for all image files under the example project, excluding doc/images directory. QSet excludeDocDirs(excludeDirs); - excludeDocDirs.insert(QDir(fullPath).canonicalPath() + "/doc/images"); - QStringList imageFiles = Config::getFilesHere(fullPath, exampleImageFilter, Location(), + excludeDocDirs.insert(exampleDir.path() + QLatin1String("/doc/images")); + QStringList imageFiles = Config::getFilesHere(exampleDir.path(), exampleImageFilter, Location(), excludeDocDirs, excludeFiles); if (!exampleFiles.isEmpty()) { - // move main.cpp and to the end, if it exists + // move main.cpp to the end, if it exists QString mainCpp; const auto isGeneratedOrMainCpp = [&mainCpp](const QString &fileName) { @@ -842,16 +809,19 @@ void CppCodeParser::setExampleFileLists(PageNode *pn) if (!mainCpp.isEmpty()) exampleFiles.append(mainCpp); - // add any qmake Qt resource files and qmake project files - exampleFiles += Config::getFilesHere(fullPath, "*.qrc *.pro *.qmlproject qmldir"); + // Add any resource and project files + exampleFiles += Config::getFilesHere(exampleDir.path(), + QLatin1String("*.qrc *.pro *.qmlproject *.pyproject CMakeLists.txt qmldir")); } + exampleDir.cdUp(); + int pathLen = exampleDir.path().size() + 1; for (auto &file : exampleFiles) - file = file.mid(sizeOfBoringPartOfName); + file = file.mid(pathLen); for (auto &file : imageFiles) - file = file.mid(sizeOfBoringPartOfName); - ExampleNode *en = static_cast(pn); - en->setFiles(exampleFiles); + file = file.mid(pathLen); + + en->setFiles(exampleFiles, fullPath.mid(pathLen)); en->setImages(imageFiles); } -- cgit v1.2.1 From 920ffd21b15f79c47cc18b69344a90836e100005 Mon Sep 17 00:00:00 2001 From: Paul Wicking Date: Wed, 11 Mar 2020 12:22:42 +0100 Subject: QDoc: Remove commented out code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ie3c74010c62fa6c468732364bd1be77024fcca5b Reviewed-by: Topi Reiniƶ --- src/qdoc/cppcodeparser.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/qdoc/cppcodeparser.cpp') diff --git a/src/qdoc/cppcodeparser.cpp b/src/qdoc/cppcodeparser.cpp index ed12f64c2..065032024 100644 --- a/src/qdoc/cppcodeparser.cpp +++ b/src/qdoc/cppcodeparser.cpp @@ -531,7 +531,6 @@ void CppCodeParser::processMetaCommand(const Doc &doc, const QString &command, doc.location().warning(tr("Invalid '\\%1' not allowed in '\\%2'") .arg(COMMAND_RELATES, node->nodeTypeString())); } else if (!node->isRelatedNonmember() && - //!node->parent()->name().isEmpty() && !node->parent()->isNamespace() && !node->parent()->isHeader()) { if (!doc.isInternal()) { doc.location().warning(tr("Invalid '\\%1' ('%2' must be global)") -- cgit v1.2.1 From 739e404eee420257f217001c5df753585b8a9031 Mon Sep 17 00:00:00 2001 From: Topi Reinio Date: Fri, 27 Mar 2020 12:58:49 +0100 Subject: qdoc: Fix regression in resolved example file paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A recent refactoring of code related to generation of example file lists caused a regression; if the parameter passed to an \example command contained subdirectories, e.g. \example tutorials/gettingstarted only the immediate example directory ('gettingstarted' above) was recorded in generated example lists and manifest files. Ensure that the file paths are prefixed with the full example location, and add a test to cover this. Fixes: QTBUG-83130 Change-Id: I061dcf6cd4e94a2c65e5a50a39f379759d7cd06f Reviewed-by: Topi Reiniƶ --- src/qdoc/cppcodeparser.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/qdoc/cppcodeparser.cpp') diff --git a/src/qdoc/cppcodeparser.cpp b/src/qdoc/cppcodeparser.cpp index 065032024..5248c990d 100644 --- a/src/qdoc/cppcodeparser.cpp +++ b/src/qdoc/cppcodeparser.cpp @@ -813,8 +813,7 @@ void CppCodeParser::setExampleFileLists(ExampleNode *en) QLatin1String("*.qrc *.pro *.qmlproject *.pyproject CMakeLists.txt qmldir")); } - exampleDir.cdUp(); - int pathLen = exampleDir.path().size() + 1; + const int pathLen = exampleDir.path().size() - en->name().size(); for (auto &file : exampleFiles) file = file.mid(pathLen); for (auto &file : imageFiles) -- cgit v1.2.1