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 --- 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 + 7 files changed, 197 insertions(+), 172 deletions(-) create mode 100644 qmake/generators/symbian/epocroot.h (limited to 'qmake') diff --git a/qmake/generators/symbian/epocroot.h b/qmake/generators/symbian/epocroot.h new file mode 100644 index 0000000000..02884b178f --- /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 392eca235e..7b58adca9b 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 a104985e1e..867a910ce4 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 b3fa0f2ef8..f4886d5597 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 8455c6d723..7239ee97bb 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 8d15724139..7273c2b1c8 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 fe15d71e1a..206c1c24c3 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) { -- cgit v1.2.3