From 1d135de5cfef6da7457e5caf1612c0c112cfea7b Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Thu, 2 Dec 2021 18:58:50 +0100 Subject: [PATCH] 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. Pick-to: 6.3 Task-number: QTBUG-97834 Change-Id: I41394ba6fe9d9fe3af74786b4a802903849ae27d Reviewed-by: Alexandru Croitor --- src/qml/Qt6QmlMacros.cmake | 2 +- .../qmlimportscanner/tst_qmlimportscanner.cpp | 2 + tools/qmlimportscanner/main.cpp | 42 +++++++++++++++++-- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake index a5cea6f01a..e2bef207d3 100644 --- a/src/qml/Qt6QmlMacros.cmake +++ b/src/qml/Qt6QmlMacros.cmake @@ -2427,7 +2427,7 @@ macro(_qt_internal_parse_qml_imports_entry prefix index) cmake_parse_arguments("${prefix}" "" "CLASSNAME;NAME;PATH;PLUGIN;RELATIVEPATH;TYPE;VERSION;LINKTARGET" - "" + "COMPONENTS;SCRIPTS" ${qml_import_scanner_import_${index}} ) endmacro() diff --git a/tests/auto/qml/qmlimportscanner/tst_qmlimportscanner.cpp b/tests/auto/qml/qmlimportscanner/tst_qmlimportscanner.cpp index 2d339cc33d..1212cd3c82 100644 --- a/tests/auto/qml/qmlimportscanner/tst_qmlimportscanner.cpp +++ b/tests/auto/qml/qmlimportscanner/tst_qmlimportscanner.cpp @@ -196,6 +196,8 @@ void TestQmlimportscanner::runQmlimportscanner(const QString &mode, const QStrin } #endif + object.remove("components"); + object.remove("scripts"); bool found = false; for (auto it = expectedArray.begin(), end = expectedArray.end(); it != end; ++it) { if (*it == object) { diff --git a/tools/qmlimportscanner/main.cpp b/tools/qmlimportscanner/main.cpp index 85542cbba8..c14fda2422 100644 --- a/tools/qmlimportscanner/main.cpp +++ b/tools/qmlimportscanner/main.cpp @@ -73,6 +73,8 @@ inline QString linkTargetLiteral() { return QStringLiteral("linkTarget"); } +inline QString componentsLiteral() { return QStringLiteral("components"); } +inline QString scriptsLiteral() { return QStringLiteral("scripts"); } void printUsage(const QString &appNameIn) { @@ -218,15 +220,21 @@ QVariantMap pluginsForModulePath(const QString &modulePath, const QString &versi } QVariantList importsFromFiles; + QStringList componentFiles; + QStringList scriptFiles; const auto components = parser.components(); for (const auto &component : components) { + const QString componentFullPath = modulePath + QLatin1Char('/') + component.fileName; + componentFiles.append(componentFullPath); importsFromFiles - += findQmlImportsInQmlFile(modulePath + QLatin1Char('/') + component.fileName); + += findQmlImportsInQmlFile(componentFullPath); } const auto scripts = parser.scripts(); for (const auto &script : scripts) { + const QString scriptFullPath = modulePath + QLatin1Char('/') + script.fileName; + scriptFiles.append(scriptFullPath); importsFromFiles - += findQmlImportsInJavascriptFile(modulePath + QLatin1Char('/') + script.fileName); + += findQmlImportsInJavascriptFile(scriptFullPath); } for (const QVariant &import : importsFromFiles) { @@ -241,6 +249,10 @@ QVariantMap pluginsForModulePath(const QString &modulePath, const QString &versi if (!importsAndDependencies.isEmpty()) pluginInfo[dependenciesLiteral()] = importsAndDependencies; + if (!componentFiles.isEmpty()) + pluginInfo[componentsLiteral()] = componentFiles; + if (!scriptFiles.isEmpty()) + pluginInfo[scriptsLiteral()] = scriptFiles; return pluginInfo; } @@ -332,6 +344,8 @@ QVariantList findPathsForModuleImports(const QVariantList &imports) QString plugins = plugininfo.value(pluginsLiteral()).toString(); bool isOptional = plugininfo.value(pluginIsOptionalLiteral(), QVariant(false)).toBool(); QString classnames = plugininfo.value(classnamesLiteral()).toString(); + QStringList components = plugininfo.value(componentsLiteral()).toStringList(); + QStringList scripts = plugininfo.value(scriptsLiteral()).toStringList(); if (!linkTarget.isEmpty()) import.insert(linkTargetLiteral(), linkTarget); if (!plugins.isEmpty()) @@ -355,6 +369,14 @@ QVariantList findPathsForModuleImports(const QVariantList &imports) importsCopy.append(depImport); } } + if (!components.isEmpty()) { + components.removeDuplicates(); + import.insert(componentsLiteral(), components); + } + if (!scripts.isEmpty()) { + scripts.removeDuplicates(); + import.insert(scriptsLiteral(), scripts); + } } import.remove(versionLiteral()); done.append(import); @@ -585,8 +607,20 @@ QString generateCmakeIncludeFileContent(const QVariantList &importList) { const QMap &importDict = importVariant.toMap(); for (auto it = importDict.cbegin(); it != importDict.cend(); ++it) { - s << it.key().toUpper() << QLatin1Char(';') - << it.value().toString() << QLatin1Char(';'); + s << it.key().toUpper() << QLatin1Char(';'); + // QVariant can implicitly convert QString to the QStringList with the single + // element, let's use this. + QStringList args = it.value().toStringList(); + if (args.isEmpty()) { + // This should not happen, but if it does, the result of the + // 'cmake_parse_arguments' call will be incorrect, so follow up semicolon + // indicates that the single-/multiarg option is empty. + s << QLatin1Char(';'); + } else { + for (auto arg : args) { + s << arg << QLatin1Char(';'); + } + } } s << QStringLiteral("\")\n"); ++importsCount;