From 27bced7694a593eca555bf4cc46c084ba9302f2d Mon Sep 17 00:00:00 2001
From: Topi Reinio <topi.reinio@theqtcompany.com>
Date: Wed, 11 May 2016 14:40:26 +0200
Subject: [PATCH] qdoc: Allow example files to be excluded

Documentation configuration variables 'excludedirs' and 'excludefiles'
had no effect on what source and image files were listed as belonging
to an example.

This commit fixes that, and refactors excludedirs/files handling:
Remove duplicated code blocks, amd simplify the code reading the
variables:

  - Drop checks whether an excluded directory exists
  - Drop conversion of native separators for excluded paths

Both are unnecessary; QDoc expects '/'-separated paths for many other
variables, and if an excluded dir does not exist, it won't exclude
anything.

Change-Id: Ie25511e20d33888653c23bb84975368317eb4306
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Reviewed-by: Martin Smith <martin.smith@theqtcompany.com>
---
 src/qdoc/cppcodeparser.cpp | 14 +++++--
 src/qdoc/cppcodeparser.h   |  2 +
 src/qdoc/main.cpp          | 77 ++++++++------------------------------
 3 files changed, 28 insertions(+), 65 deletions(-)

diff --git a/src/qdoc/cppcodeparser.cpp b/src/qdoc/cppcodeparser.cpp
index c1295c3a7..61fb9b7d7 100644
--- a/src/qdoc/cppcodeparser.cpp
+++ b/src/qdoc/cppcodeparser.cpp
@@ -54,6 +54,8 @@ static bool inMacroCommand_ = false;
 static bool parsingHeaderFile_ = false;
 QStringList CppCodeParser::exampleFiles;
 QStringList CppCodeParser::exampleDirs;
+QSet<QString> CppCodeParser::excludeDirs;
+QSet<QString> CppCodeParser::excludeFiles;
 CppCodeParser* CppCodeParser::cppParser_ = 0;
 
 /*!
@@ -78,7 +80,7 @@ CppCodeParser::~CppCodeParser()
 /*!
   The constructor initializes a map of special node types
   for identifying important nodes. And it initializes
-  some filters for identifying certain kinds of files.
+  some filters for identifying and excluding certain kinds of files.
  */
 void CppCodeParser::initializeParser(const Config &config)
 {
@@ -100,6 +102,10 @@ void CppCodeParser::initializeParser(const Config &config)
     QStringList exampleFilePatterns = config.getStringList(
                 CONFIG_EXAMPLES + Config::dot + CONFIG_FILEEXTENSIONS);
 
+    // Used for excluding dirs and files from the list of example files
+    excludeDirs = QSet<QString>::fromList(config.getCanonicalPathList(CONFIG_EXCLUDEDIRS));
+    excludeFiles = QSet<QString>::fromList(config.getCanonicalPathList(CONFIG_EXCLUDEFILES));
+
     if (!exampleFilePatterns.isEmpty())
         exampleNameFilter = exampleFilePatterns.join(' ');
     else
@@ -121,6 +127,8 @@ void CppCodeParser::initializeParser(const Config &config)
 void CppCodeParser::terminateParser()
 {
     nodeTypeMap.clear();
+    excludeDirs.clear();
+    excludeFiles.clear();
     CodeParser::terminateParser();
 }
 
@@ -2643,9 +2651,9 @@ void CppCodeParser::createExampleFileNodes(DocumentNode *dn)
         sizeOfBoringPartOfName = sizeOfBoringPartOfName - 2;
     fullPath.truncate(fullPath.lastIndexOf('/'));
 
-    QStringList exampleFiles = Config::getFilesHere(fullPath,exampleNameFilter);
+    QStringList exampleFiles = Config::getFilesHere(fullPath, exampleNameFilter, Location(), excludeDirs, excludeFiles);
     QString imagesPath = fullPath + "/images";
-    QStringList imageFiles = Config::getFilesHere(imagesPath,exampleImageFilter);
+    QStringList imageFiles = Config::getFilesHere(imagesPath, exampleImageFilter, Location(), excludeDirs, excludeFiles);
     if (!exampleFiles.isEmpty()) {
         // move main.cpp and to the end, if it exists
         QString mainCpp;
diff --git a/src/qdoc/cppcodeparser.h b/src/qdoc/cppcodeparser.h
index d3a5829e3..3910807ab 100644
--- a/src/qdoc/cppcodeparser.h
+++ b/src/qdoc/cppcodeparser.h
@@ -179,6 +179,8 @@ protected:
 
     static QStringList exampleFiles;
     static QStringList exampleDirs;
+    static QSet<QString> excludeDirs;
+    static QSet<QString> excludeFiles;
     static CppCodeParser* cppParser_;
     QString exampleNameFilter;
     QString exampleImageFilter;
diff --git a/src/qdoc/main.cpp b/src/qdoc/main.cpp
index 500a085cc..990207204 100644
--- a/src/qdoc/main.cpp
+++ b/src/qdoc/main.cpp
@@ -365,31 +365,26 @@ static void processQdocconfFile(const QString &fileName)
                                                      + Config::dot
                                                      + CONFIG_LANDINGPAGE));
 
-    QSet<QString> excludedDirs;
-    QSet<QString> excludedFiles;
-    QStringList excludedDirsList;
-    QStringList excludedFilesList;
+    QSet<QString> excludedDirs = QSet<QString>::fromList(config.getCanonicalPathList(CONFIG_EXCLUDEDIRS));
+    QSet<QString> excludedFiles = QSet<QString>::fromList(config.getCanonicalPathList(CONFIG_EXCLUDEFILES));
+
+    Generator::debug("Adding doc/image dirs found in exampledirs to imagedirs");
+    QSet<QString> exampleImageDirs;
+    QStringList exampleImageList = config.getExampleImageFiles(excludedDirs, excludedFiles);
+    for (int i = 0; i < exampleImageList.size(); ++i) {
+        if (exampleImageList[i].contains("doc/images")) {
+            QString t = exampleImageList[i].left(exampleImageList[i].lastIndexOf("doc/images") + 10);
+            if (!exampleImageDirs.contains(t)) {
+                exampleImageDirs.insert(t);
+            }
+        }
+    }
+    Generator::augmentImageDirs(exampleImageDirs);
 
     if (!Generator::singleExec() || !Generator::generating()) {
         QStringList headerList;
         QStringList sourceList;
 
-        Generator::debug("Reading excludedirs");
-        excludedDirsList = config.getCanonicalPathList(CONFIG_EXCLUDEDIRS);
-        foreach (const QString &excludeDir, excludedDirsList) {
-            QString p = QDir::fromNativeSeparators(excludeDir);
-            QDir tmp(p);
-            if (tmp.exists())
-                excludedDirs.insert(p);
-        }
-
-        Generator::debug("Reading excludefiles");
-        excludedFilesList = config.getCanonicalPathList(CONFIG_EXCLUDEFILES);
-        foreach (const QString& excludeFile, excludedFilesList) {
-            QString p = QDir::fromNativeSeparators(excludeFile);
-            excludedFiles.insert(p);
-        }
-
         Generator::debug("Reading headerdirs");
         headerList = config.getAllFiles(CONFIG_HEADERS,CONFIG_HEADERDIRS,excludedDirs,excludedFiles);
         QMap<QString,QString> headers;
@@ -430,20 +425,6 @@ static void processQdocconfFile(const QString &fileName)
                 sourceFileNames.insert(t,t);
             }
         }
-
-        Generator::debug("Adding doc/image dirs found in exampledirs to imagedirs");
-        QSet<QString> exampleImageDirs;
-        QStringList exampleImageList = config.getExampleImageFiles(excludedDirs, excludedFiles);
-        for (int i=0; i<exampleImageList.size(); ++i) {
-            if (exampleImageList[i].contains("doc/images")) {
-                QString t = exampleImageList[i].left(exampleImageList[i].lastIndexOf("doc/images")+10);
-                if (!exampleImageDirs.contains(t)) {
-                    exampleImageDirs.insert(t);
-                }
-            }
-        }
-        Generator::augmentImageDirs(exampleImageDirs);
-
         /*
           Parse each header file in the set using the appropriate parser and add it
           to the big tree.
@@ -504,34 +485,6 @@ static void processQdocconfFile(const QString &fileName)
         qdb->resolveIssues();
     }
     else {
-        Generator::debug("Reading excludedirs");
-        excludedDirsList = config.getCanonicalPathList(CONFIG_EXCLUDEDIRS);
-        foreach (const QString &excludeDir, excludedDirsList) {
-            QString p = QDir::fromNativeSeparators(excludeDir);
-            QDir tmp(p);
-            if (tmp.exists())
-                excludedDirs.insert(p);
-        }
-
-        Generator::debug("Reading excludefiles");
-        excludedFilesList = config.getCanonicalPathList(CONFIG_EXCLUDEFILES);
-        foreach (const QString& excludeFile, excludedFilesList) {
-            QString p = QDir::fromNativeSeparators(excludeFile);
-            excludedFiles.insert(p);
-        }
-
-        Generator::debug("Adding doc/image dirs found in exampledirs to imagedirs");
-        QSet<QString> exampleImageDirs;
-        QStringList exampleImageList = config.getExampleImageFiles(excludedDirs, excludedFiles);
-        for (int i=0; i<exampleImageList.size(); ++i) {
-            if (exampleImageList[i].contains("doc/images")) {
-                QString t = exampleImageList[i].left(exampleImageList[i].lastIndexOf("doc/images")+10);
-                if (!exampleImageDirs.contains(t)) {
-                    exampleImageDirs.insert(t);
-                }
-            }
-        }
-        Generator::augmentImageDirs(exampleImageDirs);
         qdb->resolveStuff();
     }
 
-- 
GitLab