From e7d36a55746e6e3a2a66c47ee85cbfbfbe079c4e Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Wed, 19 Aug 2009 15:34:28 +0300 Subject: Review fixes for qmake (project.cpp cleanup) Removed symbian specific functionality from project.cpp: - generate_test_uid qmake function removed - Uids are now generated automatically for projects that don't have one. - Usage of ICON (in application_icon.prf) now requires explicit UID3 definition. - Autotests that require UID3 in .pro now define it explicitly - Move most symbian specific function implementations away from project.cpp to files under generators/symbian Reviewed-by: Janne Anttila --- mkspecs/features/qttest_p4.prf | 1 - mkspecs/features/symbian/application_icon.prf | 4 +- qmake/generators/symbian/epocroot.h | 51 +++++++ .../symbian/initprojectdeploy_symbian.cpp | 133 ++++++++++++++++ .../generators/symbian/initprojectdeploy_symbian.h | 5 + qmake/generators/symbian/symmake.cpp | 5 +- qmake/project.cpp | 169 +-------------------- qmake/project.h | 5 +- qmake/qmake.pri | 1 + tests/auto/qdatastream/qdatastream.pro | 1 + tests/auto/qdir/qdir.pro | 1 + tests/auto/qdirmodel/qdirmodel.pro | 1 + tests/auto/qicoimageformat/qicoimageformat.pro | 1 + tests/auto/qlocalsocket/test/test.pro | 1 + tests/auto/qscriptengine/qscriptengine.pro | 1 + 15 files changed, 205 insertions(+), 175 deletions(-) create mode 100644 qmake/generators/symbian/epocroot.h diff --git a/mkspecs/features/qttest_p4.prf b/mkspecs/features/qttest_p4.prf index ae58c5d..4ab5ac2 100644 --- a/mkspecs/features/qttest_p4.prf +++ b/mkspecs/features/qttest_p4.prf @@ -6,7 +6,6 @@ qtAddLibrary(QtTest) symbian:{ # qt.prf sets TARGET.EPOCSTACKSIZE and TARGET.EPOCHEAPSIZE # DEFINES += QTEST_NO_SPECIALIZATIONS - TARGET.UID3 = $$generate_test_uid($$TARGET) TARGET.CAPABILITY="ALL -TCB" RSS_RULES ="group_name=\"QtTests\";" } diff --git a/mkspecs/features/symbian/application_icon.prf b/mkspecs/features/symbian/application_icon.prf index df4bb1c..97b99a5 100644 --- a/mkspecs/features/symbian/application_icon.prf +++ b/mkspecs/features/symbian/application_icon.prf @@ -13,8 +13,8 @@ contains( CONFIG, no_icon ) { message("ICON keyword must have one or the same amout of items as in TRANSLATIONS keyword") } - # MIF files will have UID in their names, if TARGET.UID3 is not set we need to generate it - isEmpty(TARGET.UID3):TARGET.UID3 = $$generate_test_uid($$TARGET) + # MIF files will have UID in their names, if TARGET.UID3 is not set, remind the user + isEmpty(TARGET.UID3):error("TARGET.UID3 must be explicitly defined for ICON generation") # Note: symbian-sbsv2 builds can't utilize extra compiler for mifconv, so ICON handling is done in code symbian-abld { diff --git a/qmake/generators/symbian/epocroot.h b/qmake/generators/symbian/epocroot.h new file mode 100644 index 0000000..02884b1 --- /dev/null +++ b/qmake/generators/symbian/epocroot.h @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the qmake application of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://www.qtsoftware.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef EPOCROOT_H +#define EPOCROOT_H + +#include + +// Implementation of epocRoot method is in initprojectdeploy_symbian.cpp +// Defined in separate header for inclusion clarity +extern QString epocRoot(); + +#endif // EPOCROOT_H diff --git a/qmake/generators/symbian/initprojectdeploy_symbian.cpp b/qmake/generators/symbian/initprojectdeploy_symbian.cpp index 392eca2..7b58adc 100644 --- a/qmake/generators/symbian/initprojectdeploy_symbian.cpp +++ b/qmake/generators/symbian/initprojectdeploy_symbian.cpp @@ -42,6 +42,8 @@ #include "initprojectdeploy_symbian.h" #include #include +#include +#include #include #define PLUGIN_STUB_DIR "qmakepluginstubs" @@ -51,6 +53,99 @@ #define SUFFIX_EXE "exe" #define SUFFIX_QTPLUGIN "qtplugin" +static void fixEpocRootStr(QString& path) +{ + path.replace("\\", "/"); + + if (path.size() > 1 && path[1] == QChar(':')) { + path = path.mid(2); + } + + if (!path.size() || path[path.size()-1] != QChar('/')) { + path += QChar('/'); + } +} + +#define SYMBIAN_SDKS_KEY "HKEY_LOCAL_MACHINE\\Software\\Symbian\\EPOC SDKs" + +static QString epocRootStr; + +QString epocRoot() +{ + if (!epocRootStr.isEmpty()) { + return epocRootStr; + } + + // First, check the env variable + epocRootStr = qgetenv("EPOCROOT"); + + if (epocRootStr.isEmpty()) { + // No EPOCROOT set, check the default device + // First check EPOCDEVICE env variable + QString defaultDevice = qgetenv("EPOCDEVICE"); + + // Check the windows registry via QSettings for devices.xml path + QSettings settings(SYMBIAN_SDKS_KEY, QSettings::NativeFormat); + QString devicesXmlPath = settings.value("CommonPath").toString(); + + if (!devicesXmlPath.isEmpty()) { + // Parse xml for correct device + devicesXmlPath += "/devices.xml"; + QFile devicesFile(devicesXmlPath); + if (devicesFile.open(QIODevice::ReadOnly)) { + QXmlStreamReader xml(&devicesFile); + while (!xml.atEnd()) { + xml.readNext(); + if (xml.isStartElement() && xml.name() == "devices") { + if (xml.attributes().value("version") == "1.0") { + // Look for correct device + while (!(xml.isEndElement() && xml.name() == "devices") && !xml.atEnd()) { + xml.readNext(); + if (xml.isStartElement() && xml.name() == "device") { + if ((defaultDevice.isEmpty() && xml.attributes().value("default") == "yes") || + (!defaultDevice.isEmpty() && (xml.attributes().value("id").toString() + QString(":") + xml.attributes().value("name").toString()) == defaultDevice)) { + // Found the correct device + while (!(xml.isEndElement() && xml.name() == "device") && !xml.atEnd()) { + xml.readNext(); + if (xml.isStartElement() && xml.name() == "epocroot") { + epocRootStr = xml.readElementText(); + fixEpocRootStr(epocRootStr); + return epocRootStr; + } + } + xml.raiseError("No epocroot element found"); + } + } + } + } else { + xml.raiseError("Invalid 'devices' element version"); + } + } + } + if (xml.hasError()) { + fprintf(stderr, "ERROR: \"%s\" when parsing devices.xml\n", qPrintable(xml.errorString())); + } + } else { + fprintf(stderr, "Could not open devices.xml (%s)\n", qPrintable(devicesXmlPath)); + } + } else { + fprintf(stderr, "Could not retrieve " SYMBIAN_SDKS_KEY " setting\n"); + } + + fprintf(stderr, "Failed to determine epoc root.\n"); + if (!defaultDevice.isEmpty()) + fprintf(stderr, "The device indicated by EPOCDEVICE environment variable (%s) could not be found.\n", qPrintable(defaultDevice)); + fprintf(stderr, "Either set EPOCROOT or EPOCDEVICE environment variable to a valid value, or provide a default Symbian device.\n"); + + // No valid device found; set epocroot to "/" + epocRootStr = QLatin1String("/"); + } + + fixEpocRootStr(epocRootStr); + return epocRootStr; +} + + static bool isPlugin(const QFileInfo& info, const QString& devicePath) { // Libraries are plugins if deployment path is something else than @@ -103,6 +198,44 @@ static void createPluginStub(const QFileInfo& info, Option::fixPathToLocalOS(devicePath + "\\" + stubInfo.fileName()))); } +QString generate_uid(const QString& target) +{ + static QMap targetToUid; + + QString tmp = targetToUid[target]; + + if (!tmp.isEmpty()) { + return tmp; + } + + unsigned long hash = 5381; + int c; + + for (int i = 0; i < target.size(); ++i) { + c = target.at(i).toAscii(); + hash ^= c + ((c - i) << i % 20) + ((c + i) << (i + 5) % 20) + ((c - 2 * i) << (i + 10) % 20) + ((c + 2 * i) << (i + 15) % 20); + } + + tmp.setNum(hash, 16); + for (int i = tmp.size(); i < 8; ++i) + tmp.prepend("0"); + + targetToUid[target] = tmp; + + return tmp; +} + +// UIDs starting with 0xE are test UIDs in symbian +QString generate_test_uid(const QString& target) +{ + QString tmp = generate_uid(target); + tmp.replace(0, 1, "E"); + tmp.prepend("0x"); + + return tmp; +} + + void initProjectDeploySymbian(QMakeProject* project, DeploymentList &deploymentList, const QString &testPath, diff --git a/qmake/generators/symbian/initprojectdeploy_symbian.h b/qmake/generators/symbian/initprojectdeploy_symbian.h index a104985..867a910 100644 --- a/qmake/generators/symbian/initprojectdeploy_symbian.h +++ b/qmake/generators/symbian/initprojectdeploy_symbian.h @@ -50,6 +50,8 @@ #include #include +#include "epocroot.h" + struct CopyItem { CopyItem(const QString& f, const QString& t) : from(f) , to(t) { } @@ -58,6 +60,9 @@ struct CopyItem }; typedef QList DeploymentList; +extern QString generate_uid(const QString& target); +extern QString generate_test_uid(const QString& target); + extern void initProjectDeploySymbian(QMakeProject* project, DeploymentList &deploymentList, const QString &testPath, diff --git a/qmake/generators/symbian/symmake.cpp b/qmake/generators/symbian/symmake.cpp index b3fa0f2..f4886d5 100644 --- a/qmake/generators/symbian/symmake.cpp +++ b/qmake/generators/symbian/symmake.cpp @@ -486,7 +486,7 @@ void SymbianMakefileGenerator::init() // .mmp initMmpVariables(); - // Check TARGET.UID2 and TARGET.UID3 presence + // Check TARGET.UID3 presence if (0 != project->values("TARGET.UID3").size()) { uid3 = project->first("TARGET.UID3"); } else { @@ -1686,4 +1686,5 @@ void SymbianMakefileGenerator::generateDistcleanTargets(QTextStream& t) t << "distclean: clean dodistclean" << endl; t << endl; -} \ No newline at end of file +} + diff --git a/qmake/project.cpp b/qmake/project.cpp index 8455c6d..7239ee9 100644 --- a/qmake/project.cpp +++ b/qmake/project.cpp @@ -44,6 +44,8 @@ #include "option.h" #include "cachekeys.h" +#include "epocroot.h" + #include #include #include @@ -52,8 +54,6 @@ #include #include #include -#include -#include #include #ifdef Q_OS_UNIX #include @@ -79,7 +79,7 @@ enum ExpandFunc { E_MEMBER=1, E_FIRST, E_LAST, E_CAT, E_FROMFILE, E_EVAL, E_LIST E_SPRINTF, E_JOIN, E_SPLIT, E_BASENAME, E_DIRNAME, E_SECTION, E_FIND, E_SYSTEM, E_UNIQUE, E_QUOTE, E_ESCAPE_EXPAND, E_UPPER, E_LOWER, E_FILES, E_PROMPT, E_RE_ESCAPE, E_REPLACE, - E_GENERATE_TEST_UID, E_SIZE }; + E_SIZE }; QMap qmake_expandFunctions() { static QMap *qmake_expand_functions = 0; @@ -110,7 +110,6 @@ QMap qmake_expandFunctions() qmake_expand_functions->insert("files", E_FILES); qmake_expand_functions->insert("prompt", E_PROMPT); qmake_expand_functions->insert("replace", E_REPLACE); - qmake_expand_functions->insert("generate_test_uid", E_GENERATE_TEST_UID); qmake_expand_functions->insert("size", E_SIZE); } return *qmake_expand_functions; @@ -2395,22 +2394,6 @@ QMakeProject::doProjectExpand(QString func, QList args_list, ret += it->replace(before, after); } break; } - case E_GENERATE_TEST_UID: { - if(args.count() != 1) { - fprintf(stderr, "%s:%d: generate_test_uid(targetname) requires one argument.\n", - parser.file.toLatin1().constData(), parser.line_no); - } else { - QString target = args[0]; - - QString currPath = qmake_getpwd(); - target.prepend("/").prepend(currPath); - - - QString tmp = generate_test_uid(target); - - ret += tmp; - } - break; } case E_SIZE: { if(args.count() != 1) { fprintf(stderr, "%s:%d: size(var) requires one argument.\n", @@ -3308,150 +3291,4 @@ QStringList &QMakeProject::values(const QString &_var, QMap targetToUid; - - QString tmp = targetToUid[target]; - - if (!tmp.isEmpty()) { - return tmp; - } - - unsigned long hash = 5381; - int c; - - for (int i = 0; i < target.size(); ++i) { - c = target.at(i).toAscii(); - hash ^= c + ((c - i) << i % 20) + ((c + i) << (i + 5) % 20) + ((c - 2 * i) << (i + 10) % 20) + ((c + 2 * i) << (i + 15) % 20); - } - - tmp.setNum(hash, 16); - for (int i = tmp.size(); i < 8; ++i) - tmp.prepend("0"); - -#if 0 - static QMap uidConflictCheckList; - QString testStr = tmp; - testStr.replace(0, 1, "E"); // Simulate actual UID generation - if (uidConflictCheckList.contains(testStr)) { - printf("\n\n!!!! generated duplicate uid for %s is %s <-> %s !!!!\n\n\n", - qPrintable(target), - qPrintable(testStr), - qPrintable(uidConflictCheckList.value(testStr))); - } - uidConflictCheckList.insert(testStr, target); - printf("generate_uid for %s is %s \n", qPrintable(target), qPrintable(tmp)); -#endif - - targetToUid[target] = tmp; - - return tmp; -} - -static void fixEpocRootStr(QString& path) -{ - path.replace("\\", "/"); - - if (path.size() > 1 && path[1] == QChar(':')) { - path = path.mid(2); - } - - if (!path.size() || path[path.size()-1] != QChar('/')) { - path += QChar('/'); - } -} - -#define SYMBIAN_SDKS_KEY "HKEY_LOCAL_MACHINE\\Software\\Symbian\\EPOC SDKs" - -static QString epocRootStr; - -QString epocRoot() -{ - if (!epocRootStr.isEmpty()) { - return epocRootStr; - } - - // First, check the env variable - epocRootStr = qgetenv("EPOCROOT"); - - if (epocRootStr.isEmpty()) { - // No EPOCROOT set, check the default device - // First check EPOCDEVICE env variable - QString defaultDevice = qgetenv("EPOCDEVICE"); - - // Check the windows registry via QSettings for devices.xml path - QSettings settings(SYMBIAN_SDKS_KEY, QSettings::NativeFormat); - QString devicesXmlPath = settings.value("CommonPath").toString(); - - if (!devicesXmlPath.isEmpty()) { - // Parse xml for correct device - devicesXmlPath += "/devices.xml"; - QFile devicesFile(devicesXmlPath); - if (devicesFile.open(QIODevice::ReadOnly)) { - QXmlStreamReader xml(&devicesFile); - while (!xml.atEnd()) { - xml.readNext(); - if (xml.isStartElement() && xml.name() == "devices") { - if (xml.attributes().value("version") == "1.0") { - // Look for correct device - while (!(xml.isEndElement() && xml.name() == "devices") && !xml.atEnd()) { - xml.readNext(); - if (xml.isStartElement() && xml.name() == "device") { - if ((defaultDevice.isEmpty() && xml.attributes().value("default") == "yes") || - (!defaultDevice.isEmpty() && (xml.attributes().value("id").toString() + QString(":") + xml.attributes().value("name").toString()) == defaultDevice)) { - // Found the correct device - while (!(xml.isEndElement() && xml.name() == "device") && !xml.atEnd()) { - xml.readNext(); - if (xml.isStartElement() && xml.name() == "epocroot") { - epocRootStr = xml.readElementText(); - fixEpocRootStr(epocRootStr); - return epocRootStr; - } - } - xml.raiseError("No epocroot element found"); - } - } - } - } else { - xml.raiseError("Invalid 'devices' element version"); - } - } - } - if (xml.hasError()) { - fprintf(stderr, "ERROR: \"%s\" when parsing devices.xml\n", qPrintable(xml.errorString())); - } - } else { - fprintf(stderr, "Could not open devices.xml (%s)\n", qPrintable(devicesXmlPath)); - } - } else { - fprintf(stderr, "Could not retrieve " SYMBIAN_SDKS_KEY " setting\n"); - } - - fprintf(stderr, "Failed to determine epoc root.\n"); - if (!defaultDevice.isEmpty()) - fprintf(stderr, "The device indicated by EPOCDEVICE environment variable (%s) could not be found.\n", qPrintable(defaultDevice)); - fprintf(stderr, "Either set EPOCROOT or EPOCDEVICE environment variable to a valid value, or provide a default Symbian device.\n"); - - // No valid device found; set epocroot to "/" - epocRootStr = QLatin1String("/"); - } - - fixEpocRootStr(epocRootStr); - return epocRootStr; -} - QT_END_NAMESPACE diff --git a/qmake/project.h b/qmake/project.h index 8d15724..7273c2b 100644 --- a/qmake/project.h +++ b/qmake/project.h @@ -203,10 +203,7 @@ inline QString QMakeProject::first(const QString &v) inline QMap &QMakeProject::variables() { return vars; } -// Helper functions needed for Symbian .mmp files and deployment -QString generate_test_uid(const QString& target); -QString generate_uid(const QString& target); -QString epocRoot(); +// Helper functions needed for Symbian bool isForSymbian(); bool isForSymbianSbsv2(); diff --git a/qmake/qmake.pri b/qmake/qmake.pri index fe15d71..206c1c2 100644 --- a/qmake/qmake.pri +++ b/qmake/qmake.pri @@ -29,6 +29,7 @@ HEADERS += project.h property.h generators/makefile.h \ generators/symbian/symmake.h \ generators/symbian/symmake_abld.h \ generators/symbian/symmake_sbsv2.h \ + generators/symbian/epocroot.h \ generators/symbian/initprojectdeploy_symbian.h contains(QT_EDITION, OpenSource) { diff --git a/tests/auto/qdatastream/qdatastream.pro b/tests/auto/qdatastream/qdatastream.pro index 317c3bf..5b90357 100644 --- a/tests/auto/qdatastream/qdatastream.pro +++ b/tests/auto/qdatastream/qdatastream.pro @@ -22,6 +22,7 @@ wince*: { addFiles.path = . DEPLOYMENT += addFiles TARGET.EPOCHEAPSIZE = 1000000 10000000 + TARGET.UID3 = 0xE0340001 DEFINES += SYMBIAN_SRCDIR_UID=$$lower($$replace(TARGET.UID3,"0x","")) }else { DEFINES += SRCDIR=\\\"$$PWD/\\\" diff --git a/tests/auto/qdir/qdir.pro b/tests/auto/qdir/qdir.pro index 8fe5d83..0111672 100644 --- a/tests/auto/qdir/qdir.pro +++ b/tests/auto/qdir/qdir.pro @@ -16,6 +16,7 @@ wince*:{ QT = core TARGET.CAPABILITY += AllFiles + TARGET.UID3 = 0xE0340002 DEFINES += SYMBIAN_SRCDIR_UID=$$lower($$replace(TARGET.UID3,"0x","")) } else { QT = core diff --git a/tests/auto/qdirmodel/qdirmodel.pro b/tests/auto/qdirmodel/qdirmodel.pro index 6b3a707..19ec231 100644 --- a/tests/auto/qdirmodel/qdirmodel.pro +++ b/tests/auto/qdirmodel/qdirmodel.pro @@ -14,6 +14,7 @@ wince*|symbian: { wince*: { DEFINES += SRCDIR=\\\"./\\\" } symbian: { + TARGET.UID3 = 0xE0340003 DEFINES += SYMBIAN_SRCDIR_UID=$$lower($$replace(TARGET.UID3,"0x","")) } else { DEFINES += SRCDIR=\\\"$$PWD/\\\" diff --git a/tests/auto/qicoimageformat/qicoimageformat.pro b/tests/auto/qicoimageformat/qicoimageformat.pro index 45f616a..c0aa4b5 100644 --- a/tests/auto/qicoimageformat/qicoimageformat.pro +++ b/tests/auto/qicoimageformat/qicoimageformat.pro @@ -18,6 +18,7 @@ wince*: { addPlugins.sources = qico.dll addPlugins.path = imageformats DEPLOYMENT += addFiles addPlugins + TARGET.UID3 = 0xE0340004 DEFINES += SYMBIAN_SRCDIR_UID=$$lower($$replace(TARGET.UID3,"0x","")) } else { DEFINES += SRCDIR=\\\"$$PWD\\\" diff --git a/tests/auto/qlocalsocket/test/test.pro b/tests/auto/qlocalsocket/test/test.pro index da741b9..503f769 100644 --- a/tests/auto/qlocalsocket/test/test.pro +++ b/tests/auto/qlocalsocket/test/test.pro @@ -35,6 +35,7 @@ wince* { symbian { additionalFiles.sources = lackey.exe additionalFiles.path = \sys\bin + TARGET.UID3 = 0xE0340005 DEFINES += SYMBIAN_SRCDIR_UID=$$lower($$replace(TARGET.UID3,"0x","")) } diff --git a/tests/auto/qscriptengine/qscriptengine.pro b/tests/auto/qscriptengine/qscriptengine.pro index 4d1828f..f72c070 100644 --- a/tests/auto/qscriptengine/qscriptengine.pro +++ b/tests/auto/qscriptengine/qscriptengine.pro @@ -10,6 +10,7 @@ wince*|symbian*: { } symbian: { + TARGET.UID3 = 0xE0340006 DEFINES += SYMBIAN_SRCDIR_UID=$$lower($$replace(TARGET.UID3,"0x","")) TARGET.EPOCHEAPSIZE="0x100000 0x1000000 // Min 1Mb, max 16Mb" } -- cgit v0.12