summaryrefslogtreecommitdiffstats
path: root/src/tools
diff options
context:
space:
mode:
authorAlexey Edelev <alexey.edelev@qt.io>2021-08-13 18:40:26 +0200
committerAlexey Edelev <alexey.edelev@qt.io>2021-09-08 23:37:51 +0200
commit42d0089d44bec5628884d8cf6bf2b910a298a141 (patch)
treee9a13ef631c0ada6be853b38c1f4f0a4ec4d7453 /src/tools
parentfd3315bc614c907eef098d6940b9358b193c4327 (diff)
androiddeployqt: Add support of multiple qml root paths
If application uses qml files from multiple locations, e.g. subdirectories inside source directory it's important to provide this information to qmlimportscanner to produce consistent set of QML modules that need to be included into the end-point application apk. This makes possible to specify more than one QT_QML_ROOT_PATH per target and propagates these paths to the qmlimportscanner using androiddeployqt tool. Pick-to: 6.2 Task-number: QTBUG-93340 Change-Id: Ic31017b3f2671108adb6d6118ef1c75f1ccc3ec5 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/androiddeployqt/main.cpp57
1 files changed, 37 insertions, 20 deletions
diff --git a/src/tools/androiddeployqt/main.cpp b/src/tools/androiddeployqt/main.cpp
index 2fa944a95b..bc280dc107 100644
--- a/src/tools/androiddeployqt/main.cpp
+++ b/src/tools/androiddeployqt/main.cpp
@@ -171,7 +171,7 @@ struct Options
QString inputFileName;
QString applicationBinary;
QString applicationArguments;
- QString rootPath;
+ std::vector<QString> rootPaths;
QString rccBinaryPath;
QString depFilePath;
QString buildDirectory;
@@ -1030,8 +1030,17 @@ bool readInputFile(Options *options)
{
const QJsonValue qmlRootPath = jsonObject.value(QLatin1String("qml-root-path"));
- if (!qmlRootPath.isUndefined())
- options->rootPath = qmlRootPath.toString();
+ if (qmlRootPath.isString()) {
+ options->rootPaths.push_back(qmlRootPath.toString());
+ } else if (qmlRootPath.isArray()) {
+ auto qmlRootPaths = qmlRootPath.toArray();
+ for (auto path : qmlRootPaths) {
+ if (path.isString())
+ options->rootPaths.push_back(path.toString());
+ }
+ } else {
+ options->rootPaths.push_back(options->inputFileName);
+ }
}
{
@@ -1671,7 +1680,8 @@ bool readAndroidDependencyXml(Options *options,
QString file = reader.attributes().value(QLatin1String("file")).toString();
// Special case, since this is handled by qmlimportscanner instead
- if (!options->rootPath.isEmpty() && (file == QLatin1String("qml") || file == QLatin1String("qml/")))
+ if (!options->rootPaths.empty()
+ && (file == QLatin1String("qml") || file == QLatin1String("qml/")))
continue;
const QList<QtDependency> fileNames = findFilesRecursively(*options, file);
@@ -1849,6 +1859,7 @@ QString defaultLibexecDir()
}
bool goodToCopy(const Options *options, const QString &file, QStringList *unmetDependencies);
+bool checkQmlFileInRootPaths(const Options *options, const QString &absolutePath);
bool scanImports(Options *options, QSet<QString> *usedDependencies)
{
@@ -1864,16 +1875,6 @@ bool scanImports(Options *options, QSet<QString> *usedDependencies)
qmlImportScanner += QLatin1String(".exe");
#endif
- QString rootPath = options->rootPath;
-
- if (rootPath.isEmpty())
- rootPath = QFileInfo(options->inputFileName).absolutePath();
- else
- rootPath = QFileInfo(rootPath).absoluteFilePath();
-
- if (!rootPath.endsWith(QLatin1Char('/')))
- rootPath += QLatin1Char('/');
-
QStringList importPaths;
importPaths += shellQuote(options->qtInstallDirectory + QLatin1String("/qml"));
@@ -1914,11 +1915,18 @@ bool scanImports(Options *options, QSet<QString> *usedDependencies)
return true;
}
- // After checking for qml folder imports we can add rootPath
- if (!rootPath.isEmpty())
- importPaths += shellQuote(rootPath);
+ for (auto rootPath : options->rootPaths) {
+ rootPath = QFileInfo(rootPath).absoluteFilePath();
+
+ if (!rootPath.endsWith(QLatin1Char('/')))
+ rootPath += QLatin1Char('/');
+
+ // After checking for qml folder imports we can add rootPath
+ if (!rootPath.isEmpty())
+ importPaths += shellQuote(rootPath);
- qmlImportScanner += QLatin1String(" -rootPath %1").arg(shellQuote(rootPath));
+ qmlImportScanner += QLatin1String(" -rootPath %1").arg(shellQuote(rootPath));
+ }
if (!options->qrcFiles.isEmpty()) {
qmlImportScanner += QLatin1String(" -qrcFiles");
@@ -1980,7 +1988,7 @@ bool scanImports(Options *options, QSet<QString> *usedDependencies)
if (!absolutePath.endsWith(QLatin1Char('/')))
absolutePath += QLatin1Char('/');
- if (absolutePath.startsWith(rootPath)) {
+ if (checkQmlFileInRootPaths(options, absolutePath)) {
if (options->verbose)
fprintf(stdout, " -- Skipping because path is in QML root path.\n");
continue;
@@ -2035,6 +2043,15 @@ bool scanImports(Options *options, QSet<QString> *usedDependencies)
return true;
}
+bool checkQmlFileInRootPaths(const Options *options, const QString &absolutePath)
+{
+ for (auto rootPath : options->rootPaths) {
+ if (absolutePath.startsWith(rootPath))
+ return true;
+ }
+ return false;
+}
+
bool runCommand(const Options &options, const QString &command)
{
if (options.verbose)
@@ -2161,7 +2178,7 @@ bool readDependencies(Options *options)
}
}
- if ((!options->rootPath.isEmpty() || options->qrcFiles.isEmpty()) &&
+ if ((!options->rootPaths.empty() || options->qrcFiles.isEmpty()) &&
!scanImports(options, &usedDependencies))
return false;