diff options
| author | Alexey Edelev <[email protected]> | 2021-08-13 18:40:26 +0200 |
|---|---|---|
| committer | Alexey Edelev <[email protected]> | 2021-09-08 23:37:51 +0200 |
| commit | 42d0089d44bec5628884d8cf6bf2b910a298a141 (patch) | |
| tree | e9a13ef631c0ada6be853b38c1f4f0a4ec4d7453 | |
| parent | fd3315bc614c907eef098d6940b9358b193c4327 (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 <[email protected]>
Reviewed-by: Assam Boudjelthia <[email protected]>
| -rw-r--r-- | src/corelib/Qt6AndroidMacros.cmake | 18 | ||||
| -rw-r--r-- | src/tools/androiddeployqt/main.cpp | 57 |
2 files changed, 50 insertions, 25 deletions
diff --git a/src/corelib/Qt6AndroidMacros.cmake b/src/corelib/Qt6AndroidMacros.cmake index c5f04c49bc8..3640624aa33 100644 --- a/src/corelib/Qt6AndroidMacros.cmake +++ b/src/corelib/Qt6AndroidMacros.cmake @@ -187,13 +187,21 @@ function(qt6_android_generate_deployment_settings target) " \"qml-import-paths\": \"${_import_paths}\",\n") endif() - get_target_property(qml_root_path ${target} QT_QML_ROOT_PATH) - if(NOT qml_root_path) - set(qml_root_path "${target_source_dir}") + get_target_property(qml_root_paths ${target} QT_QML_ROOT_PATH) + if(NOT qml_root_paths) + set(qml_root_paths "${target_source_dir}") endif() - file(TO_CMAKE_PATH "${qml_root_path}" qml_root_path_native) + + set(qml_native_root_paths "") + foreach(root_path IN LISTS qml_root_paths) + file(TO_CMAKE_PATH "${root_path}" qml_root_path_native) + list(APPEND qml_native_root_paths "\"${qml_root_path_native}\"") + endforeach() + + list(JOIN qml_native_root_paths "," qml_native_root_paths) + string(APPEND file_contents - " \"qml-root-path\": \"${qml_root_path_native}\",\n") + " \"qml-root-path\": [${qml_native_root_paths}],\n") # App binary string(APPEND file_contents diff --git a/src/tools/androiddeployqt/main.cpp b/src/tools/androiddeployqt/main.cpp index 2fa944a95ba..bc280dc1071 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; |
