Revert "move .qmake.cache search to Option"
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>
Wed, 9 May 2012 13:14:37 +0000 (15:14 +0200)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>
Tue, 19 Jun 2012 14:37:49 +0000 (16:37 +0200)
We are now moving in the exact opposite direction.
This logically reverts commit 059200a44ba7177d0c9ec6bb5e6ee0b7e0c3f017.
Some adjustments were necessary to maintain the project root stuff.

Conflicts:

qmake/main.cpp
qmake/option.cpp
qmake/option.h
qmake/project.cpp

Change-Id: Ic14fa571cbbfe9ac159f92493e49741d70a87eff
Reviewed-by: Joerg Bornemann <joerg.bornemann@nokia.com>
qmake/main.cpp
qmake/option.cpp
qmake/option.h
qmake/project.cpp

index 985afaa..38e09f6 100644 (file)
@@ -163,11 +163,6 @@ int runQMake(int argc, char **argv)
                 fn = fn.right(fn.length() - di - 1);
             }
 
-            if (!Option::prepareProject(fn)) {
-                exit_val = 3;
-                break;
-            }
-
             // read project..
             if(!project.read(fn)) {
                 fprintf(stderr, "Error processing project file: %s\n",
index 3ddde2a..de907f0 100644 (file)
@@ -114,8 +114,6 @@ bool Option::mkfile::do_dep_heuristics = true;
 bool Option::mkfile::do_preprocess = false;
 bool Option::mkfile::do_stub_makefile = false;
 bool Option::mkfile::do_cache = true;
-QString Option::mkfile::project_root;
-QString Option::mkfile::project_build_root;
 QString Option::mkfile::cachefile;
 QStringList Option::mkfile::project_files;
 QString Option::mkfile::qmakespec_commandline;
@@ -583,62 +581,6 @@ void Option::applyHostMode()
    }
 }
 
-bool Option::prepareProject(const QString &pfile)
-{
-    mkfile::project_build_root.clear();
-    if (mkfile::do_cache) {
-        if (mkfile::cachefile.isEmpty())  { //find it as it has not been specified
-            QDir dir(output_dir);
-            while (!dir.exists(QLatin1String(".qmake.cache")))
-                if (dir.isRoot() || !dir.cdUp())
-                    goto no_cache;
-            mkfile::cachefile = dir.filePath(QLatin1String(".qmake.cache"));
-            mkfile::project_build_root = dir.path();
-        } else {
-            QFileInfo fi(mkfile::cachefile);
-            mkfile::cachefile = QDir::cleanPath(fi.absoluteFilePath());
-            mkfile::project_build_root = QDir::cleanPath(fi.absolutePath());
-        }
-
-        if (mkfile::qmakespec.isEmpty()) {
-            QMakeProject cproj;
-            if (!cproj.read(mkfile::cachefile, QMakeProject::ReadProFile))
-                return false;
-            mkfile::qmakespec = cproj.first(QLatin1String("QMAKESPEC"));
-        }
-    }
-  no_cache:
-
-    QString srcpath = (pfile != "-")
-            ? QDir::cleanPath(QFileInfo(pfile).absolutePath()) : qmake_getpwd();
-    if (srcpath != output_dir || mkfile::project_build_root.isEmpty()) {
-        QDir srcdir(srcpath);
-        QDir dstdir(output_dir);
-        do {
-            if (!mkfile::project_build_root.isEmpty()) {
-                // If we already know the build root, just match up the source root with it.
-                if (dstdir.path() == mkfile::project_build_root) {
-                    mkfile::project_root = srcdir.path();
-                    break;
-                }
-            } else {
-                // Look for mkspecs/ in source and build. First to win determines the root.
-                if (dstdir.exists("mkspecs") || srcdir.exists("mkspecs")) {
-                    mkfile::project_build_root = dstdir.path();
-                    mkfile::project_root = srcdir.path();
-                    if (mkfile::project_root == mkfile::project_build_root)
-                        mkfile::project_root.clear();
-                    break;
-                }
-            }
-        } while (!srcdir.isRoot() && srcdir.cdUp() && !dstdir.isRoot() && dstdir.cdUp());
-    } else {
-        mkfile::project_root.clear();
-    }
-
-    return true;
-}
-
 bool Option::postProcessProject(QMakeProject *project)
 {
     Option::cpp_ext = project->variables()["QMAKE_EXT_CPP"];
index ce680b0..0ec6a36 100644 (file)
@@ -109,7 +109,6 @@ struct Option
     //both of these must be called..
     static int init(int argc=0, char **argv=0); //parse cmdline
     static void applyHostMode();
-    static bool prepareProject(const QString &pfile);
     static bool postProcessProject(QMakeProject *);
 
     enum StringFixFlags {
@@ -203,8 +202,6 @@ struct Option
         static bool do_dep_heuristics;
         static bool do_preprocess;
         static bool do_stub_makefile;
-        static QString project_root;
-        static QString project_build_root;
         static QString cachefile;
         static int cachefile_depth;
         static QStringList project_files;
index 612acda..283dee1 100644 (file)
@@ -164,6 +164,9 @@ struct parser_info {
     bool from_file;
 } parser;
 
+static QString project_root;
+static QString project_build_root;
+
 static QString remove_quotes(const QString &arg)
 {
     const ushort SINGLEQUOTE = '\'';
@@ -612,10 +615,10 @@ QStringList qmake_mkspec_paths()
         for (QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it)
             ret << ((*it) + concat);
     }
-    if (!Option::mkfile::project_build_root.isEmpty())
-        ret << Option::mkfile::project_build_root + concat;
-    if (!Option::mkfile::project_root.isEmpty())
-        ret << Option::mkfile::project_root + concat;
+    if (!project_build_root.isEmpty())
+        ret << project_build_root + concat;
+    if (!project_root.isEmpty())
+        ret << project_root + concat;
     ret << QLibraryInfo::location(QLibraryInfo::DataPath) + concat;
     ret.removeDuplicates();
 
@@ -1298,11 +1301,61 @@ QMakeProject::read(uchar cmd)
         if(!Option::user_template_prefix.isEmpty())
             base_vars["TEMPLATE_PREFIX"] = QStringList(Option::user_template_prefix);
 
+        project_build_root.clear();
+
         if (Option::mkfile::do_cache) {        // parse the cache
-            if (Option::output_dir.startsWith(Option::mkfile::project_build_root))
+            if (Option::mkfile::cachefile.isEmpty())  { //find it as it has not been specified
+                QDir dir(Option::output_dir);
+                while (!dir.exists(QLatin1String(".qmake.cache")))
+                    if (dir.isRoot() || !dir.cdUp())
+                        goto no_cache;
+                Option::mkfile::cachefile = dir.filePath(QLatin1String(".qmake.cache"));
+                project_build_root = dir.path();
+            } else {
+                QFileInfo fi(Option::mkfile::cachefile);
+                Option::mkfile::cachefile = QDir::cleanPath(fi.absoluteFilePath());
+                project_build_root = QDir::cleanPath(fi.absolutePath());
+            }
+
+            QHash<QString, QStringList> cache;
+            if (!read(Option::mkfile::cachefile, cache)) {
+                Option::mkfile::cachefile.clear();
+                goto no_cache;
+            }
+            if (Option::mkfile::qmakespec.isEmpty() && !cache["QMAKESPEC"].isEmpty())
+                Option::mkfile::qmakespec = cache["QMAKESPEC"].first();
+
+            if (Option::output_dir.startsWith(project_build_root))
                 Option::mkfile::cachefile_depth =
-                        Option::output_dir.mid(Option::mkfile::project_build_root.length()).count('/');
+                        Option::output_dir.mid(project_build_root.length()).count('/');
+        }
+      no_cache:
+
+        if (qmake_getpwd() != Option::output_dir || project_build_root.isEmpty()) {
+            QDir srcdir(qmake_getpwd());
+            QDir dstdir(Option::output_dir);
+            do {
+                if (!project_build_root.isEmpty()) {
+                    // If we already know the build root, just match up the source root with it.
+                    if (dstdir.path() == project_build_root) {
+                        project_root = srcdir.path();
+                        break;
+                    }
+                } else {
+                    // Look for mkspecs/ in source and build. First to win determines the root.
+                    if (dstdir.exists("mkspecs") || srcdir.exists("mkspecs")) {
+                        project_build_root = dstdir.path();
+                        project_root = srcdir.path();
+                        if (project_root == project_build_root)
+                            project_root.clear();
+                        break;
+                    }
+                }
+            } while (!srcdir.isRoot() && srcdir.cdUp() && !dstdir.isRoot() && dstdir.cdUp());
+        } else {
+            project_root.clear();
         }
+
         {             // parse mkspec
             QString qmakespec = Option::mkfile::qmakespec;
             if (qmakespec.isEmpty())