From 10372c074bf2975ccb5e4afd3bba0f2738e0a1d5 Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Mon, 7 Nov 2022 16:35:42 +0100 Subject: [PATCH] Make sure that module can be imported by the provided QML import path When resolving QML module dependencies we scan the produced by the build system import paths for the required QML modules. Previously the check in androiddeployqt only was confirming that the required import starts with the one of import paths. This worked well unless the required import is nested in higher level import path. In the situation when we have the following build structure: build_dir/ imports/ MyModule/ ... and both 'build_dir' and 'build_dir/imports' directories are in QML import paths, the MyModule QML module is resolved by the 'build_dir/imports'. But androiddeployqt assumed that it's found by 'build_dir' import path and copied the whole 'imports' directory as the 'MyModule' QML module. The resulting bundle then had the following content: qml/ imports/ MyModule/ ... ... instead of the correct one: qml/ MyModule/ ... ... This checks if import path contains the required url-based module path before using it as the base directory to copy the module. Amends 0a73fb10005053945571e6cdb0b03d916715c112 Pick-to: 6.2 6.4 Fixes: QTBUG-108194 Change-Id: I79e1a8a67f62e5ae4a899ba1a4f49ee4ad44ebf9 Reviewed-by: Qt CI Bot Reviewed-by: Dominik Holland --- src/tools/androiddeployqt/main.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/tools/androiddeployqt/main.cpp b/src/tools/androiddeployqt/main.cpp index 1575ea9b24..2ad27d439a 100644 --- a/src/tools/androiddeployqt/main.cpp +++ b/src/tools/androiddeployqt/main.cpp @@ -228,7 +228,7 @@ static const QHash elfArchitectures = { bool goodToCopy(const Options *options, const QString &file, QStringList *unmetDependencies); bool checkCanImportFromRootPaths(const Options *options, const QString &absolutePath, - const QUrl &moduleUrl); + const QString &moduleUrl); bool readDependenciesFromElf(Options *options, const QString &fileName, QSet *usedDependencies, QSet *remainingDependencies); @@ -2076,7 +2076,8 @@ bool scanImports(Options *options, QSet *usedDependencies) const QUrl url(object.value("name"_L1).toString()); - if (checkCanImportFromRootPaths(options, info.absolutePath(), url)) { + const QString moduleUrlPath = u"/"_s + url.toString().replace(u'.', u'/'); + if (checkCanImportFromRootPaths(options, info.absolutePath(), moduleUrlPath)) { if (options->verbose) fprintf(stdout, " -- Skipping because path is in QML root path.\n"); continue; @@ -2084,13 +2085,8 @@ bool scanImports(Options *options, QSet *usedDependencies) QString importPathOfThisImport; for (const QString &importPath : std::as_const(importPaths)) { -#if defined(Q_OS_WIN32) - Qt::CaseSensitivity caseSensitivity = Qt::CaseInsensitive; -#else - Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive; -#endif QString cleanImportPath = QDir::cleanPath(importPath); - if (info.absoluteFilePath().startsWith(cleanImportPath, caseSensitivity)) { + if (QFile::exists(cleanImportPath + moduleUrlPath)) { importPathOfThisImport = importPath; break; } @@ -2169,11 +2165,10 @@ bool scanImports(Options *options, QSet *usedDependencies) } bool checkCanImportFromRootPaths(const Options *options, const QString &absolutePath, - const QUrl &moduleUrl) + const QString &moduleUrlPath) { - const QString pathFromUrl = u"/"_s + moduleUrl.toString().replace(u'.', u'/'); for (auto rootPath : options->rootPaths) { - if ((rootPath + pathFromUrl) == absolutePath) + if ((rootPath + moduleUrlPath) == absolutePath) return true; } return false;