aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Edelev <alexey.edelev@qt.io>2022-06-22 19:43:29 +0200
committerAlexey Edelev <alexey.edelev@qt.io>2022-06-30 17:52:50 +0200
commit2cc85e60d4313bd845bfdc233e5e75a8b7ccb01f (patch)
tree0fac4020f55427daefff37dd0d16a4254ad1e8a3
parentf9022e847fd8717622a06ef042449be6436ce24a (diff)
Add listing of the components and scripts that belongs to the qml module
Add qml components and scripts to the qmlimportscanner output to give information about files that actually belong to the qml module. Also remove dependency duplicates to reduce the amount of scans are made by qmlimporscanner. Task-number: QTBUG-97834 Task-number: QTBUG-36637 Change-Id: Ic2533a827a716cd9c4e3a2be54ac0beafa666aaa (cherry picked from commit 1d135de5cfef6da7457e5caf1612c0c112cfea7b) Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r--tools/qmlimportscanner/main.cpp66
1 files changed, 54 insertions, 12 deletions
diff --git a/tools/qmlimportscanner/main.cpp b/tools/qmlimportscanner/main.cpp
index 9f6a89810f..52eebcdf65 100644
--- a/tools/qmlimportscanner/main.cpp
+++ b/tools/qmlimportscanner/main.cpp
@@ -71,6 +71,14 @@ inline QString dependenciesLiteral() { return QStringLiteral("dependencies"); }
inline QString moduleLiteral() { return QStringLiteral("module"); }
inline QString javascriptLiteral() { return QStringLiteral("javascript"); }
inline QString directoryLiteral() { return QStringLiteral("directory"); }
+inline QString componentsLiteral()
+{
+ return QStringLiteral("components");
+}
+inline QString scriptsLiteral()
+{
+ return QStringLiteral("scripts");
+}
void printUsage(const QString &appNameIn)
{
@@ -150,21 +158,42 @@ QVariantMap pluginsForModulePath(const QString &modulePath) {
QString plugins;
QString classnames;
QStringList dependencies;
+ QStringList componentFiles;
+ QStringList scriptFiles;
QByteArray line;
do {
line = qmldirFile.readLine();
- if (line.startsWith("plugin")) {
- plugins += QString::fromUtf8(line.split(' ').at(1));
- plugins += QLatin1Char(' ');
- } else if (line.startsWith("classname")) {
- classnames += QString::fromUtf8(line.split(' ').at(1));
- classnames += QLatin1Char(' ');
- } else if (line.startsWith("depends")) {
- const QList<QByteArray> dep = line.split(' ');
- if (dep.length() != 3)
- std::cerr << "depends: expected 2 arguments: module identifier and version" << std::endl;
- else
- dependencies << QString::fromUtf8(dep[1]) + QLatin1Char(' ') + QString::fromUtf8(dep[2]).simplified();
+ const QList<QByteArray> sections = line.split(' ');
+ if (sections.size() > 0) {
+ const QByteArray &sectionType = sections.at(0);
+ if (sectionType == "plugin") {
+ plugins += QString::fromUtf8(line.split(' ').at(1));
+ plugins += QLatin1Char(' ');
+ } else if (sectionType == "classname") {
+ classnames += QString::fromUtf8(line.split(' ').at(1));
+ classnames += QLatin1Char(' ');
+ } else if (sectionType == "depends") {
+ if (sections.size() != 3)
+ std::cerr << "depends: expected 2 arguments: module identifier and version"
+ << std::endl;
+ else
+ dependencies << QString::fromUtf8(sections.at(1)) + QLatin1Char(' ')
+ + QString::fromUtf8(sections.at(2)).simplified();
+ } else if (sections.size() == 2 && sectionType != "module"
+ && sectionType != "typeinfo") {
+ componentFiles.append(modulePath + QLatin1Char('/')
+ + QString::fromUtf8(sections.at(1)));
+ } else if (sections.size() == 3
+ || (sectionType == "singleton" && sections.size() == 4)) {
+ int fileNameIndex = (sectionType == "singleton") ? 3 : 2;
+ const QString fileName = QString::fromUtf8(sections.at(fileNameIndex));
+ const QString filePath = modulePath + QLatin1Char('/') + fileName;
+ if (fileName.endsWith(QLatin1String(".js"))
+ || fileName.endsWith(QLatin1String(".mjs")))
+ scriptFiles.append(filePath);
+ else
+ componentFiles.append(filePath);
+ }
}
} while (line.length() > 0);
@@ -173,7 +202,12 @@ QVariantMap pluginsForModulePath(const QString &modulePath) {
pluginInfo[pluginsLiteral()] = plugins.simplified();
pluginInfo[classnamesLiteral()] = classnames.simplified();
if (dependencies.length())
+ dependencies.removeDuplicates();
pluginInfo[dependenciesLiteral()] = dependencies;
+ if (!componentFiles.isEmpty())
+ pluginInfo[componentsLiteral()] = componentFiles;
+ if (!scriptFiles.isEmpty())
+ pluginInfo[scriptsLiteral()] = scriptFiles;
return pluginInfo;
}
@@ -247,6 +281,8 @@ QVariantList findPathsForModuleImports(const QVariantList &imports)
QVariantMap plugininfo = pluginsForModulePath(import.value(pathLiteral()).toString());
QString plugins = plugininfo.value(pluginsLiteral()).toString();
QString classnames = plugininfo.value(classnamesLiteral()).toString();
+ QStringList components = plugininfo.value(componentsLiteral()).toStringList();
+ QStringList scripts = plugininfo.value(scriptsLiteral()).toStringList();
if (!plugins.isEmpty())
import.insert(QStringLiteral("plugin"), plugins);
if (!classnames.isEmpty())
@@ -262,6 +298,12 @@ QVariantList findPathsForModuleImports(const QVariantList &imports)
importsCopy.append(depImport);
}
}
+ if (!components.isEmpty()) {
+ import.insert(componentsLiteral(), components);
+ }
+ if (!scripts.isEmpty()) {
+ import.insert(scriptsLiteral(), scripts);
+ }
}
done.append(import);
}