OSDN Git Service

Move the function comparing settings and Makefile to Qt4Project
authordt <qtc-committer@nokia.com>
Thu, 23 Jul 2009 16:15:25 +0000 (18:15 +0200)
committerdt <qtc-committer@nokia.com>
Thu, 23 Jul 2009 16:15:25 +0000 (18:15 +0200)
I need that in the Qt4ProjectConfigWidget to decide whether I should
show a import label.

src/plugins/qt4projectmanager/qmakestep.cpp
src/plugins/qt4projectmanager/qt4project.cpp
src/plugins/qt4projectmanager/qt4project.h

index ed9d8a7..45699c6 100644 (file)
@@ -91,45 +91,6 @@ QStringList QMakeStep::arguments(const QString &buildConfiguration)
     return arguments;
 }
 
-// We match -spec and -platfrom separetly
-// We ignore -cache, because qmake contained a bug that it didn't
-// mention the -cache in the Makefile
-// That means changing the -cache option in the additional arguments
-// does not automatically rerun qmake. Alas, we could try more
-// intelligent matching for -cache, but i guess people rarely
-// do use that.
-
-QStringList removeSpecFromArgumentList(const QStringList &old)
-{
-    if (!old.contains("-spec") && !old.contains("-platform"))
-        return old;
-    QStringList newList;
-    bool ignoreNext = false;
-    foreach(const QString &item, old) {
-        if (ignoreNext) {
-            ignoreNext = false;
-        } else if (item == "-spec" || item == "-platform" || item == "-cache") {
-            ignoreNext = true;
-        } else {
-            newList << item;
-        }
-    }
-    return newList;
-}
-
-QString extractSpecFromArgumentList(const QStringList &list)
-{
-    int index = list.indexOf("-spec");
-    if (index == -1)
-        index = list.indexOf("-platform");
-    if (index == -1)
-        return QString();
-    if (index + 1 < list.length())
-        return list.at(index +1);
-    else
-        return QString();
-}
-
 bool QMakeStep::init(const QString &name)
 {
     m_buildConfiguration = name;
@@ -155,50 +116,7 @@ bool QMakeStep::init(const QString &name)
     if (QDir(workingDirectory).exists(QLatin1String("Makefile"))) {
         QString qtPath = QtVersionManager::findQtVersionFromMakefile(workingDirectory);
         if (qtVersion->path() == qtPath) {
-            // same qtversion
-            QPair<QtVersion::QmakeBuildConfig, QStringList> result =
-                    QtVersionManager::scanMakeFile(workingDirectory, qtVersion->defaultBuildConfig());
-            if (QtVersion::QmakeBuildConfig(m_pro->value(name, "buildConfiguration").toInt()) == result.first) {
-                // The QMake Build Configuration are the same,
-                // now compare arguments lists
-                // we have to compare without the spec/platform cmd argument
-                // and compare that on its own
-                QString actualSpec = extractSpecFromArgumentList(value(name, "qmakeArgs").toStringList());
-                if (actualSpec.isEmpty())
-                    actualSpec = m_pro->qtVersion(name)->mkspec();
-                QString parsedSpec = extractSpecFromArgumentList(result.second);
-
-                // Now to convert the actualSpec to a absolute path, we go through a few hops
-                if (QFileInfo(actualSpec).isRelative()) {
-                    QString path = qtVersion->sourcePath() + "/mkspecs/" + actualSpec;
-                    if (QFileInfo(path).exists()) {
-                        actualSpec = QDir::cleanPath(path);
-                    } else {
-                        path = qtVersion->versionInfo().value("QMAKE_MKSPECS") + "/" + actualSpec;
-                        if (QFileInfo(path).exists()) {
-                            actualSpec = QDir::cleanPath(path);
-                        } else {
-                            path = workingDirectory + "/" + actualSpec;
-                            if (QFileInfo(path).exists())
-                                actualSpec = QDir::cleanPath(path);
-                        }
-                    }
-                }
-
-                if (QFileInfo(parsedSpec).isRelative())
-                    parsedSpec = QDir::cleanPath(workingDirectory + "/" + parsedSpec);
-
-                QStringList actualArgs = removeSpecFromArgumentList(value(name, "qmakeArgs").toStringList());
-                QStringList parsedArgs = removeSpecFromArgumentList(result.second);
-
-                qDebug()<<"Actual args:"<<actualArgs;
-                qDebug()<<"Parsed args:"<<parsedArgs;
-                qDebug()<<"Actual spec:"<<actualSpec;
-                qDebug()<<"Parsed spec:"<<parsedSpec;
-
-                if (actualArgs == parsedArgs && actualSpec == parsedSpec)
-                    needToRunQMake = false;
-            }
+            needToRunQMake = m_pro->compareBuildConfigurationToImportFrom(name, workingDirectory);
         }
     }
 
index cd8be85..c242402 100644 (file)
@@ -1098,6 +1098,107 @@ void Qt4Project::invalidateCachedTargetInformation()
     emit targetInformationChanged();
 }
 
+// We match -spec and -platfrom separetly
+// We ignore -cache, because qmake contained a bug that it didn't
+// mention the -cache in the Makefile
+// That means changing the -cache option in the additional arguments
+// does not automatically rerun qmake. Alas, we could try more
+// intelligent matching for -cache, but i guess people rarely
+// do use that.
+
+QStringList removeSpecFromArgumentList(const QStringList &old)
+{
+    if (!old.contains("-spec") && !old.contains("-platform") && !old.contains("-cache"))
+        return old;
+    QStringList newList;
+    bool ignoreNext = false;
+    foreach(const QString &item, old) {
+        qDebug()<<"Item:"<<item;
+        if (ignoreNext) {
+            qDebug()<<"ignored (2)";
+            ignoreNext = false;
+        } else if (item == "-spec" || item == "-platform" || item == "-cache") {
+            ignoreNext = true;
+            qDebug()<<"ignored (1)";
+        } else {
+            newList << item;
+            qDebug()<<"added";
+        }
+    }
+    return newList;
+}
+
+QString extractSpecFromArgumentList(const QStringList &list)
+{
+    int index = list.indexOf("-spec");
+    if (index == -1)
+        index = list.indexOf("-platform");
+    if (index == -1)
+        return QString();
+    if (index + 1 < list.length())
+        return list.at(index +1);
+    else
+        return QString();
+}
+
+bool Qt4Project::compareBuildConfigurationToImportFrom(const QString &buildConfiguration, const QString &workingDirectory)
+{
+    if (QDir(workingDirectory).exists(QLatin1String("Makefile"))) {
+        QString qtPath = QtVersionManager::findQtVersionFromMakefile(workingDirectory);
+        QtVersion *version = qtVersion(buildConfiguration);
+        if (version->path() == qtPath) {
+            // same qtversion
+            QPair<QtVersion::QmakeBuildConfig, QStringList> result =
+                    QtVersionManager::scanMakeFile(workingDirectory, version->defaultBuildConfig());
+            if (QtVersion::QmakeBuildConfig(value(buildConfiguration, "buildConfiguration").toInt()) == result.first) {
+                // The QMake Build Configuration are the same,
+                // now compare arguments lists
+                // we have to compare without the spec/platform cmd argument
+                // and compare that on its own
+                QString actualSpec = extractSpecFromArgumentList(qmakeStep()->value(buildConfiguration, "qmakeArgs").toStringList());
+                if (actualSpec.isEmpty())
+                    actualSpec = qtVersion(buildConfiguration)->mkspec();
+                QString parsedSpec = extractSpecFromArgumentList(result.second);
+
+                // Now to convert the actualSpec to a absolute path, we go through a few hops
+                if (QFileInfo(actualSpec).isRelative()) {
+                    QString path = version->sourcePath() + "/mkspecs/" + actualSpec;
+                    if (QFileInfo(path).exists()) {
+                        actualSpec = QDir::cleanPath(path);
+                    } else {
+                        path = version->versionInfo().value("QMAKE_MKSPECS") + "/" + actualSpec;
+                        if (QFileInfo(path).exists()) {
+                            actualSpec = QDir::cleanPath(path);
+                        } else {
+                            path = workingDirectory + "/" + actualSpec;
+                            if (QFileInfo(path).exists())
+                                actualSpec = QDir::cleanPath(path);
+                        }
+                    }
+                }
+
+                if (QFileInfo(parsedSpec).isRelative())
+                    parsedSpec = QDir::cleanPath(workingDirectory + "/" + parsedSpec);
+
+
+                qDebug()<<"before:"<<qmakeStep()->value(buildConfiguration, "qmakeArgs").toStringList();
+                QStringList actualArgs = removeSpecFromArgumentList(qmakeStep()->value(buildConfiguration, "qmakeArgs").toStringList());
+                qDebug()<<"after:"<<actualArgs;
+                QStringList parsedArgs = removeSpecFromArgumentList(result.second);
+
+                qDebug()<<"Actual args:"<<actualArgs;
+                qDebug()<<"Parsed args:"<<parsedArgs;
+                qDebug()<<"Actual spec:"<<actualSpec;
+                qDebug()<<"Parsed spec:"<<parsedSpec;
+
+                if (actualArgs == parsedArgs && actualSpec == parsedSpec)
+                    return false;
+            }
+        }
+    }
+    return true;
+}
+
 
 /*!
   Handle special case were a subproject of the qt directory is opened, and
index 073728a..c6319f6 100644 (file)
@@ -196,6 +196,8 @@ public:
     virtual QStringList includePaths(const QString &fileName) const;
     virtual QStringList frameworkPaths(const QString &fileName) const;
 
+    bool compareBuildConfigurationToImportFrom(const QString &buildConfiguration, const QString &workingDirectory);
+
 signals:
     void targetInformationChanged();