From 792bdecebdd426672bc2d687a55ef1a732322ac9 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Fri, 16 Oct 2009 15:49:18 +0300 Subject: Refactored SymbianSubdirsMetaMakefileGenerator out of qmake. There was no need to have SymbianSubdirsMetaMakefileGenerator in cross-platform metamakefile.cpp, so moved the Symbian specific functionality to symmake.cpp as suggested by qmake reviewers. Task-number: QT-822 Reviewed-by: Janne Anttila --- qmake/generators/metamakefile.cpp | 268 +---------------------------------- qmake/generators/symbian/symmake.cpp | 100 ++++++------- qmake/project.cpp | 47 +++--- 3 files changed, 69 insertions(+), 346 deletions(-) diff --git a/qmake/generators/metamakefile.cpp b/qmake/generators/metamakefile.cpp index 69dd627..5915fcf 100644 --- a/qmake/generators/metamakefile.cpp +++ b/qmake/generators/metamakefile.cpp @@ -419,269 +419,6 @@ SubdirsMetaMakefileGenerator::~SubdirsMetaMakefileGenerator() subs.clear(); } -class SymbianSubdirsMetaMakefileGenerator : public SubdirsMetaMakefileGenerator -{ -public: - SymbianSubdirsMetaMakefileGenerator(QMakeProject *p, const QString &n, bool op) : SubdirsMetaMakefileGenerator(p, n, op) { } - virtual ~SymbianSubdirsMetaMakefileGenerator(); - - virtual bool init(); - virtual bool write(const QString &); - -protected: - - static QMap mmpPaths; - - static QMultiMap mmpDependency; - - static QStringList getDependencyList(QString mmpFilename, int recursionDepth); - - static QStringList calculateRelativePaths(QString mmpParent, QStringList mmpChildren); - -private: - QString cleanFromSpecialCharacters(QString& str); -}; - -QMap SymbianSubdirsMetaMakefileGenerator::mmpPaths; - -QMultiMap SymbianSubdirsMetaMakefileGenerator::mmpDependency; - -QStringList SymbianSubdirsMetaMakefileGenerator::getDependencyList(QString mmpFilename, int recursionDepth) -{ - QStringList list; - - QList values = mmpDependency.values(mmpFilename); - if (recursionDepth < 0) { - // special case; just first dependency level - list = values; - return list; - } - if (values.size() == 0) { - //reached recursion END condition - if (recursionDepth == 0) { - --recursionDepth; - return list; // empty list // no dependencies / return - } else { - list.append(mmpFilename); - recursionDepth--; - return list; // leaf // return - } - } else { - recursionDepth++; - for (int i = 0; i < values.size(); ++i) { - QString current = values.at(i); - QStringList tailList = getDependencyList(current, recursionDepth); - for (int j = 0; j < tailList.size(); ++j) { - QString path = tailList.at(j); - list.append(path); - } - } - - if (recursionDepth > 0) { - //for mmp somewhere in middle - list.append(mmpFilename); - } - recursionDepth--; - return list; - } -} - -SymbianSubdirsMetaMakefileGenerator::~SymbianSubdirsMetaMakefileGenerator() { } - -bool SymbianSubdirsMetaMakefileGenerator::write(const QString &oldpwd) -{ - return SubdirsMetaMakefileGenerator::write(oldpwd); -} - -QString SymbianSubdirsMetaMakefileGenerator::cleanFromSpecialCharacters(QString& str) -{ - QString tmp = str; - - tmp.replace(QString("/"), QString("_")); - tmp.replace(QString("\\"), QString("_")); - tmp.replace(QString("-"), QString("_")); - tmp.replace(QString(":"), QString("_")); - tmp.replace(QString("."), QString("_")); - - return tmp; -} - -bool SymbianSubdirsMetaMakefileGenerator::init() -{ - if (init_flag) - return false; - - init_flag = true; - - // If we are here then we have template == subdirs - - Option::recursive = true; - - if (Option::recursive) { - QString old_output_dir = QDir::cleanPath(Option::output_dir); - if (!old_output_dir.endsWith('/')) - old_output_dir += '/'; - QString old_output = Option::output.fileName(); - QString oldpwd = QDir::cleanPath(qmake_getpwd()); - - if (!oldpwd.endsWith('/')) - oldpwd += '/'; - - // find the parent mmp filename - int end = oldpwd.size() - 1; - int start = oldpwd.lastIndexOf("/", end - 2); - QString parentMmpFilename = oldpwd.mid(start + 1, end - start - 1); - parentMmpFilename.prepend(oldpwd); - parentMmpFilename = parentMmpFilename.append(Option::mmp_ext); - - - const QStringList &subdirs = project->values("SUBDIRS"); - static int recurseDepth = -1; - ++recurseDepth; - for (int i = 0; i < subdirs.size(); ++i) { - Subdir *sub = new Subdir; - sub->indent = recurseDepth; - - QFileInfo subdir(subdirs.at(i)); - // childMmpFielname should be derived from subdirName - QString subdirName = subdirs.at(i); - if (!project->isEmpty(subdirs.at(i) + ".file")) - subdir = project->first(subdirs.at(i) + ".file"); - else if (!project->isEmpty(subdirs.at(i) + ".subdir")) - subdir = project->first(subdirs.at(i) + ".subdir"); - QString sub_name; - - QString childMmpFilename; - - if (subdir.isDir()) { - subdir = QFileInfo(subdir.filePath() + "/" + subdir.fileName() + Option::pro_ext); - childMmpFilename = subdir.fileName(); - childMmpFilename = subdir.absoluteFilePath(); - childMmpFilename.replace(Option::pro_ext, QString("")); - childMmpFilename.append(Option::mmp_ext); - } else { - childMmpFilename = subdir.absoluteFilePath(); - childMmpFilename.replace(Option::pro_ext, Option::mmp_ext); - sub_name = childMmpFilename; - sub_name.replace(Option::mmp_ext, QString("")); - sub_name.replace(0, sub_name.lastIndexOf("/") + 1, QString("")); - project->values("SHADOW_BLD_INFS").append(QString("bld.inf.") + sub_name); - } - - //handle sub project - QMakeProject *sub_proj = new QMakeProject(project->properties()); - for (int ind = 0; ind < sub->indent; ++ind) - printf(" "); - sub->input_dir = subdir.absolutePath(); - if (subdir.isRelative() && old_output_dir != oldpwd) { - sub->output_dir = old_output_dir + "/" + subdir.path(); - printf("Reading %s [%s]\n", subdir.absoluteFilePath().toLatin1().constData(), sub->output_dir.toLatin1().constData()); - } else { - sub->output_dir = sub->input_dir; - printf("Reading %s\n", subdir.absoluteFilePath().toLatin1().constData()); - } - - // find the child mmp filename - qmake_setpwd(sub->input_dir); - - QString newpwd = qmake_getpwd(); - - Option::output_dir = sub->output_dir; - if (Option::output_dir.at(Option::output_dir.length() - 1) != QLatin1Char('/')) - Option::output_dir += QLatin1Char('/'); - sub_proj->read(subdir.fileName()); - if (!sub_proj->variables()["QMAKE_FAILED_REQUIREMENTS"].isEmpty()) { - fprintf(stderr, "Project file(%s) not recursed because all requirements not met:\n\t%s\n", - subdir.fileName().toLatin1().constData(), - sub_proj->values("QMAKE_FAILED_REQUIREMENTS").join(" ").toLatin1().constData()); - delete sub; - delete sub_proj; - //continue; - } else { - // map mmpfile to its absolut filepath - mmpPaths.insert(childMmpFilename, newpwd); - - // update mmp files dependency map - mmpDependency.insert(parentMmpFilename, childMmpFilename); - - sub->makefile = MetaMakefileGenerator::createMetaGenerator(sub_proj, sub_name); - if (0 && sub->makefile->type() == SUBDIRSMETATYPE) { - subs.append(sub); - } else { - const QString output_name = Option::output.fileName(); - Option::output.setFileName(sub->output_file); - sub->makefile->write(sub->output_dir); - delete sub; - qmakeClearCaches(); - sub = 0; - Option::output.setFileName(output_name); - } - } - - Option::output_dir = old_output_dir; - qmake_setpwd(oldpwd); - - } - --recurseDepth; - Option::output.setFileName(old_output); - Option::output_dir = old_output_dir; - qmake_setpwd(oldpwd); - } - - Subdir *self = new Subdir; - self->input_dir = qmake_getpwd(); - - // To fully expand find all dependencies: - // Do as recursion, then insert result as subdirs data in project - QString newpwd = qmake_getpwd(); - if (!newpwd.endsWith('/')) - newpwd += '/'; - int end = newpwd.size() - 1; - int start = newpwd.lastIndexOf("/", end - 2); - QString mmpFilename = newpwd.mid(start + 1, end - start - 1); - mmpFilename.prepend(newpwd); - mmpFilename = mmpFilename.append(Option::mmp_ext); - - // map mmpfile to its absolute filepath - mmpPaths.insert(mmpFilename, newpwd); - - QStringList directDependencyList = getDependencyList(mmpFilename, -1); - for (int i = 0; i < directDependencyList.size(); ++i) { - project->values("MMPFILES_DIRECT_DEPENDS").append(directDependencyList.at(i)); - } - - QStringList dependencyList = getDependencyList(mmpFilename, 0); - - self->output_dir = Option::output_dir; - if (!Option::recursive || (!Option::output.fileName().endsWith(Option::dir_sep) && !QFileInfo(Option::output).isDir())) - self->output_file = Option::output.fileName(); - self->makefile = new BuildsMetaMakefileGenerator(project, name, false); - self->makefile->init(); - subs.append(self); - - return true; -} - -QStringList SymbianSubdirsMetaMakefileGenerator::calculateRelativePaths(QString mmpParent, QStringList mmpChildren) -{ - QStringList mmpRelativePaths; - QString parentDir = mmpPaths.value(mmpParent); - QDir directory(parentDir); - for (int i = 0; i < mmpChildren.size(); ++i) { - QString childDir = mmpPaths.value(mmpChildren.at(i)); - if (mmpChildren.at(i) == mmpParent) - mmpRelativePaths.append(mmpChildren.at(i)); - else { - QString relativePath = directory.relativeFilePath(childDir); - if (relativePath.startsWith("..")) - mmpRelativePaths.append(childDir); - else - directory.relativeFilePath(relativePath); - } - } - return mmpRelativePaths; -} - //Factory things QT_BEGIN_INCLUDE_NAMESPACE #include "unixmake.h" @@ -750,10 +487,7 @@ MetaMakefileGenerator::createMetaGenerator(QMakeProject *proj, const QString &na MetaMakefileGenerator *ret = 0; if ((Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE || Option::qmake_mode == Option::QMAKE_GENERATE_PRL)) { - if (proj->first("MAKEFILE_GENERATOR").startsWith("SYMBIAN") && proj->values("TEMPLATE").contains("subdirs")) { - // new metamakefilegenerator type to support subdirs for symbian related projects - ret = new SymbianSubdirsMetaMakefileGenerator(proj, name, op); - } else if (proj->first("TEMPLATE").endsWith("subdirs")) + if (proj->first("TEMPLATE").endsWith("subdirs")) ret = new SubdirsMetaMakefileGenerator(proj, name, op); } if (!ret) diff --git a/qmake/generators/symbian/symmake.cpp b/qmake/generators/symbian/symmake.cpp index 3d24053..19af1da 100644 --- a/qmake/generators/symbian/symmake.cpp +++ b/qmake/generators/symbian/symmake.cpp @@ -1092,6 +1092,7 @@ void SymbianMakefileGenerator::writeMmpFileRulesPart(QTextStream& t) void SymbianMakefileGenerator::writeBldInfContent(QTextStream &t, bool addDeploymentExtension) { // Read user defined bld inf rules + QMap userBldInfRules; for (QMap::iterator it = project->variables().begin(); it != project->variables().end(); ++it) { if (it.key().startsWith(BLD_INF_RULES_BASE)) { @@ -1122,58 +1123,44 @@ void SymbianMakefileGenerator::writeBldInfContent(QTextStream &t, bool addDeploy QString mmpfilename = escapeFilePath(fileFixify(project->projectFile())); mmpfilename = mmpfilename.replace(mmpfilename.lastIndexOf("."), 4, Option::mmp_ext); QString currentPath = qmake_getpwd(); + QDir directory(currentPath); - if (!currentPath.endsWith(QString("/"))) - currentPath.append("/"); - - QStringList mmpProjects = project->values("MMPFILES_DIRECT_DEPENDS"); - QStringList shadowProjects = project->values("SHADOW_BLD_INFS"); - - removeDuplicatedStrings(mmpProjects); - removeDuplicatedStrings(shadowProjects); + const QStringList &subdirs = project->values("SUBDIRS"); + foreach(QString item, subdirs) { + QString fixedItem; + if (!project->isEmpty(item + ".file")) { + fixedItem = project->first(item + ".file"); + } else if (!project->isEmpty(item + ".subdir")) { + fixedItem = project->first(item + ".subdir"); + } else { + fixedItem = item; + } - // Go in reverse order as that is the way how we build the list - QListIterator iT(mmpProjects); - iT.toBack(); - while (iT.hasPrevious()) { - QString fullMmpName = iT.previous(); - QString relativePath; + QFileInfo subdir(fileInfo(fixedItem)); + QString relativePath = directory.relativeFilePath(fixedItem); + QString subdirFileName = subdir.completeBaseName(); + QString fullProName = subdir.absoluteFilePath();; QString bldinfFilename; - QString fullProFilename = fullMmpName; - fullProFilename.replace(Option::mmp_ext, Option::pro_ext); - QString uid = generate_uid(fullProFilename); - - QString cleanMmpName = fullProFilename; - cleanMmpName.replace(Option::pro_ext, QString("")); - cleanMmpName.replace(0, cleanMmpName.lastIndexOf("/") + 1, QString("")); - - if (shadowProjects.contains(BLD_INF_FILENAME "." + cleanMmpName)) { // shadow project - QDir directory(currentPath); - relativePath = directory.relativeFilePath(fullProFilename); - bldinfFilename = BLD_INF_FILENAME "." + cleanMmpName; + if (subdir.isDir()) { + // Subdir is a regular project + bldinfFilename = relativePath + QString("/") + QString(BLD_INF_FILENAME); + fullProName += QString("/") + subdirFileName + Option::pro_ext; + } else { + // Subdir is actually a .pro file if (relativePath.contains("/")) { - // Shadow .pro not in same directory as parent .pro - if (relativePath.startsWith("..")) { - // Shadow .pro out of parent .pro - relativePath.replace(relativePath.lastIndexOf("/"), relativePath.length(), QString("")); - bldinfFilename.prepend("/").prepend(relativePath); - } else { - relativePath.replace(relativePath.lastIndexOf("/"), relativePath.length(), QString("")); - bldinfFilename.prepend("/").prepend(relativePath); - } + // .pro not in same directory as parent .pro + relativePath.remove(relativePath.lastIndexOf("/") + 1, relativePath.length()); + bldinfFilename = relativePath; } else { - // Shadow .pro and parent .pro in same directory - bldinfFilename.prepend("./"); + // .pro and parent .pro in same directory + bldinfFilename = QString("./"); } - } else { // regular project - QDir directory(currentPath); - relativePath = directory.relativeFilePath(fullProFilename); - relativePath.replace(relativePath.lastIndexOf("/"), relativePath.length(), QString("")); - bldinfFilename = relativePath.append("/").append(BLD_INF_FILENAME); + bldinfFilename += QString(BLD_INF_FILENAME ".") + subdirFileName; } - QString bldinfDefine = QString("BLD_INF_") + cleanMmpName + QString("_") + uid; + QString uid = generate_uid(fullProName); + QString bldinfDefine = QString("BLD_INF_") + subdirFileName + QString("_") + uid; bldinfDefine = bldinfDefine.toUpper(); removeSpecialCharacters(bldinfDefine); @@ -1195,6 +1182,7 @@ void SymbianMakefileGenerator::writeBldInfContent(QTextStream &t, bool addDeploy t << endl; // Add project mmps and old style extension makefiles + QString mmpTag; if (project->values("CONFIG").contains("symbian_test", Qt::CaseInsensitive)) mmpTag = QLatin1String(BLD_INF_TAG_TESTMMPFILES); @@ -1204,9 +1192,7 @@ void SymbianMakefileGenerator::writeBldInfContent(QTextStream &t, bool addDeploy t << endl << mmpTag << endl << endl; writeBldInfMkFilePart(t, addDeploymentExtension); - if (targetType == TypeSubdirs) { - mmpProjects.removeOne(mmpfilename); - } else { + if (targetType != TypeSubdirs) { QString shortProFilename = project->projectFile(); shortProFilename.replace(0, shortProFilename.lastIndexOf("/") + 1, QString("")); shortProFilename.replace(Option::pro_ext, QString("")); @@ -1224,6 +1210,7 @@ void SymbianMakefileGenerator::writeBldInfContent(QTextStream &t, bool addDeploy t << endl << BLD_INF_TAG_EXTENSIONS << endl << endl; // Generate extension rules + writeBldInfExtensionRulesPart(t); userItems = userBldInfRules.value(BLD_INF_TAG_EXTENSIONS); @@ -1698,8 +1685,8 @@ void SymbianMakefileGenerator::writeSisTargets(QTextStream &t) .arg(MAKE_CACHE_NAME) .arg(OK_SIS_TARGET) .arg(FAIL_SIS_NOCACHE_TARGET) - .arg(FAIL_SIS_NOPKG_TARGET); - t << siscommand << endl; + .arg(FAIL_SIS_NOPKG_TARGET); + t << siscommand << endl; t << endl; t << OK_SIS_TARGET ":" << endl; @@ -1710,15 +1697,15 @@ void SymbianMakefileGenerator::writeSisTargets(QTextStream &t) .arg("pkg"); t << pkgcommand << endl; t << endl; - - t << FAIL_SIS_NOPKG_TARGET ":" << endl; - t << "\t$(error PKG file does not exist, 'SIS' target is only supported for executables or projects with DEPLOYMENT statement)" << endl; + + t << FAIL_SIS_NOPKG_TARGET ":" << endl; + t << "\t$(error PKG file does not exist, 'SIS' target is only supported for executables or projects with DEPLOYMENT statement)" << endl; t << endl; - - t << FAIL_SIS_NOCACHE_TARGET ":" << endl; - t << "\t$(error Project has to be build before calling 'SIS' target)" << endl; + + t << FAIL_SIS_NOCACHE_TARGET ":" << endl; + t << "\t$(error Project has to be build before calling 'SIS' target)" << endl; t << endl; - + t << RESTORE_BUILD_TARGET ":" << endl; t << "-include " MAKE_CACHE_NAME << endl; @@ -1728,7 +1715,8 @@ void SymbianMakefileGenerator::writeSisTargets(QTextStream &t) void SymbianMakefileGenerator::generateDistcleanTargets(QTextStream& t) { t << "dodistclean:" << endl; - foreach(QString item, project->values("SUBDIRS")) { + const QStringList &subdirs = project->values("SUBDIRS"); + foreach(QString item, subdirs) { bool fromFile = false; QString fixedItem; if (!project->isEmpty(item + ".file")) { diff --git a/qmake/project.cpp b/qmake/project.cpp index 89fe5bd..e49441b 100644 --- a/qmake/project.cpp +++ b/qmake/project.cpp @@ -519,7 +519,7 @@ static isForSymbian_enum isForSymbian_value = isForSymbian_NOT_SET; // Checking for symbian build is primarily determined from the qmake spec, // but if that is not specified, detect if symbian is the default spec // by checking the MAKEFILE_GENERATOR variable value. -static void init_isForSymbian(const QMap& vars) +static void init_symbian(const QMap& vars) { if (isForSymbian_value != isForSymbian_NOT_SET) return; @@ -527,26 +527,27 @@ static void init_isForSymbian(const QMap& vars) QString spec = QFileInfo(Option::mkfile::qmakespec).fileName(); if (spec.startsWith("symbian-abld", Qt::CaseInsensitive)) { isForSymbian_value = isForSymbian_ABLD; - return; - } - if (spec.startsWith("symbian-sbsv2", Qt::CaseInsensitive)) { + } else if (spec.startsWith("symbian-sbsv2", Qt::CaseInsensitive)) { isForSymbian_value = isForSymbian_SBSV2; - return; - } - - QStringList generatorList = vars["MAKEFILE_GENERATOR"]; - - if (!generatorList.isEmpty()) { - QString generator = generatorList.first(); - if (generator.startsWith("SYMBIAN_ABLD")) - isForSymbian_value = isForSymbian_ABLD; - else if (generator.startsWith("SYMBIAN_SBSV2")) - isForSymbian_value = isForSymbian_SBSV2; - else - isForSymbian_value = isForSymbian_FALSE; } else { - isForSymbian_value = isForSymbian_FALSE; + QStringList generatorList = vars["MAKEFILE_GENERATOR"]; + + if (!generatorList.isEmpty()) { + QString generator = generatorList.first(); + if (generator.startsWith("SYMBIAN_ABLD")) + isForSymbian_value = isForSymbian_ABLD; + else if (generator.startsWith("SYMBIAN_SBSV2")) + isForSymbian_value = isForSymbian_SBSV2; + else + isForSymbian_value = isForSymbian_FALSE; + } else { + isForSymbian_value = isForSymbian_FALSE; + } } + + // Force recursive on Symbian, as non-recursive is not really a viable option there + if (isForSymbian_value != isForSymbian_FALSE) + Option::recursive = true; } bool isForSymbian() @@ -554,9 +555,9 @@ bool isForSymbian() // If isForSymbian_value has not been initialized explicitly yet, // call initializer with dummy map to check qmake spec. if (isForSymbian_value == isForSymbian_NOT_SET) - init_isForSymbian(QMap()); + init_symbian(QMap()); - return (isForSymbian_value == isForSymbian_ABLD || isForSymbian_value == isForSymbian_SBSV2); + return (isForSymbian_value != isForSymbian_FALSE); } bool isForSymbianSbsv2() @@ -564,7 +565,7 @@ bool isForSymbianSbsv2() // If isForSymbian_value has not been initialized explicitly yet, // call initializer with dummy map to check qmake spec. if (isForSymbian_value == isForSymbian_NOT_SET) - init_isForSymbian(QMap()); + init_symbian(QMap()); return (isForSymbian_value == isForSymbian_SBSV2); } @@ -1463,7 +1464,7 @@ QMakeProject::read(uchar cmd) return false; } - init_isForSymbian(base_vars); + init_symbian(base_vars); if(Option::mkfile::do_cache && !Option::mkfile::cachefile.isEmpty()) { debug_msg(1, "QMAKECACHE file: reading %s", Option::mkfile::cachefile.toLatin1().constData()); @@ -1715,7 +1716,7 @@ QMakeProject::doProjectInclude(QString file, uchar flags, QMap