From 059200a44ba7177d0c9ec6bb5e6ee0b7e0c3f017 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 23 Feb 2012 17:05:28 +0100 Subject: move .qmake.cache search to Option this is a one-time operation which depends only on the invocation, so this new home is much more appropriate. Change-Id: I11ef30a8227afed06e58e64e65809dba25e81567 Reviewed-by: Joerg Bornemann --- qmake/main.cpp | 5 +++++ qmake/option.cpp | 29 +++++++++++++++++++++++++++++ qmake/option.h | 2 ++ qmake/project.cpp | 32 +++----------------------------- 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/qmake/main.cpp b/qmake/main.cpp index 38e09f60fd..54cf9f9bdf 100644 --- a/qmake/main.cpp +++ b/qmake/main.cpp @@ -163,6 +163,11 @@ int runQMake(int argc, char **argv) fn = fn.right(fn.length() - di - 1); } + if (!Option::prepareProject()) { + exit_val = 3; + break; + } + // read project.. if(!project.read(fn)) { fprintf(stderr, "Error processing project file: %s\n", diff --git a/qmake/option.cpp b/qmake/option.cpp index 431299b46b..306e6b5286 100644 --- a/qmake/option.cpp +++ b/qmake/option.cpp @@ -116,6 +116,7 @@ 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_build_root; QString Option::mkfile::cachefile; QStringList Option::mkfile::project_files; QString Option::mkfile::qmakespec_commandline; @@ -567,6 +568,34 @@ void Option::applyHostMode() } } +bool Option::prepareProject() +{ + 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: + return true; +} + bool Option::postProcessProject(QMakeProject *project) { Option::cpp_ext = project->variables()["QMAKE_EXT_CPP"]; diff --git a/qmake/option.h b/qmake/option.h index ee8a1c2403..b8a3b561fa 100644 --- a/qmake/option.h +++ b/qmake/option.h @@ -108,6 +108,7 @@ 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(); static bool postProcessProject(QMakeProject *); enum StringFixFlags { @@ -201,6 +202,7 @@ struct Option static bool do_dep_heuristics; static bool do_preprocess; static bool do_stub_makefile; + static QString project_build_root; static QString cachefile; static int cachefile_depth; static QStringList project_files; diff --git a/qmake/project.cpp b/qmake/project.cpp index 0445c8eee9..1179812b1b 100644 --- a/qmake/project.cpp +++ b/qmake/project.cpp @@ -1281,35 +1281,9 @@ QMakeProject::read(uchar cmd) base_vars["TEMPLATE_PREFIX"] = QStringList(Option::user_template_prefix); if ((cmd & ReadSetup) && Option::mkfile::do_cache) { // parse the cache - int cache_depth = -1; - QString qmake_cache = Option::mkfile::cachefile; - if(qmake_cache.isEmpty()) { //find it as it has not been specified - QString dir = Option::output_dir; - while(!QFile::exists((qmake_cache = dir + QLatin1String("/.qmake.cache")))) { - dir = dir.left(dir.lastIndexOf(QLatin1Char('/'))); - if(dir.isEmpty() || dir.indexOf(QLatin1Char('/')) == -1) { - qmake_cache = ""; - break; - } - if(cache_depth == -1) - cache_depth = 1; - else - cache_depth++; - } - } else { - QString abs_cache = QFileInfo(Option::mkfile::cachefile).absoluteDir().path(); - if(Option::output_dir.startsWith(abs_cache)) - cache_depth = Option::output_dir.mid(abs_cache.length()).count('/'); - } - if(!qmake_cache.isEmpty()) { - QHash cache; - if(read(qmake_cache, cache)) { - Option::mkfile::cachefile_depth = cache_depth; - Option::mkfile::cachefile = qmake_cache; - if(Option::mkfile::qmakespec.isEmpty() && !cache["QMAKESPEC"].isEmpty()) - Option::mkfile::qmakespec = cache["QMAKESPEC"].first(); - } - } + if (Option::output_dir.startsWith(Option::mkfile::project_build_root)) + Option::mkfile::cachefile_depth = + Option::output_dir.mid(Option::mkfile::project_build_root.length()).count('/'); } if (cmd & ReadSetup) { // parse mkspec QString qmakespec = fixEnvVariables(Option::mkfile::qmakespec); -- cgit v1.2.3