From f8959aa759b337919cd482555b090a7bdfe2c29a Mon Sep 17 00:00:00 2001
From: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
Date: Mon, 7 Jun 2010 21:25:11 +0200
Subject: [PATCH] hide includes from within feature files

this fixes the recent appearance of qt_webkit_version.pri in all qt 4.7
based projects.

in fact, the patch does somewhat more: it makes the evaluator provide
the information to the higher layers which is necessary for a truly
hierarchical display of includes. TBD later.

Reviewed-by: dt
Task-number: QTCREATORBUG-1590
---
 .../qt4projectmanager/profilereader.cpp       | 15 ++++++--
 src/plugins/qt4projectmanager/profilereader.h |  4 +-
 src/shared/proparser/profileevaluator.cpp     | 37 +++++++++++--------
 src/shared/proparser/profileevaluator.h       |  4 +-
 4 files changed, 40 insertions(+), 20 deletions(-)

diff --git a/src/plugins/qt4projectmanager/profilereader.cpp b/src/plugins/qt4projectmanager/profilereader.cpp
index 3781fc37d0..ecd53ee51c 100644
--- a/src/plugins/qt4projectmanager/profilereader.cpp
+++ b/src/plugins/qt4projectmanager/profilereader.cpp
@@ -48,7 +48,8 @@ ProFileReader::~ProFileReader()
 bool ProFileReader::readProFile(const QString &fileName)
 {
     if (ProFile *pro = parsedProFile(fileName)) {
-        aboutToEval(pro);
+        m_ignoreLevel = 0;
+        aboutToEval(0, pro, EvalIncludeFile);
         bool ok = accept(pro);
         pro->deref();
         return ok;
@@ -56,15 +57,23 @@ bool ProFileReader::readProFile(const QString &fileName)
     return false;
 }
 
-void ProFileReader::aboutToEval(ProFile *pro)
+void ProFileReader::aboutToEval(ProFile *, ProFile *pro, EvalFileType type)
 {
-    if (!m_includeFiles.contains(pro->fileName())) {
+    if (m_ignoreLevel || type == EvalFeatureFile) {
+        m_ignoreLevel++;
+    } else if (!m_includeFiles.contains(pro->fileName())) {
         m_includeFiles.insert(pro->fileName(), pro);
         m_proFiles.append(pro);
         pro->ref();
     }
 }
 
+void ProFileReader::doneWithEval(ProFile *)
+{
+    if (m_ignoreLevel)
+        m_ignoreLevel--;
+}
+
 QList<ProFile*> ProFileReader::includeFiles() const
 {
     QString qmakeMkSpecDir = QFileInfo(propertyValue("QMAKE_MKSPECS")).absoluteFilePath();
diff --git a/src/plugins/qt4projectmanager/profilereader.h b/src/plugins/qt4projectmanager/profilereader.h
index b749bc3e56..1019be7870 100644
--- a/src/plugins/qt4projectmanager/profilereader.h
+++ b/src/plugins/qt4projectmanager/profilereader.h
@@ -58,7 +58,8 @@ signals:
     void errorFound(const QString &error);
 
 private:
-    virtual void aboutToEval(ProFile *proFile);
+    virtual void aboutToEval(ProFile *parent, ProFile *proFile, EvalFileType type);
+    virtual void doneWithEval(ProFile *parent);
     virtual void logMessage(const QString &msg);
     virtual void fileMessage(const QString &msg);
     virtual void errorMessage(const QString &msg);
@@ -66,6 +67,7 @@ private:
 private:
     QMap<QString, ProFile *> m_includeFiles;
     QList<ProFile *> m_proFiles;
+    int m_ignoreLevel;
 };
 
 class ProFileCacheManager : public QObject
diff --git a/src/shared/proparser/profileevaluator.cpp b/src/shared/proparser/profileevaluator.cpp
index b4788904b0..2da9257116 100644
--- a/src/shared/proparser/profileevaluator.cpp
+++ b/src/shared/proparser/profileevaluator.cpp
@@ -260,6 +260,7 @@ public:
     ProItem::ProItemReturn evaluateConditionalFunction(const QString &function, const QString &arguments);
     ProFile *parsedProFile(const QString &fileName, bool cache,
                            const QString &contents = QString());
+    bool evaluateFileDirect(const QString &fileName, ProFileEvaluator::EvalFileType type);
     bool evaluateFile(const QString &fileName);
     bool evaluateFeatureFile(const QString &fileName,
                              QHash<QString, QStringList> *values = 0, FunctionDefs *defs = 0);
@@ -3120,6 +3121,20 @@ ProFile *ProFileEvaluator::Private::parsedProFile(const QString &fileName, bool
     return pro;
 }
 
+bool ProFileEvaluator::Private::evaluateFileDirect(
+        const QString &fileName, ProFileEvaluator::EvalFileType type)
+{
+    if (ProFile *pro = parsedProFile(fileName, true)) {
+        q->aboutToEval(currentProFile(), pro, type);
+        bool ok = (visitProFile(pro) == ProItem::ReturnTrue);
+        q->doneWithEval(currentProFile());
+        pro->deref();
+        return ok;
+    } else {
+        return false;
+    }
+}
+
 bool ProFileEvaluator::Private::evaluateFile(const QString &fileName)
 {
     if (fileName.isEmpty())
@@ -3129,14 +3144,7 @@ bool ProFileEvaluator::Private::evaluateFile(const QString &fileName)
             errorMessage(format("circular inclusion of %1").arg(fileName));
             return false;
         }
-    if (ProFile *pro = parsedProFile(fileName, true)) {
-        q->aboutToEval(pro);
-        bool ok = (visitProFile(pro) == ProItem::ReturnTrue);
-        pro->deref();
-        return ok;
-    } else {
-        return false;
-    }
+    return evaluateFileDirect(fileName, ProFileEvaluator::EvalIncludeFile);
 }
 
 bool ProFileEvaluator::Private::evaluateFeatureFile(
@@ -3183,13 +3191,8 @@ bool ProFileEvaluator::Private::evaluateFeatureFile(
         bool cumulative = m_cumulative;
         m_cumulative = false;
 
-        // Don't use evaluateFile() here to avoid calling aboutToEval().
         // The path is fully normalized already.
-        bool ok = false;
-        if (ProFile *pro = parsedProFile(fn, true)) {
-            ok = (visitProFile(pro) == ProItem::ReturnTrue);
-            pro->deref();
-        }
+        bool ok = evaluateFileDirect(fn, ProFileEvaluator::EvalFeatureFile);
 
         m_cumulative = cumulative;
         return ok;
@@ -3371,7 +3374,11 @@ QString ProFileEvaluator::propertyValue(const QString &name) const
     return d->propertyValue(name);
 }
 
-void ProFileEvaluator::aboutToEval(ProFile *)
+void ProFileEvaluator::aboutToEval(ProFile *, ProFile *, EvalFileType)
+{
+}
+
+void ProFileEvaluator::doneWithEval(ProFile *)
 {
 }
 
diff --git a/src/shared/proparser/profileevaluator.h b/src/shared/proparser/profileevaluator.h
index 57df396d5a..d8202b65f7 100644
--- a/src/shared/proparser/profileevaluator.h
+++ b/src/shared/proparser/profileevaluator.h
@@ -94,7 +94,9 @@ public:
     QString propertyValue(const QString &val) const;
 
     // for our descendents
-    virtual void aboutToEval(ProFile *proFile); // only .pri, but not .prf. or .pro
+    enum EvalFileType { EvalFeatureFile, EvalIncludeFile };
+    virtual void aboutToEval(ProFile *parent, ProFile *proFile, EvalFileType type);
+    virtual void doneWithEval(ProFile *parent);
     virtual void logMessage(const QString &msg);
     virtual void errorMessage(const QString &msg); // .pro parse errors
     virtual void fileMessage(const QString &msg); // error() and message() from .pro file
-- 
GitLab