Android: Improve qmldir discovery of QML to Java codegen

Recursively find all qml modules, built by this project.
Later, the qmldir of these modules will be used to
generated to code.

The command line argument -i of qmldom tool had
to be replaced with -I. The -i was incorrect as it
expects the qmldir file while -I accepts a QML directory
to be included.

Fixes: QTBUG-125892
Fixes: QTBUG-125970
Change-Id: I4099e488d3d7f4b79566e6ea19eca95f57f7c2fd
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit 7ed88eb565d40b195aa868e67777872ef07a5ea2)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit b141854d76f062b7674c0d055e0139bd40b3bc4d)
This commit is contained in:
Soheil Armin 2024-11-05 18:17:22 +02:00 committed by Qt Cherry-pick Bot
parent d629b9574b
commit c47b638c2a

View File

@ -4,6 +4,7 @@
#include <QCoreApplication>
#include <QStringList>
#include <QDir>
#include <QDirIterator>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
@ -3458,9 +3459,7 @@ bool writeDependencyFile(const Options &options)
int generateJavaQmlComponents(const Options &options)
{
// TODO QTBUG-125892: Current method of path discovery are to be improved
// For instance, it does not discover statically linked **inner** QML modules.
const auto getImportPaths = [](const QString &buildPath, const QString &libName,
const auto getImportPaths = [options](const QString &buildPath, const QString &libName,
QStringList &appImports, QStringList &externalImports) -> bool {
QFile confRspFile("%1/.qt/qml_imports/%2_conf.rsp"_L1.arg(buildPath, libName));
if (!confRspFile.exists() || !confRspFile.open(QFile::ReadOnly))
@ -3476,6 +3475,22 @@ int generateJavaQmlComponents(const Options &options)
externalImports << currentLine;
}
}
// Find inner qmldir files
QSet<QString> qmldirDirectories;
for (const QString &path : appImports) {
QDirIterator it(path, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
while (it.hasNext()) {
const QDir dir(it.next());
const QString absolutePath = dir.absolutePath();
if (!absolutePath.startsWith(options.outputDirectory)
&& dir.exists("qmldir"_L1)) {
qmldirDirectories.insert(absolutePath);
}
}
}
appImports << qmldirDirectories.values();
return appImports.count() + externalImports.count();
};
@ -3497,6 +3512,7 @@ int generateJavaQmlComponents(const Options &options)
if (!qmlDirFile.exists() || !qmlDirFile.open(QFile::ReadOnly))
return ModuleInfo();
ModuleInfo moduleInfo;
QSet<QString> qmlComponentNames;
QTextStream qmldirStream(&qmlDirFile);
while (!qmldirStream.atEnd()) {
const QString currentLine = qmldirStream.readLine();
@ -3509,8 +3525,10 @@ int generateJavaQmlComponents(const Options &options)
} else if (currentLine.size()
&& (currentLine[0].isUpper() || currentLine.startsWith("singleton"_L1))) {
const QStringList parts = currentLine.split(" "_L1);
if (parts.size() > 2)
if (parts.size() > 2 && !qmlComponentNames.contains(parts.first())) {
moduleInfo.qmlComponents.append({ parts.first(), parts.last() });
qmlComponentNames.insert(parts.first());
}
}
}
return moduleInfo;
@ -3522,7 +3540,7 @@ int generateJavaQmlComponents(const Options &options)
QByteArray domInfo;
QString importFlags;
for (auto &importPath : otherImportPaths)
importFlags.append(" -i %1"_L1.arg(shellQuote(importPath)));
importFlags.append(" -I %1"_L1.arg(shellQuote(importPath)));
const QString qmlDomCmd = "%1 -d -D required -f +:propertyInfos %2 %3"_L1.arg(
shellQuote(qmlDomExecPath), importFlags,