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 <alexandru.croitor@qt.io>
This commit is contained in:
Alexey Edelev 2021-12-02 18:58:50 +01:00
parent 52402e6522
commit 1d135de5cf
3 changed files with 41 additions and 5 deletions

View File

@ -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()

View File

@ -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) {

View File

@ -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<QString, QVariant> &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;