aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qmlimportscanner
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2016-12-12 09:22:22 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2016-12-20 19:20:14 +0000
commit68e23adeeb30d1d0e0483abd8e2b308978c79faa (patch)
tree33edd5ffa503c71a5c5b1c13cad46cb64f6ba1e0 /tools/qmlimportscanner
parent0d243a89ac225f4080f16c93e4a6340d0ddc6f0e (diff)
qmlimportscanner: Output the relative path of a plugin
Change 3c5e438890db63ecde98c84d221f87a3af52e1bf enabling using the target path version of a parent module made it harder to determine the deployment target path from the module name. Output the relative path in addition to remove the need to do that in deployment tools. Task-number: QTBUG-57494 Task-number: QTBUG-52556 Change-Id: Ib76f40f19b530f9351205df9109f2fef6191979d Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'tools/qmlimportscanner')
-rw-r--r--tools/qmlimportscanner/main.cpp36
1 files changed, 22 insertions, 14 deletions
diff --git a/tools/qmlimportscanner/main.cpp b/tools/qmlimportscanner/main.cpp
index 1e5f7a9921..b2ff751231 100644
--- a/tools/qmlimportscanner/main.cpp
+++ b/tools/qmlimportscanner/main.cpp
@@ -58,6 +58,7 @@ QStringList g_qmlImportPaths;
static inline QString typeLiteral() { return QStringLiteral("type"); }
static inline QString versionLiteral() { return QStringLiteral("version"); }
static inline QString nameLiteral() { return QStringLiteral("name"); }
+static inline QString relativePathLiteral() { return QStringLiteral("relativePath"); }
static inline QString pluginsLiteral() { return QStringLiteral("plugins"); }
static inline QString pathLiteral() { return QStringLiteral("path"); }
static inline QString classnamesLiteral() { return QStringLiteral("classnames"); }
@@ -162,8 +163,9 @@ QVariantMap pluginsForModulePath(const QString &modulePath) {
return pluginInfo;
}
-// Search for a given qml import in g_qmlImportPaths.
-QString resolveImportPath(const QString &uri, const QString &version)
+// Search for a given qml import in g_qmlImportPaths and return a pair
+// of absolute / relative paths (for deployment).
+QPair<QString, QString> resolveImportPath(const QString &uri, const QString &version)
{
const QLatin1Char dot('.');
const QLatin1Char slash('/');
@@ -180,18 +182,21 @@ QString resolveImportPath(const QString &uri, const QString &version)
// - qml/QtQml.2/Models
// - qml/QtQml/Models
if (ver.isEmpty()) {
- const QString candidatePath = QDir::cleanPath(qmlImportPath + slash + parts.join(slash));
+ QString relativePath = parts.join(slash);
+ if (relativePath.endsWith(slash))
+ relativePath.chop(1);
+ const QString candidatePath = QDir::cleanPath(qmlImportPath + slash + relativePath);
if (QDir(candidatePath).exists())
- return candidatePath; // import found
+ return qMakePair(candidatePath, relativePath); // import found
} else {
for (int index = parts.count() - 1; index >= 0; --index) {
- const QString candidatePath = QDir::cleanPath(qmlImportPath + slash
- + parts.mid(0, index + 1).join(slash)
- + dot + ver + slash
- + parts.mid(index + 1).join(slash));
-
+ QString relativePath = parts.mid(0, index + 1).join(slash)
+ + dot + ver + slash + parts.mid(index + 1).join(slash);
+ if (relativePath.endsWith(slash))
+ relativePath.chop(1);
+ const QString candidatePath = QDir::cleanPath(qmlImportPath + slash + relativePath);
if (QDir(candidatePath).exists())
- return candidatePath; // import found
+ return qMakePair(candidatePath, relativePath); // import found
}
}
}
@@ -207,7 +212,7 @@ QString resolveImportPath(const QString &uri, const QString &version)
ver = ver.mid(0, lastDot);
}
- return QString(); // not found
+ return QPair<QString, QString>(); // not found
}
// Find absolute file system paths and plugins for a list of modules.
@@ -219,9 +224,12 @@ QVariantList findPathsForModuleImports(const QVariantList &imports)
for (int i = 0; i < importsCopy.length(); ++i) {
QVariantMap import = qvariant_cast<QVariantMap>(importsCopy[i]);
if (import[typeLiteral()] == QLatin1String("module")) {
- QString path = resolveImportPath(import.value(nameLiteral()).toString(), import.value(versionLiteral()).toString());
- if (!path.isEmpty())
- import[pathLiteral()] = path;
+ const QPair<QString, QString> paths =
+ resolveImportPath(import.value(nameLiteral()).toString(), import.value(versionLiteral()).toString());
+ if (!paths.first.isEmpty()) {
+ import.insert(pathLiteral(), paths.first);
+ import.insert(relativePathLiteral(), paths.second);
+ }
QVariantMap plugininfo = pluginsForModulePath(import.value(pathLiteral()).toString());
QString plugins = plugininfo.value(pluginsLiteral()).toString();
QString classnames = plugininfo.value(classnamesLiteral()).toString();