From a19ed6063a6998943c777d823a0eaacf570dee3a Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 15 Feb 2013 16:07:54 +0100 Subject: [PATCH] Fix Android plugin to support Qt 5 style rules-files In Qt 5 we have modularized the rules files so that each module specifies its own rules. This patch updates the plugin to support reading from these in addition to the rules.xml of Qt 4 so that it should work well for both. The "replaces" attribute of the lib element is also added in Qt 5 because the files are generated and thus the approach of rules.xml where replaces is a separate element and where the order has semantics was not convenient. We of course support the Necessitas approach as well. Change-Id: Ife21903c9faf61e1791cf8c0ea78bb61c74dcb34 Reviewed-by: Daniel Teske Reviewed-by: Paul Olav Tvete --- src/plugins/android/androiddeploystep.cpp | 5 +- src/plugins/android/androidmanager.cpp | 94 ++++++++++++++++------- 2 files changed, 70 insertions(+), 29 deletions(-) diff --git a/src/plugins/android/androiddeploystep.cpp b/src/plugins/android/androiddeploystep.cpp index 7c311ef85fb..73ab60777e3 100644 --- a/src/plugins/android/androiddeploystep.cpp +++ b/src/plugins/android/androiddeploystep.cpp @@ -262,7 +262,10 @@ int AndroidDeployStep::deviceAPILevel() Utils::FileName AndroidDeployStep::localLibsRulesFilePath() { - return AndroidManager::localLibsRulesFilePath(target()); + Utils::FileName fileName = AndroidManager::localLibsRulesFilePath(target()); + fileName.append(QLatin1String("/rules.xml")); + + return fileName; } unsigned int AndroidDeployStep::remoteModificationTime(const QString &fullDestination, QHash *cache) diff --git a/src/plugins/android/androidmanager.cpp b/src/plugins/android/androidmanager.cpp index ee02ca89f5f..11f0ccf4f52 100644 --- a/src/plugins/android/androidmanager.cpp +++ b/src/plugins/android/androidmanager.cpp @@ -558,7 +558,7 @@ Utils::FileName AndroidManager::localLibsRulesFilePath(ProjectExplorer::Target * QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(target->kit()); if (!version) return Utils::FileName(); - return Utils::FileName::fromString(version->qmakeProperty("QT_INSTALL_LIBS") + QLatin1String("/rules.xml")); + return Utils::FileName::fromString(version->qmakeProperty("QT_INSTALL_LIBS")); } QString AndroidManager::loadLocalLibs(ProjectExplorer::Target *target, int apiLevel) @@ -708,41 +708,79 @@ QString AndroidManager::loadLocal(ProjectExplorer::Target *target, int apiLevel, QString localLibs; - QDomDocument doc; - if (!openXmlFile(doc, localLibsRulesFilePath(target))) + QDir rulesFilesDir(localLibsRulesFilePath(target).toString()); + if (!rulesFilesDir.exists()) return localLibs; QStringList libs; libs << qtLibs(target) << prebundledLibs(target); - QDomElement element = doc.documentElement().firstChildElement(QLatin1String("platforms")).firstChildElement(itemType + QLatin1Char('s')).firstChildElement(QLatin1String("version")); - while (!element.isNull()) { - if (element.attribute(QLatin1String("value")).toInt() == apiLevel) { - if (element.hasAttribute(QLatin1String("symlink"))) - apiLevel = element.attribute(QLatin1String("symlink")).toInt(); - break; + + QFileInfoList rulesFiles = rulesFilesDir.entryInfoList(QStringList() << QLatin1String("*.xml"), + QDir::Files | QDir::Readable); + + QStringList dependencyLibs; + QStringList replacedLibs; + foreach (QFileInfo rulesFile, rulesFiles) { + if (rulesFile.baseName() != QLatin1String("rules") + && !rulesFile.baseName().endsWith(QLatin1String("-android-dependencies"))) { + continue; + } + + QDomDocument doc; + if (!openXmlFile(doc, Utils::FileName::fromString(rulesFile.absoluteFilePath()))) + return localLibs; + + QDomElement element = doc.documentElement().firstChildElement(QLatin1String("platforms")).firstChildElement(itemType + QLatin1Char('s')).firstChildElement(QLatin1String("version")); + while (!element.isNull()) { + if (element.attribute(QLatin1String("value")).toInt() == apiLevel) { + if (element.hasAttribute(QLatin1String("symlink"))) + apiLevel = element.attribute(QLatin1String("symlink")).toInt(); + break; + } + element = element.nextSiblingElement(QLatin1String("version")); + } + + element = doc.documentElement().firstChildElement(QLatin1String("dependencies")).firstChildElement(QLatin1String("lib")); + while (!element.isNull()) { + if (libs.contains(element.attribute(QLatin1String("name")))) { + QDomElement libElement = element.firstChildElement(QLatin1String("depends")).firstChildElement(itemType); + while (!libElement.isNull()) { + if (libElement.hasAttribute(attribute)) { + QString dependencyLib = libElement.attribute(attribute).arg(apiLevel); + if (!dependencyLibs.contains(dependencyLib)) + dependencyLibs << dependencyLib; + } + + if (libElement.hasAttribute(QLatin1String("replaces"))) { + QString replacedLib = libElement.attribute(QLatin1String("replaces")).arg(apiLevel); + if (!replacedLibs.contains(replacedLib)) + replacedLibs << replacedLib; + } + + libElement = libElement.nextSiblingElement(itemType); + } + + libElement = element.firstChildElement(QLatin1String("replaces")).firstChildElement(itemType); + while (!libElement.isNull()) { + if (libElement.hasAttribute(attribute)) { + QString replacedLib = libElement.attribute(attribute).arg(apiLevel); + if (!replacedLibs.contains(replacedLib)) + replacedLibs << replacedLib; + } + + libElement = libElement.nextSiblingElement(itemType); + } + } + element = element.nextSiblingElement(QLatin1String("lib")); } - element = element.nextSiblingElement(QLatin1String("version")); } - element = doc.documentElement().firstChildElement(QLatin1String("dependencies")).firstChildElement(QLatin1String("lib")); - while (!element.isNull()) { - if (libs.contains(element.attribute(QLatin1String("name")))) { - QDomElement libElement = element.firstChildElement(QLatin1String("depends")).firstChildElement(itemType); - while (!libElement.isNull()) { - if (libElement.hasAttribute(attribute)) - localLibs += libElement.attribute(attribute).arg(apiLevel) + QLatin1Char(':'); - libElement = libElement.nextSiblingElement(itemType); - } + // The next loop requires all library names to end with a ":" so we append one + // to the end after joining. + localLibs = dependencyLibs.join(QLatin1Char(':')) + QLatin1Char(':'); + foreach (QString replacedLib, replacedLibs) + localLibs.remove(replacedLib + QLatin1Char(':')); - libElement = element.firstChildElement(QLatin1String("replaces")).firstChildElement(itemType); - while (!libElement.isNull()) { - if (libElement.hasAttribute(attribute)) - localLibs.replace(libElement.attribute(attribute).arg(apiLevel) + QLatin1Char(':'), QString()); - libElement = libElement.nextSiblingElement(itemType); - } - } - element = element.nextSiblingElement(QLatin1String("lib")); - } return localLibs; }