diff options
author | Marco Benelli <marco.benelli@theqtcompany.com> | 2016-01-08 11:25:47 +0100 |
---|---|---|
committer | Marco Benelli <marco.benelli@theqtcompany.com> | 2016-02-02 14:58:21 +0000 |
commit | 7b38d8e0025aba6366fd2f222838cf99f6bd15f3 (patch) | |
tree | 1b464c69033a51d233176c414d52e953f85fbefb | |
parent | 1929fee8e17e9ca66e7fe08faa9ed9fa7fdbb127 (diff) |
qmlplugindump: option to merge qmltypes.
QtCreator does not handle dependencies between Qml types defined in
different qmltypes files. Sometimes manual editing of qmltypes file is
needed to let QtCreator find the missing type information.
With the new -merge option it is possible to merge a qmltypes file to
the output of qmlplugindump. Dependencies are correctly merged but
components are simply added, so they could cause conflict.
Change-Id: I6569339e4f05d37ea63fa2173983b4d595ae0ad6
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@theqtcompany.com>
-rw-r--r-- | tools/qmlplugindump/main.cpp | 42 | ||||
-rw-r--r-- | tools/qmlplugindump/qmlplugindump.pro | 6 | ||||
-rw-r--r-- | tools/qmlplugindump/qmltypereader.cpp | 63 | ||||
-rw-r--r-- | tools/qmlplugindump/qmltypereader.h | 42 |
4 files changed, 150 insertions, 3 deletions
diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp index fe92f80bad..393abc8883 100644 --- a/tools/qmlplugindump/main.cpp +++ b/tools/qmlplugindump/main.cpp @@ -56,9 +56,11 @@ #include <QtCore/private/qobject_p.h> #include <QtCore/private/qmetaobject_p.h> +#include <QRegularExpression> #include <iostream> #include <algorithm> +#include "qmltypereader.h" #include "qmlstreamwriter.h" #ifdef QT_SIMULATOR @@ -733,7 +735,7 @@ void sigSegvHandler(int) { void printUsage(const QString &appName) { std::cerr << qPrintable(QString( - "Usage: %1 [-v] [-noinstantiate] [-defaultplatform] [-[non]relocatable] [-dependencies <dependencies.json>] module.uri version [module/import/path]\n" + "Usage: %1 [-v] [-noinstantiate] [-defaultplatform] [-[non]relocatable] [-dependencies <dependencies.json>] [-merge <file-to-merge.qmltypes>] module.uri version [module/import/path]\n" " %1 [-v] [-noinstantiate] -path path/to/qmldir/directory [version]\n" " %1 [-v] -builtins\n" "Example: %1 Qt.labs.folderlistmodel 2.0 /home/user/dev/qt-install/imports").arg( @@ -987,6 +989,7 @@ int main(int argc, char *argv[]) QString pluginImportVersion; bool relocatable = true; QString dependenciesFile; + QString mergeFile; enum Action { Uri, Path, Builtins }; Action action = Uri; { @@ -1005,6 +1008,13 @@ int main(int argc, char *argv[]) return EXIT_INVALIDARGUMENTS; } dependenciesFile = args.at(iArg); + } else if (arg == QLatin1String("--merge") + || arg == QLatin1String("-merge")) { + if (++iArg == args.size()) { + std::cerr << "missing merge file" << std::endl; + return EXIT_INVALIDARGUMENTS; + } + mergeFile = args.at(iArg); } else if (arg == QLatin1String("--notrelocatable") || arg == QLatin1String("-notrelocatable") || arg == QLatin1String("--nonrelocatable") @@ -1066,6 +1076,26 @@ int main(int argc, char *argv[]) QDir::setCurrent(pluginImportPath); engine.addImportPath(pluginImportPath); } + + // Merge file. + QStringList mergeDependencies; + QString mergeComponents; + if (!mergeFile.isEmpty()) { + QStringList merge = readQmlTypes(mergeFile); + if (!merge.isEmpty()) { + QRegularExpression re("(\\w+\\.*\\w*\\s*\\d+\\.\\d+)"); + QRegularExpressionMatchIterator i = re.globalMatch(merge[1]); + while (i.hasNext()) { + QRegularExpressionMatch m = i.next(); + QString d = m.captured(1); + mergeDependencies << m.captured(1); + } + mergeComponents = merge [2]; + } + } + + // Dependencies. + bool calculateDependencies = !pluginImportUri.isEmpty() && !pluginImportVersion.isEmpty(); QStringList dependencies; if (!dependenciesFile.isEmpty()) @@ -1215,6 +1245,13 @@ int main(int argc, char *argv[]) "// '%1 %2'\n" "\n").arg(QFileInfo(args.at(0)).baseName(), args.mid(1).join(QLatin1Char(' ')))); qml.writeStartObject("Module"); + + // Insert merge dependencies. + if (!mergeDependencies.isEmpty()) { + dependencies << mergeDependencies; + } + compactDependencies(&dependencies); + QStringList quotedDependencies; foreach (const QString &dep, dependencies) quotedDependencies << enquote(dep); @@ -1241,6 +1278,9 @@ int main(int argc, char *argv[]) if (pluginImportUri.isEmpty()) dumper.writeEasingCurve(); + // Insert merge file. + qml.write(mergeComponents); + qml.writeEndObject(); qml.writeEndDocument(); diff --git a/tools/qmlplugindump/qmlplugindump.pro b/tools/qmlplugindump/qmlplugindump.pro index 6fdcd349d1..e45a7fad83 100644 --- a/tools/qmlplugindump/qmlplugindump.pro +++ b/tools/qmlplugindump/qmlplugindump.pro @@ -6,10 +6,12 @@ QTPLUGIN.platforms = qminimal SOURCES += \ main.cpp \ - qmlstreamwriter.cpp + qmlstreamwriter.cpp \ + qmltypereader.cpp HEADERS += \ - qmlstreamwriter.h + qmlstreamwriter.h \ + qmltypereader.h macx { # Prevent qmlplugindump from popping up in the dock when launched. diff --git a/tools/qmlplugindump/qmltypereader.cpp b/tools/qmlplugindump/qmltypereader.cpp new file mode 100644 index 0000000000..67ba415388 --- /dev/null +++ b/tools/qmlplugindump/qmltypereader.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmltypereader.h" + +#include <QFileInfo> +#include <QFile> +#include <QRegularExpression> + +#include <iostream> + +QStringList readQmlTypes(const QString &filename) { + QRegularExpression re("import QtQuick.tooling 1.2.*Module {\\s*dependencies:\\[([^\\]]*)\\](.*)}", + QRegularExpression::DotMatchesEverythingOption); + if (!QFileInfo(filename).exists()) { + std::cerr << "Non existing file: " << filename.toStdString() << std::endl; + return QStringList(); + } + QFile f(filename); + if (!f.open(QFileDevice::ReadOnly)) { + std::cerr << "Error in opening file " << filename.toStdString() << " : " + << f.errorString().toStdString() << std::endl; + return QStringList(); + } + QByteArray fileData = f.readAll(); + QString data(fileData); + QRegularExpressionMatch m = re.match(data); + if (m.lastCapturedIndex() != 2) { + std::cerr << "Malformed file: " << filename.toStdString() << std::endl; + return QStringList(); + } + return m.capturedTexts(); +} diff --git a/tools/qmlplugindump/qmltypereader.h b/tools/qmlplugindump/qmltypereader.h new file mode 100644 index 0000000000..b995566e0b --- /dev/null +++ b/tools/qmlplugindump/qmltypereader.h @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the tools applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMLTYPEREADER_H +#define QMLTYPEREADER_H + +#include <QString> +#include <QStringList> + +QStringList readQmlTypes(const QString &filename); + +#endif // QMLTYPEREADER_H |