From 5a9a24fa3d16543e123cee44a3f5e46f98e1bb98 Mon Sep 17 00:00:00 2001
From: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Date: Wed, 26 Nov 2014 17:37:42 +0100
Subject: [PATCH] move postprocessing of INCLUDEPATH into
 ProFileEvaluator::accept()

the rationale is that postprocessing which is done by the generators (in
some cases right at the point of emitting code to the makefile) should
be abstracted inside the "medium-level" class which also does the path
resolution done by the generators.

along the way we also make minor fixes to the processing:
- we pay attention to CONFIG+=no_include_pwd
- we add the build dir as well when shadow building

Change-Id: Ib389942fdc0470e05c1aa49e3615b6ac00241662
Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
---
 .../qmakeprojectmanager/qmakenodes.cpp        | 11 --------
 src/plugins/qmakeprojectmanager/qmakenodes.h  |  2 --
 .../qmakeprojectmanager/qmakeproject.cpp      |  4 ---
 src/shared/proparser/profileevaluator.cpp     | 25 ++++++++++++++-----
 src/shared/proparser/profileevaluator.h       |  2 --
 5 files changed, 19 insertions(+), 25 deletions(-)

diff --git a/src/plugins/qmakeprojectmanager/qmakenodes.cpp b/src/plugins/qmakeprojectmanager/qmakenodes.cpp
index 4061182796..6e3a31f5c9 100644
--- a/src/plugins/qmakeprojectmanager/qmakenodes.cpp
+++ b/src/plugins/qmakeprojectmanager/qmakenodes.cpp
@@ -231,7 +231,6 @@ public:
     QStringList newProjectFilesCumlative;
     ProFile *fileForCurrentProjectCumlative; // probably only used in parser thread
     TargetInformation targetInformation;
-    QString resolvedMkspecPath;
     InstallsList installsList;
     QHash<QmakeVariable, QStringList> newVarValues;
     bool isDeployable;
@@ -1892,7 +1891,6 @@ EvalResult *QmakeProFileNode::evaluate(const EvalInput &input)
             }
         }
         result->targetInformation = targetInformation(input.readerExact, readerBuildPass, input.buildDirectory, input.projectFilePath);
-        result->resolvedMkspecPath = input.readerExact->resolvedMkSpec();
         result->installsList = installsList(readerBuildPass, input.projectFilePath, input.projectDir);
 
         // update other variables
@@ -2237,7 +2235,6 @@ void QmakeProFileNode::applyEvaluate(EvalResult *evalResult)
     if (m_validParse) {
         // update TargetInformation
         m_qmakeTargetInformation = result->targetInformation;
-        m_resolvedMkspecPath = result->resolvedMkspecPath;
 
         m_subProjectsNotToDeploy = result->subProjectsNotToDeploy;
         m_installsList = result->installsList;
@@ -2317,13 +2314,10 @@ QStringList QmakeProFileNode::includePaths(QtSupport::ProFileReader *reader, con
     }
 
     paths.append(reader->absolutePathValues(QLatin1String("INCLUDEPATH"), projectDir));
-    paths.append(reader->absolutePathValues(QLatin1String("QMAKE_INCDIR"), projectDir));
     // paths already contains moc dir and ui dir, due to corrrectly parsing uic.prf and moc.prf
     // except if those directories don't exist at the time of parsing
     // thus we add those directories manually (without checking for existence)
     paths << mocDirPath(reader, buildDir) << uiDirPath(reader, buildDir);
-    // qmake always adds "."
-    paths << projectDir;
     paths.removeDuplicates();
     return paths;
 }
@@ -2427,11 +2421,6 @@ TargetInformation QmakeProFileNode::targetInformation() const
     return m_qmakeTargetInformation;
 }
 
-QString QmakeProFileNode::resolvedMkspecPath() const
-{
-    return m_resolvedMkspecPath;
-}
-
 InstallsList QmakeProFileNode::installsList(const QtSupport::ProFileReader *reader, const QString &projectFilePath, const QString &projectDir)
 {
     InstallsList result;
diff --git a/src/plugins/qmakeprojectmanager/qmakenodes.h b/src/plugins/qmakeprojectmanager/qmakenodes.h
index 8b7d9a33b2..7c45c98f5f 100644
--- a/src/plugins/qmakeprojectmanager/qmakenodes.h
+++ b/src/plugins/qmakeprojectmanager/qmakenodes.h
@@ -415,7 +415,6 @@ public:
     QString objectsDirectory() const;
     QByteArray cxxDefines() const;
     bool isDeployable() const;
-    QString resolvedMkspecPath() const;
 
     enum AsyncUpdateDelay { ParseNow, ParseLater };
     void scheduleUpdate(AsyncUpdateDelay delay);
@@ -473,7 +472,6 @@ private:
 
     QMap<QString, QDateTime> m_uitimestamps;
     TargetInformation m_qmakeTargetInformation;
-    QString m_resolvedMkspecPath;
     QStringList m_subProjectsNotToDeploy;
     InstallsList m_installsList;
 
diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.cpp b/src/plugins/qmakeprojectmanager/qmakeproject.cpp
index 77efbcb1bd..5bf18ed002 100644
--- a/src/plugins/qmakeprojectmanager/qmakeproject.cpp
+++ b/src/plugins/qmakeprojectmanager/qmakeproject.cpp
@@ -538,10 +538,6 @@ void QmakeProject::updateCppCodeModel()
             }
         }
 
-        if (QmakeProFileNode *node = rootQmakeProjectNode())
-            templatePart->headerPaths += ProjectPart::HeaderPath(node->resolvedMkspecPath(),
-                                                         ProjectPart::HeaderPath::IncludePath);
-
         // part->precompiledHeaders
         templatePart->precompiledHeaders.append(pro->variableValue(PrecompiledHeaderVar));
 
diff --git a/src/shared/proparser/profileevaluator.cpp b/src/shared/proparser/profileevaluator.cpp
index 8252e4ba2c..4c9df0926a 100644
--- a/src/shared/proparser/profileevaluator.cpp
+++ b/src/shared/proparser/profileevaluator.cpp
@@ -197,7 +197,25 @@ bool ProFileEvaluator::loadNamedSpec(const QString &specDir, bool hostSpec)
 
 bool ProFileEvaluator::accept(ProFile *pro, QMakeEvaluator::LoadFlags flags)
 {
-    return d->visitProFile(pro, QMakeHandler::EvalProjectFile, flags) == QMakeEvaluator::ReturnTrue;
+    if (d->visitProFile(pro, QMakeHandler::EvalProjectFile, flags) != QMakeEvaluator::ReturnTrue)
+        return false;
+
+    if (flags & QMakeEvaluator::LoadPostFiles) {
+        // This is postprocessing which is hard-coded inside qmake's generators.
+
+        ProStringList &incpath = d->valuesRef(ProKey("INCLUDEPATH"));
+        incpath += d->values(ProKey("QMAKE_INCDIR"));
+        if (!d->isActiveConfig(QStringLiteral("no_include_pwd"))) {
+            incpath.prepend(ProString(pro->directoryName()));
+            // It's pretty stupid that this is appended - it should be the second entry.
+            if (pro->directoryName() != d->m_outputDir)
+                incpath << ProString(d->m_outputDir);
+        }
+        // The location of this is inconsistent among generators.
+        incpath << ProString(d->m_qmakespec);
+    }
+
+    return true;
 }
 
 QString ProFileEvaluator::propertyValue(const QString &name) const
@@ -205,11 +223,6 @@ QString ProFileEvaluator::propertyValue(const QString &name) const
     return d->m_option->propertyValue(ProKey(name)).toQString();
 }
 
-QString ProFileEvaluator::resolvedMkSpec() const
-{
-    return d->m_qmakespec;
-}
-
 #ifdef PROEVALUATOR_CUMULATIVE
 void ProFileEvaluator::setCumulative(bool on)
 {
diff --git a/src/shared/proparser/profileevaluator.h b/src/shared/proparser/profileevaluator.h
index 1009792f95..544dccb060 100644
--- a/src/shared/proparser/profileevaluator.h
+++ b/src/shared/proparser/profileevaluator.h
@@ -93,8 +93,6 @@ public:
             const ProFile *pro) const;
     QString propertyValue(const QString &val) const;
 
-    QString resolvedMkSpec() const;
-
 private:
     QString sysrootify(const QString &path, const QString &baseDir) const;
 
-- 
GitLab