aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-07-02 17:40:07 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-07-08 07:46:39 +0000
commite52e7ad76edc6012285db6c83eb12e8724a234ac (patch)
tree3aca0e5e95f94de328397b43c47a830155fa0048 /tools
parent0efc634a9002f57b7cb08eb11d946d9483da42f8 (diff)
qmlplugindump: Fix handling of dependencies
Tolerate dependencies without version and don't write them into the output anymore. No one should read them as the same info has to be available from the associated qmldir files. Change-Id: I5e4cd93c83cb5e874a8a6e1467461d081b1a089c Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/qmlplugindump/main.cpp119
1 files changed, 61 insertions, 58 deletions
diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp
index 0aa163707c..ab26c5b3d5 100644
--- a/tools/qmlplugindump/main.cpp
+++ b/tools/qmlplugindump/main.cpp
@@ -818,8 +818,7 @@ static bool readDependenciesData(QString dependenciesFile, const QByteArray &fil
}
if (doc.isArray()) {
const QStringList requiredKeys = QStringList() << QStringLiteral("name")
- << QStringLiteral("type")
- << QStringLiteral("version");
+ << QStringLiteral("type");
const auto deps = doc.array();
for (const QJsonValue &dep : deps) {
if (dep.isObject()) {
@@ -831,7 +830,7 @@ static bool readDependenciesData(QString dependenciesFile, const QByteArray &fil
continue;
QString name = obj.value((QStringLiteral("name"))).toString();
QString version = obj.value(QStringLiteral("version")).toString();
- if (name.isEmpty() || urisToSkip.contains(name) || version.isEmpty())
+ if (name.isEmpty() || urisToSkip.contains(name))
continue;
if (name.contains(QLatin1String("Private"), Qt::CaseInsensitive)) {
if (verbose)
@@ -842,7 +841,8 @@ static bool readDependenciesData(QString dependenciesFile, const QByteArray &fil
if (verbose)
std::cerr << "appending dependency "
<< qPrintable( name ) << " " << qPrintable(version) << std::endl;
- dependencies->append(name + QLatin1Char(' ')+version);
+ dependencies->append(version.isEmpty() ? name
+ : (name + QLatin1Char(' ') + version));
}
}
} else {
@@ -933,54 +933,68 @@ static bool getDependencies(const QQmlEngine &engine, const QString &pluginImpor
return true;
}
-bool compactDependencies(QStringList *dependencies)
+bool dependencyBetter(const QString &lhs, const QString &rhs)
{
- if (dependencies->isEmpty())
+ QStringList leftSegments = lhs.split(QLatin1Char(' '), Qt::SkipEmptyParts);
+ QStringList rightSegments = rhs.split(QLatin1Char(' '), Qt::SkipEmptyParts);
+
+ if (leftSegments.isEmpty())
+ return false;
+ if (rightSegments.isEmpty())
+ return true;
+
+ const QString leftModule = leftSegments.first();
+ const QString rightModule = rightSegments.first();
+
+ if (leftModule < rightModule)
+ return true;
+ if (leftModule > rightModule)
+ return false;
+
+ if (leftSegments.length() == 1)
return false;
- dependencies->sort();
- QStringList oldDep = dependencies->constFirst().split(QLatin1Char(' '));
- Q_ASSERT(oldDep.size() == 2);
- int oldPos = 0;
- for (int idep = 1; idep < dependencies->size(); ++idep) {
- QString depStr = dependencies->at(idep);
- const QStringList newDep = depStr.split(QLatin1Char(' '));
- Q_ASSERT(newDep.size() == 2);
- if (newDep.constFirst() != oldDep.constFirst()) {
- if (++oldPos != idep)
- dependencies->replace(oldPos, depStr);
- oldDep = newDep;
+ if (rightSegments.length() == 1)
+ return true;
+
+ const QStringList leftVersion = leftSegments.at(1).split(QLatin1Char('.'));
+ const QStringList rightVersion = rightSegments.at(1).split(QLatin1Char('.'));
+
+ auto compareSegment = [&](int segmentIndex) {
+ if (leftVersion.length() <= segmentIndex)
+ return rightVersion.length() > segmentIndex ? 1 : 0;
+ if (rightVersion.length() <= segmentIndex)
+ return -1;
+
+ bool leftOk = false;
+ bool rightOk = false;
+ const int leftSegment = leftSegments[segmentIndex].toUShort(&leftOk);
+ const int rightSegment = rightSegments[segmentIndex].toUShort(&rightOk);
+
+ if (!leftOk)
+ return rightOk ? 1 : 0;
+ if (!rightOk)
+ return -1;
+
+ return rightSegment - leftSegment;
+ };
+
+ const int major = compareSegment(0);
+ return (major == 0) ? compareSegment(1) < 0 : major < 0;
+}
+
+void compactDependencies(QStringList *dependencies)
+{
+ std::sort(dependencies->begin(), dependencies->end(), dependencyBetter);
+ QString currentModule;
+ for (auto it = dependencies->begin(); it != dependencies->end();) {
+ QStringList segments = it->split(QLatin1Char(' '), Qt::SkipEmptyParts);
+ if (segments.isEmpty() || segments.first() == currentModule) {
+ it = dependencies->erase(it);
} else {
- const QStringList v1 = oldDep.constLast().split(QLatin1Char('.'));
- const QStringList v2 = newDep.constLast().split(QLatin1Char('.'));
- Q_ASSERT(v1.size() == 2);
- Q_ASSERT(v2.size() == 2);
- bool ok;
- int major1 = v1.first().toInt(&ok);
- Q_ASSERT(ok);
- int major2 = v2.first().toInt(&ok);
- Q_ASSERT(ok);
- if (major1 != major2) {
- std::cerr << "Found a dependency on " << qPrintable(oldDep.constFirst())
- << " with two major versions:" << qPrintable(oldDep.constLast())
- << " and " << qPrintable(newDep.constLast())
- << " which is unsupported, discarding smaller version" << std::endl;
- if (major1 < major2)
- dependencies->replace(oldPos, depStr);
- } else {
- int minor1 = v1.last().toInt(&ok);
- Q_ASSERT(ok);
- int minor2 = v2.last().toInt(&ok);
- Q_ASSERT(ok);
- if (minor1 < minor2)
- dependencies->replace(oldPos, depStr);
- }
+ currentModule = segments.first();
+ ++it;
}
}
- if (++oldPos < dependencies->size()) {
- *dependencies = dependencies->mid(0, oldPos);
- return true;
- }
- return false;
}
inline std::wostream &operator<<(std::wostream &str, const QString &s)
@@ -1345,17 +1359,6 @@ int main(int argc, char *argv[])
"\n").arg(QFileInfo(args.at(0)).baseName(), args.mid(1).join(QLatin1Char(' '))));
qml.writeStartObject("Module");
- // Insert merge dependencies.
- if (!mergeDependencies.isEmpty()) {
- dependencies << mergeDependencies;
- }
- compactDependencies(&dependencies);
-
- QStringList quotedDependencies;
- for (const QString &dep : qAsConst(dependencies))
- quotedDependencies << enquote(dep);
- qml.writeArrayBinding("dependencies", quotedDependencies);
-
// put the metaobjects into a map so they are always dumped in the same order
QMap<QString, const QMetaObject *> nameToMeta;
for (const QMetaObject *meta : qAsConst(metas))