From fe7fc3f23e4b2f06ade47db1ed3c55f9135bc1fe Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Fri, 3 Dec 2021 18:40:22 +0100 Subject: [PATCH] Copy only files that belongs to QML module Instead of copying all files that the QML module directory contains, this approach only copies files that belong to the QML module according to the qmlimportscanner output. Pick-to: 6.3 Fixes: QTBUG-97834 Change-Id: I881a6fba28ca24be4f33de8693b41b6dfefe8d6b Reviewed-by: Ulf Hermann --- src/tools/androiddeployqt/main.cpp | 77 +++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 23 deletions(-) diff --git a/src/tools/androiddeployqt/main.cpp b/src/tools/androiddeployqt/main.cpp index ff695c3079..d80fdc4398 100644 --- a/src/tools/androiddeployqt/main.cpp +++ b/src/tools/androiddeployqt/main.cpp @@ -2057,7 +2057,7 @@ bool scanImports(Options *options, QSet *usedDependencies) qPrintable(object.value(QLatin1String("name")).toString())); } else { if (options->verbose) - fprintf(stdout, " -- Adding '%s' as QML dependency\n", path.toLocal8Bit().constData()); + fprintf(stdout, " -- Adding '%s' as QML dependency\n", qPrintable(path)); QFileInfo info(path); @@ -2097,30 +2097,61 @@ bool scanImports(Options *options, QSet *usedDependencies) return false; } - QDir dir(importPathOfThisImport); - importPathOfThisImport = dir.absolutePath() + QLatin1Char('/'); - - const QList fileNames = findFilesRecursively(*options, info, importPathOfThisImport); - for (QtDependency fileName : fileNames) { - if (usedDependencies->contains(fileName.absolutePath)) - continue; - - usedDependencies->insert(fileName.absolutePath); - - if (options->verbose) - fprintf(stdout, " -- Appending dependency found by qmlimportscanner: %s\n", qPrintable(fileName.absolutePath)); - - // Put all imports in default import path in assets - fileName.relativePath.prepend(QLatin1String("qml/")); - options->qtDependencies[options->currentArchitecture].append(fileName); - - if (fileName.absolutePath.endsWith(QLatin1String(".so")) && checkArchitecture(*options, fileName.absolutePath)) { - QSet remainingDependencies; - if (!readDependenciesFromElf(options, fileName.absolutePath, usedDependencies, &remainingDependencies)) - return false; - + importPathOfThisImport = QDir(importPathOfThisImport).absolutePath() + QLatin1Char('/'); + QList qmlImportsDependencies; + auto collectQmlDependency = [&usedDependencies, &qmlImportsDependencies, + &importPathOfThisImport](const QString &filePath) { + if (!usedDependencies->contains(filePath)) { + usedDependencies->insert(filePath); + qmlImportsDependencies += QtDependency( + QLatin1String("qml/") + filePath.mid(importPathOfThisImport.size()), + filePath); } + }; + + QString plugin = object.value(QLatin1String("plugin")).toString(); + bool pluginIsOptional = object.value(QLatin1String("pluginIsOptional")).toBool(); + QFileInfo pluginFileInfo = QFileInfo( + path + QLatin1Char('/') + QLatin1String("lib") + plugin + QLatin1Char('_') + + options->currentArchitecture + QLatin1String(".so")); + QString pluginFilePath = pluginFileInfo.absoluteFilePath(); + QSet remainingDependencies; + if (pluginFileInfo.exists() && checkArchitecture(*options, pluginFilePath) + && readDependenciesFromElf(options, pluginFilePath, usedDependencies, + &remainingDependencies)) { + collectQmlDependency(pluginFilePath); + } else if (!pluginIsOptional) { + if (options->verbose) + fprintf(stdout, " -- Skipping because the required plugin is missing.\n"); + continue; } + + QFileInfo qmldirFileInfo = QFileInfo(path + QLatin1Char('/') + QLatin1String("qmldir")); + if (qmldirFileInfo.exists()) { + collectQmlDependency(qmldirFileInfo.absoluteFilePath()); + } + + QVariantList qmlFiles = + object.value(QLatin1String("components")).toArray().toVariantList(); + qmlFiles.append(object.value(QLatin1String("scripts")).toArray().toVariantList()); + bool qmlFilesMissing = false; + for (const auto &qmlFileEntry : qmlFiles) { + QFileInfo fileInfo(qmlFileEntry.toString()); + if (!fileInfo.exists()) { + qmlFilesMissing = true; + break; + } + collectQmlDependency(fileInfo.absoluteFilePath()); + } + + if (qmlFilesMissing) { + if (options->verbose) + fprintf(stdout, + " -- Skipping because the required qml files are missing.\n"); + continue; + } + + options->qtDependencies[options->currentArchitecture].append(qmlImportsDependencies); } }