2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-11-10 15:07:53 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-11-10 15:07:53 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-11-10 15:07:53 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:58:39 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-11-10 15:07:53 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 17:14:20 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-11-10 15:07:53 +01:00
|
|
|
|
|
|
|
|
#include "qmljsplugindumper.h"
|
2014-01-23 14:28:31 +01:00
|
|
|
#include "qmljsmodelmanagerinterface.h"
|
2017-09-28 16:24:13 +02:00
|
|
|
#include "qmljsutils.h"
|
2010-11-10 15:07:53 +01:00
|
|
|
|
|
|
|
|
#include <qmljs/qmljsinterpreter.h>
|
2016-02-26 17:28:30 +01:00
|
|
|
#include <qmljs/qmljsviewercontext.h>
|
2019-06-21 08:40:47 +02:00
|
|
|
|
|
|
|
|
#include <utils/algorithm.h>
|
2011-04-15 15:55:11 +02:00
|
|
|
#include <utils/filesystemwatcher.h>
|
2011-03-30 15:15:15 +02:00
|
|
|
#include <utils/fileutils.h>
|
2016-09-10 22:56:52 +03:00
|
|
|
#include <utils/hostosinfo.h>
|
2020-04-17 11:40:42 +02:00
|
|
|
#include <utils/runextensions.h>
|
2010-11-10 15:07:53 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
2020-03-26 12:17:03 +01:00
|
|
|
#include <QDirIterator>
|
2016-04-20 15:51:04 +02:00
|
|
|
#include <QRegularExpression>
|
2010-11-10 15:07:53 +01:00
|
|
|
|
2010-12-03 11:17:25 +01:00
|
|
|
using namespace LanguageUtils;
|
2010-11-10 15:07:53 +01:00
|
|
|
using namespace QmlJS;
|
|
|
|
|
|
2014-01-23 14:28:31 +01:00
|
|
|
PluginDumper::PluginDumper(ModelManagerInterface *modelManager)
|
2010-11-10 15:07:53 +01:00
|
|
|
: QObject(modelManager)
|
|
|
|
|
, m_modelManager(modelManager)
|
2019-07-31 17:21:41 +02:00
|
|
|
, m_pluginWatcher(nullptr)
|
2010-11-10 15:07:53 +01:00
|
|
|
{
|
2011-06-28 12:01:56 +02:00
|
|
|
qRegisterMetaType<QmlJS::ModelManagerInterface::ProjectInfo>("QmlJS::ModelManagerInterface::ProjectInfo");
|
2011-04-15 15:55:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utils::FileSystemWatcher *PluginDumper::pluginWatcher()
|
|
|
|
|
{
|
|
|
|
|
if (!m_pluginWatcher) {
|
|
|
|
|
m_pluginWatcher = new Utils::FileSystemWatcher(this);
|
|
|
|
|
m_pluginWatcher->setObjectName(QLatin1String("PluginDumperWatcher"));
|
2016-06-27 22:25:11 +03:00
|
|
|
connect(m_pluginWatcher, &Utils::FileSystemWatcher::fileChanged,
|
|
|
|
|
this, &PluginDumper::pluginChanged);
|
2011-04-15 15:55:11 +02:00
|
|
|
}
|
|
|
|
|
return m_pluginWatcher;
|
2010-11-10 15:07:53 +01:00
|
|
|
}
|
|
|
|
|
|
2011-06-28 12:01:56 +02:00
|
|
|
void PluginDumper::loadBuiltinTypes(const QmlJS::ModelManagerInterface::ProjectInfo &info)
|
|
|
|
|
{
|
|
|
|
|
// move to the owning thread
|
2020-11-11 16:34:39 +01:00
|
|
|
metaObject()->invokeMethod(this, [=] { onLoadBuiltinTypes(info); });
|
2011-06-28 12:01:56 +02:00
|
|
|
}
|
|
|
|
|
|
2011-02-08 13:29:21 +01:00
|
|
|
void PluginDumper::loadPluginTypes(const QString &libraryPath, const QString &importPath, const QString &importUri, const QString &importVersion)
|
2010-11-10 15:07:53 +01:00
|
|
|
{
|
|
|
|
|
// move to the owning thread
|
2020-11-11 16:34:39 +01:00
|
|
|
metaObject()->invokeMethod(this, [=] { onLoadPluginTypes(libraryPath, importPath,
|
|
|
|
|
importUri, importVersion); });
|
2010-11-10 15:07:53 +01:00
|
|
|
}
|
|
|
|
|
|
2011-06-28 12:01:56 +02:00
|
|
|
void PluginDumper::scheduleRedumpPlugins()
|
|
|
|
|
{
|
|
|
|
|
// move to the owning thread
|
2020-11-11 16:34:39 +01:00
|
|
|
metaObject()->invokeMethod(this, &PluginDumper::dumpAllPlugins, Qt::QueuedConnection);
|
2011-06-28 12:01:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PluginDumper::onLoadBuiltinTypes(const QmlJS::ModelManagerInterface::ProjectInfo &info, bool force)
|
|
|
|
|
{
|
2019-01-17 14:06:53 +01:00
|
|
|
if (info.qmlDumpPath.isEmpty() || info.qtQmlPath.isEmpty())
|
2011-06-28 12:01:56 +02:00
|
|
|
return;
|
|
|
|
|
|
2019-01-17 14:06:53 +01:00
|
|
|
const QString importsPath = QDir::cleanPath(info.qtQmlPath);
|
2011-06-28 12:01:56 +02:00
|
|
|
if (m_runningQmldumps.values().contains(importsPath))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
LibraryInfo builtinInfo;
|
|
|
|
|
if (!force) {
|
|
|
|
|
const Snapshot snapshot = m_modelManager->snapshot();
|
2019-01-17 14:06:53 +01:00
|
|
|
builtinInfo = snapshot.libraryInfo(info.qtQmlPath);
|
2011-06-28 12:01:56 +02:00
|
|
|
if (builtinInfo.isValid())
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
builtinInfo = LibraryInfo(LibraryInfo::Found);
|
2019-01-17 14:06:53 +01:00
|
|
|
m_modelManager->updateLibraryInfo(info.qtQmlPath, builtinInfo);
|
2011-06-28 12:01:56 +02:00
|
|
|
|
2014-11-24 18:03:23 +01:00
|
|
|
// prefer QTDIR/qml/builtins.qmltypes if available
|
2019-01-17 14:06:53 +01:00
|
|
|
const QString builtinQmltypesPath = info.qtQmlPath + QLatin1String("/builtins.qmltypes");
|
2011-06-28 12:01:56 +02:00
|
|
|
if (QFile::exists(builtinQmltypesPath)) {
|
2019-01-17 14:06:53 +01:00
|
|
|
loadQmltypesFile(QStringList(builtinQmltypesPath), info.qtQmlPath, builtinInfo);
|
2011-06-28 12:01:56 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-17 14:06:53 +01:00
|
|
|
runQmlDump(info, QStringList(QLatin1String("--builtins")), info.qtQmlPath);
|
|
|
|
|
m_qtToInfo.insert(info.qtQmlPath, info);
|
2011-06-28 12:01:56 +02:00
|
|
|
}
|
|
|
|
|
|
2011-09-02 13:25:08 +02:00
|
|
|
static QString makeAbsolute(const QString &path, const QString &base)
|
|
|
|
|
{
|
|
|
|
|
if (QFileInfo(path).isAbsolute())
|
|
|
|
|
return path;
|
2014-09-02 14:40:41 +02:00
|
|
|
return QString::fromLatin1("%1/%3").arg(base, path);
|
2011-09-02 13:25:08 +02:00
|
|
|
}
|
|
|
|
|
|
2011-02-08 13:29:21 +01:00
|
|
|
void PluginDumper::onLoadPluginTypes(const QString &libraryPath, const QString &importPath, const QString &importUri, const QString &importVersion)
|
2010-11-10 15:07:53 +01:00
|
|
|
{
|
|
|
|
|
const QString canonicalLibraryPath = QDir::cleanPath(libraryPath);
|
|
|
|
|
if (m_runningQmldumps.values().contains(canonicalLibraryPath))
|
|
|
|
|
return;
|
|
|
|
|
const Snapshot snapshot = m_modelManager->snapshot();
|
2010-11-26 14:24:59 +01:00
|
|
|
const LibraryInfo libraryInfo = snapshot.libraryInfo(canonicalLibraryPath);
|
2011-05-12 15:29:00 +02:00
|
|
|
if (libraryInfo.pluginTypeInfoStatus() != LibraryInfo::NoTypeInfo)
|
2010-11-10 15:07:53 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// avoid inserting the same plugin twice
|
|
|
|
|
int index;
|
|
|
|
|
for (index = 0; index < m_plugins.size(); ++index) {
|
|
|
|
|
if (m_plugins.at(index).qmldirPath == libraryPath)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (index == m_plugins.size())
|
|
|
|
|
m_plugins.append(Plugin());
|
|
|
|
|
|
|
|
|
|
Plugin &plugin = m_plugins[index];
|
|
|
|
|
plugin.qmldirPath = canonicalLibraryPath;
|
|
|
|
|
plugin.importPath = importPath;
|
|
|
|
|
plugin.importUri = importUri;
|
2011-02-08 13:29:21 +01:00
|
|
|
plugin.importVersion = importVersion;
|
2010-11-10 15:07:53 +01:00
|
|
|
|
2011-09-02 13:25:08 +02:00
|
|
|
// add default qmltypes file if it exists
|
2020-03-26 12:17:03 +01:00
|
|
|
QDirIterator it(canonicalLibraryPath, QStringList { "*.qmltypes" }, QDir::Files);
|
|
|
|
|
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
const QString defaultQmltypesPath = makeAbsolute(it.next(), canonicalLibraryPath);
|
|
|
|
|
|
|
|
|
|
if (!plugin.typeInfoPaths.contains(defaultQmltypesPath))
|
2019-10-22 16:29:40 +02:00
|
|
|
plugin.typeInfoPaths += defaultQmltypesPath;
|
|
|
|
|
}
|
2011-09-02 13:25:08 +02:00
|
|
|
|
|
|
|
|
// add typeinfo files listed in qmldir
|
2014-01-16 11:43:59 +01:00
|
|
|
foreach (const QmlDirParser::TypeInfo &typeInfo, libraryInfo.typeInfos()) {
|
|
|
|
|
QString pathNow = makeAbsolute(typeInfo.fileName, canonicalLibraryPath);
|
|
|
|
|
if (!plugin.typeInfoPaths.contains(pathNow) && QFile::exists(pathNow))
|
|
|
|
|
plugin.typeInfoPaths += pathNow;
|
|
|
|
|
}
|
2011-09-02 13:25:08 +02:00
|
|
|
|
2010-11-26 14:24:59 +01:00
|
|
|
// watch plugin libraries
|
2010-11-10 15:07:53 +01:00
|
|
|
foreach (const QmlDirParser::Plugin &plugin, snapshot.libraryInfo(canonicalLibraryPath).plugins()) {
|
|
|
|
|
const QString pluginLibrary = resolvePlugin(canonicalLibraryPath, plugin.path, plugin.name);
|
2011-08-17 11:59:15 +02:00
|
|
|
if (!pluginLibrary.isEmpty()) {
|
|
|
|
|
if (!pluginWatcher()->watchesFile(pluginLibrary))
|
|
|
|
|
pluginWatcher()->addFile(pluginLibrary, Utils::FileSystemWatcher::WatchModifiedDate);
|
|
|
|
|
m_libraryToPluginIndex.insert(pluginLibrary, index);
|
|
|
|
|
}
|
2010-11-10 15:07:53 +01:00
|
|
|
}
|
|
|
|
|
|
2011-09-02 13:25:08 +02:00
|
|
|
// watch library qmltypes file
|
|
|
|
|
if (!plugin.typeInfoPaths.isEmpty()) {
|
|
|
|
|
foreach (const QString &path, plugin.typeInfoPaths) {
|
|
|
|
|
if (!QFile::exists(path))
|
|
|
|
|
continue;
|
2011-08-17 11:59:15 +02:00
|
|
|
if (!pluginWatcher()->watchesFile(path))
|
|
|
|
|
pluginWatcher()->addFile(path, Utils::FileSystemWatcher::WatchModifiedDate);
|
|
|
|
|
m_libraryToPluginIndex.insert(path, index);
|
|
|
|
|
}
|
2010-11-26 14:24:59 +01:00
|
|
|
}
|
|
|
|
|
|
2010-11-10 15:07:53 +01:00
|
|
|
dump(plugin);
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 09:30:46 +01:00
|
|
|
void PluginDumper::dumpAllPlugins()
|
|
|
|
|
{
|
2011-06-28 12:01:56 +02:00
|
|
|
foreach (const Plugin &plugin, m_plugins) {
|
2010-11-24 09:30:46 +01:00
|
|
|
dump(plugin);
|
2011-06-28 12:01:56 +02:00
|
|
|
}
|
2010-11-24 09:30:46 +01:00
|
|
|
}
|
|
|
|
|
|
2011-09-21 15:54:07 +02:00
|
|
|
static QString noTypeinfoError(const QString &libraryPath)
|
2011-09-09 13:56:41 +02:00
|
|
|
{
|
2014-03-06 14:24:11 +01:00
|
|
|
return PluginDumper::tr("QML module does not contain information about components contained in plugins.\n\n"
|
2011-09-29 12:42:14 +02:00
|
|
|
"Module path: %1\n"
|
2011-09-21 15:54:07 +02:00
|
|
|
"See \"Using QML Modules with Plugins\" in the documentation.").arg(
|
|
|
|
|
libraryPath);
|
2011-09-09 13:56:41 +02:00
|
|
|
}
|
|
|
|
|
|
2010-11-10 15:07:53 +01:00
|
|
|
static QString qmldumpErrorMessage(const QString &libraryPath, const QString &error)
|
|
|
|
|
{
|
2011-09-21 15:54:07 +02:00
|
|
|
return noTypeinfoError(libraryPath) + QLatin1String("\n\n") +
|
2013-10-17 13:48:04 +02:00
|
|
|
PluginDumper::tr("Automatic type dump of QML module failed.\nErrors:\n%1").
|
|
|
|
|
arg(error) + QLatin1Char('\n');
|
2010-11-10 15:07:53 +01:00
|
|
|
}
|
|
|
|
|
|
2011-09-09 13:56:41 +02:00
|
|
|
static QString qmldumpFailedMessage(const QString &libraryPath, const QString &error)
|
2010-11-24 09:30:46 +01:00
|
|
|
{
|
2011-01-20 16:02:28 +01:00
|
|
|
QString firstLines =
|
2014-08-23 01:19:53 +02:00
|
|
|
QStringList(error.split(QLatin1Char('\n')).mid(0, 10)).join(QLatin1Char('\n'));
|
2011-09-21 15:54:07 +02:00
|
|
|
return noTypeinfoError(libraryPath) + QLatin1String("\n\n") +
|
|
|
|
|
PluginDumper::tr("Automatic type dump of QML module failed.\n"
|
2011-09-09 13:56:41 +02:00
|
|
|
"First 10 lines or errors:\n"
|
|
|
|
|
"\n"
|
2011-09-21 15:54:07 +02:00
|
|
|
"%1"
|
2011-09-09 13:56:41 +02:00
|
|
|
"\n"
|
|
|
|
|
"Check 'General Messages' output pane for details."
|
2011-09-21 15:54:07 +02:00
|
|
|
).arg(firstLines);
|
2010-11-24 09:30:46 +01:00
|
|
|
}
|
|
|
|
|
|
2011-05-30 11:10:06 +02:00
|
|
|
static void printParseWarnings(const QString &libraryPath, const QString &warning)
|
|
|
|
|
{
|
2014-01-23 14:28:31 +01:00
|
|
|
ModelManagerInterface::writeWarning(
|
2014-03-06 14:24:11 +01:00
|
|
|
PluginDumper::tr("Warnings while parsing QML type information of %1:\n"
|
2014-01-23 14:28:31 +01:00
|
|
|
"%2").arg(libraryPath, warning));
|
2011-05-30 11:10:06 +02:00
|
|
|
}
|
|
|
|
|
|
2013-03-08 15:44:58 +01:00
|
|
|
static QString qmlPluginDumpErrorMessage(QProcess *process)
|
|
|
|
|
{
|
|
|
|
|
QString errorMessage;
|
|
|
|
|
const QString binary = QDir::toNativeSeparators(process->program());
|
|
|
|
|
switch (process->error()) {
|
|
|
|
|
case QProcess::FailedToStart:
|
|
|
|
|
errorMessage = PluginDumper::tr("\"%1\" failed to start: %2").arg(binary, process->errorString());
|
|
|
|
|
break;
|
|
|
|
|
case QProcess::Crashed:
|
|
|
|
|
errorMessage = PluginDumper::tr("\"%1\" crashed.").arg(binary);
|
|
|
|
|
break;
|
|
|
|
|
case QProcess::Timedout:
|
|
|
|
|
errorMessage = PluginDumper::tr("\"%1\" timed out.").arg(binary);
|
|
|
|
|
break;
|
|
|
|
|
case QProcess::ReadError:
|
|
|
|
|
case QProcess::WriteError:
|
|
|
|
|
errorMessage = PluginDumper::tr("I/O error running \"%1\".").arg(binary);
|
|
|
|
|
break;
|
|
|
|
|
case QProcess::UnknownError:
|
|
|
|
|
if (process->exitCode())
|
|
|
|
|
errorMessage = PluginDumper::tr("\"%1\" returned exit code %2.").arg(binary).arg(process->exitCode());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
errorMessage += QLatin1Char('\n') + PluginDumper::tr("Arguments: %1").arg(process->arguments().join(QLatin1Char(' ')));
|
|
|
|
|
if (process->error() != QProcess::FailedToStart) {
|
|
|
|
|
const QString stdErr = QString::fromLocal8Bit(process->readAllStandardError());
|
|
|
|
|
if (!stdErr.isEmpty()) {
|
|
|
|
|
errorMessage += QLatin1Char('\n');
|
|
|
|
|
errorMessage += stdErr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return errorMessage;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-10 15:07:53 +01:00
|
|
|
void PluginDumper::qmlPluginTypeDumpDone(int exitCode)
|
|
|
|
|
{
|
|
|
|
|
QProcess *process = qobject_cast<QProcess *>(sender());
|
|
|
|
|
if (!process)
|
|
|
|
|
return;
|
|
|
|
|
process->deleteLater();
|
|
|
|
|
|
|
|
|
|
const QString libraryPath = m_runningQmldumps.take(process);
|
2011-06-28 12:01:56 +02:00
|
|
|
if (libraryPath.isEmpty())
|
|
|
|
|
return;
|
2010-11-10 15:07:53 +01:00
|
|
|
const Snapshot snapshot = m_modelManager->snapshot();
|
|
|
|
|
LibraryInfo libraryInfo = snapshot.libraryInfo(libraryPath);
|
2014-11-24 19:51:58 +01:00
|
|
|
bool privatePlugin = libraryPath.endsWith(QLatin1String("private"));
|
2010-11-10 15:07:53 +01:00
|
|
|
|
|
|
|
|
if (exitCode != 0) {
|
2013-03-08 15:44:58 +01:00
|
|
|
const QString errorMessages = qmlPluginDumpErrorMessage(process);
|
2014-11-24 19:51:58 +01:00
|
|
|
if (!privatePlugin)
|
|
|
|
|
ModelManagerInterface::writeWarning(qmldumpErrorMessage(libraryPath, errorMessages));
|
2011-09-09 13:56:41 +02:00
|
|
|
libraryInfo.setPluginTypeInfoStatus(LibraryInfo::DumpError, qmldumpFailedMessage(libraryPath, errorMessages));
|
2010-11-10 15:07:53 +01:00
|
|
|
|
2020-04-17 11:40:42 +02:00
|
|
|
const QByteArray output = process->readAllStandardOutput();
|
|
|
|
|
|
|
|
|
|
class CppQmlTypesInfo {
|
|
|
|
|
public:
|
|
|
|
|
QString error;
|
|
|
|
|
QString warning;
|
|
|
|
|
CppQmlTypesLoader::BuiltinObjects objectsList;
|
|
|
|
|
QList<ModuleApiInfo> moduleApis;
|
|
|
|
|
QStringList dependencies;
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-24 16:08:25 +02:00
|
|
|
auto future = Utils::runAsync([output, libraryPath](QFutureInterface<CppQmlTypesInfo>& future)
|
|
|
|
|
{
|
|
|
|
|
CppQmlTypesInfo infos;
|
|
|
|
|
CppQmlTypesLoader::parseQmlTypeDescriptions(output, &infos.objectsList, &infos.moduleApis, &infos.dependencies,
|
|
|
|
|
&infos.error, &infos.warning,
|
|
|
|
|
QLatin1String("<dump of ") + libraryPath + QLatin1Char('>'));
|
|
|
|
|
future.reportFinished(&infos);
|
|
|
|
|
});
|
Refactor tst_joinAllThreads, to be used in ModelManager d'tor
The idea in this approach is that we only collect those futures,
which have resulted from runAsync. The assumption is that
all tasks associated with those futures may sooner or
later finish, without the need to call qApp->processEvents().
OTOH, we don't collect fake futures coming from Utils::onFinished,
as these requires the spinning event loop in order to deliver
the onFinished signal.
So, the new joinAllThreads() method waits for all collected
futures to finish. We also _do_ want canceled and not finished
futures to finish, since even when they are canceled,
they may still be running and using the internals
of possibly destructed ModelManager. This means, we are only
waiting for other threads to be finished, without reporting
their results to e.g. onFinished() handlers.
Some tests require that all onFinished handlers are also processed.
In order to achieve this, we create a loop inside
tst_joinAllThreads() method and we call joinAllThreads(), so
it will wait for all pending queue to finish, and then we call process
events, in order to let finished futures propagate their results
to their respective onFinished() handlers.
Some handlers may have stared another threads when being processed,
so we may expect that some new futures will appear.
So, after processing the events we check if any new events
appeared, and in this case we repeat the loop.
Otherwise, we finish synchronization.
Amends: 96c860159b862460e21be16a6e2839c0b591e016
Task-number: QTCREATORBUG-25350
Change-Id: I5e44150c55f6be00445a5695938482d948990c94
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
2021-03-05 13:54:50 +01:00
|
|
|
m_modelManager->addFuture(future);
|
2020-04-17 11:40:42 +02:00
|
|
|
|
Refactor tst_joinAllThreads, to be used in ModelManager d'tor
The idea in this approach is that we only collect those futures,
which have resulted from runAsync. The assumption is that
all tasks associated with those futures may sooner or
later finish, without the need to call qApp->processEvents().
OTOH, we don't collect fake futures coming from Utils::onFinished,
as these requires the spinning event loop in order to deliver
the onFinished signal.
So, the new joinAllThreads() method waits for all collected
futures to finish. We also _do_ want canceled and not finished
futures to finish, since even when they are canceled,
they may still be running and using the internals
of possibly destructed ModelManager. This means, we are only
waiting for other threads to be finished, without reporting
their results to e.g. onFinished() handlers.
Some tests require that all onFinished handlers are also processed.
In order to achieve this, we create a loop inside
tst_joinAllThreads() method and we call joinAllThreads(), so
it will wait for all pending queue to finish, and then we call process
events, in order to let finished futures propagate their results
to their respective onFinished() handlers.
Some handlers may have stared another threads when being processed,
so we may expect that some new futures will appear.
So, after processing the events we check if any new events
appeared, and in this case we repeat the loop.
Otherwise, we finish synchronization.
Amends: 96c860159b862460e21be16a6e2839c0b591e016
Task-number: QTCREATORBUG-25350
Change-Id: I5e44150c55f6be00445a5695938482d948990c94
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
2021-03-05 13:54:50 +01:00
|
|
|
Utils::onFinished(future, this, [this, libraryInfo, privatePlugin, libraryPath]
|
|
|
|
|
(const QFuture<CppQmlTypesInfo>& future) {
|
2020-04-24 16:08:25 +02:00
|
|
|
CppQmlTypesInfo infos = future.result();
|
2020-04-17 11:40:42 +02:00
|
|
|
|
|
|
|
|
LibraryInfo libInfo = libraryInfo;
|
|
|
|
|
|
|
|
|
|
if (!infos.error.isEmpty()) {
|
|
|
|
|
libInfo.setPluginTypeInfoStatus(LibraryInfo::DumpError,
|
|
|
|
|
qmldumpErrorMessage(libraryPath, infos.error));
|
|
|
|
|
if (!privatePlugin)
|
|
|
|
|
printParseWarnings(libraryPath, libInfo.pluginTypeInfoError());
|
|
|
|
|
} else {
|
|
|
|
|
libInfo.setMetaObjects(infos.objectsList.values());
|
|
|
|
|
libInfo.setModuleApis(infos.moduleApis);
|
|
|
|
|
libInfo.setPluginTypeInfoStatus(LibraryInfo::DumpDone);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!infos.warning.isEmpty())
|
|
|
|
|
printParseWarnings(libraryPath, infos.warning);
|
|
|
|
|
|
|
|
|
|
libInfo.updateFingerprint();
|
|
|
|
|
|
|
|
|
|
m_modelManager->updateLibraryInfo(libraryPath, libInfo);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
libraryInfo.setPluginTypeInfoStatus(LibraryInfo::DumpDone);
|
|
|
|
|
libraryInfo.updateFingerprint();
|
|
|
|
|
m_modelManager->updateLibraryInfo(libraryPath, libraryInfo);
|
2010-11-10 15:07:53 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PluginDumper::qmlPluginTypeDumpError(QProcess::ProcessError)
|
|
|
|
|
{
|
|
|
|
|
QProcess *process = qobject_cast<QProcess *>(sender());
|
|
|
|
|
if (!process)
|
|
|
|
|
return;
|
|
|
|
|
process->deleteLater();
|
|
|
|
|
|
|
|
|
|
const QString libraryPath = m_runningQmldumps.take(process);
|
2011-06-28 12:01:56 +02:00
|
|
|
if (libraryPath.isEmpty())
|
|
|
|
|
return;
|
2013-03-08 15:44:58 +01:00
|
|
|
const QString errorMessages = qmlPluginDumpErrorMessage(process);
|
2014-11-24 19:51:58 +01:00
|
|
|
const Snapshot snapshot = m_modelManager->snapshot();
|
|
|
|
|
LibraryInfo libraryInfo = snapshot.libraryInfo(libraryPath);
|
|
|
|
|
if (!libraryPath.endsWith(QLatin1String("private"), Qt::CaseInsensitive))
|
|
|
|
|
ModelManagerInterface::writeWarning(qmldumpErrorMessage(libraryPath, errorMessages));
|
|
|
|
|
libraryInfo.setPluginTypeInfoStatus(LibraryInfo::DumpError, qmldumpFailedMessage(libraryPath, errorMessages));
|
|
|
|
|
libraryInfo.updateFingerprint();
|
|
|
|
|
m_modelManager->updateLibraryInfo(libraryPath, libraryInfo);
|
2010-11-10 15:07:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PluginDumper::pluginChanged(const QString &pluginLibrary)
|
|
|
|
|
{
|
|
|
|
|
const int pluginIndex = m_libraryToPluginIndex.value(pluginLibrary, -1);
|
|
|
|
|
if (pluginIndex == -1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const Plugin &plugin = m_plugins.at(pluginIndex);
|
|
|
|
|
dump(plugin);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-17 11:40:42 +02:00
|
|
|
QFuture<PluginDumper::QmlTypeDescription> PluginDumper::loadQmlTypeDescription(const QStringList &paths) const {
|
|
|
|
|
auto future = Utils::runAsync([=](QFutureInterface<PluginDumper::QmlTypeDescription> &future)
|
|
|
|
|
{
|
|
|
|
|
PluginDumper::QmlTypeDescription result;
|
|
|
|
|
|
|
|
|
|
for (const QString &p: paths) {
|
|
|
|
|
Utils::FileReader reader;
|
2021-05-18 09:47:07 +02:00
|
|
|
if (!reader.fetch(Utils::FilePath::fromString(p), QFile::Text)) {
|
2020-04-17 11:40:42 +02:00
|
|
|
result.errors += reader.errorString();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
QString error;
|
|
|
|
|
QString warning;
|
|
|
|
|
CppQmlTypesLoader::BuiltinObjects objs;
|
|
|
|
|
QList<ModuleApiInfo> apis;
|
|
|
|
|
QStringList deps;
|
|
|
|
|
CppQmlTypesLoader::parseQmlTypeDescriptions(reader.data(), &objs, &apis, &deps,
|
|
|
|
|
&error, &warning, p);
|
|
|
|
|
if (!error.isEmpty()) {
|
|
|
|
|
result.errors += tr("Failed to parse \"%1\".\nError: %2").arg(p, error);
|
|
|
|
|
} else {
|
|
|
|
|
result.objects += objs.values();
|
|
|
|
|
result.moduleApis += apis;
|
|
|
|
|
if (!deps.isEmpty())
|
|
|
|
|
result.dependencies += deps;
|
|
|
|
|
}
|
|
|
|
|
if (!warning.isEmpty())
|
|
|
|
|
result.warnings += warning;
|
2011-10-12 08:36:02 +02:00
|
|
|
}
|
2020-04-17 11:40:42 +02:00
|
|
|
|
|
|
|
|
future.reportFinished(&result);
|
|
|
|
|
});
|
Refactor tst_joinAllThreads, to be used in ModelManager d'tor
The idea in this approach is that we only collect those futures,
which have resulted from runAsync. The assumption is that
all tasks associated with those futures may sooner or
later finish, without the need to call qApp->processEvents().
OTOH, we don't collect fake futures coming from Utils::onFinished,
as these requires the spinning event loop in order to deliver
the onFinished signal.
So, the new joinAllThreads() method waits for all collected
futures to finish. We also _do_ want canceled and not finished
futures to finish, since even when they are canceled,
they may still be running and using the internals
of possibly destructed ModelManager. This means, we are only
waiting for other threads to be finished, without reporting
their results to e.g. onFinished() handlers.
Some tests require that all onFinished handlers are also processed.
In order to achieve this, we create a loop inside
tst_joinAllThreads() method and we call joinAllThreads(), so
it will wait for all pending queue to finish, and then we call process
events, in order to let finished futures propagate their results
to their respective onFinished() handlers.
Some handlers may have stared another threads when being processed,
so we may expect that some new futures will appear.
So, after processing the events we check if any new events
appeared, and in this case we repeat the loop.
Otherwise, we finish synchronization.
Amends: 96c860159b862460e21be16a6e2839c0b591e016
Task-number: QTCREATORBUG-25350
Change-Id: I5e44150c55f6be00445a5695938482d948990c94
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
2021-03-05 13:54:50 +01:00
|
|
|
m_modelManager->addFuture(future);
|
2020-04-17 11:40:42 +02:00
|
|
|
|
|
|
|
|
return future;
|
2016-02-26 17:28:30 +01:00
|
|
|
}
|
2020-04-17 11:40:42 +02:00
|
|
|
|
2016-02-26 17:28:30 +01:00
|
|
|
/*!
|
|
|
|
|
* \brief Build the path of an existing qmltypes file from a module name.
|
|
|
|
|
* \param name
|
2017-09-28 16:24:13 +02:00
|
|
|
* \return the module's qmltypes file path or an empty string if not found
|
2016-02-26 17:28:30 +01:00
|
|
|
*
|
|
|
|
|
* Look for \a name qmltypes file in model manager's import paths.
|
|
|
|
|
*
|
2017-09-28 16:24:13 +02:00
|
|
|
* \sa QmlJs::modulePath
|
2016-02-26 17:28:30 +01:00
|
|
|
* \sa LinkPrivate::importNonFile
|
|
|
|
|
*/
|
|
|
|
|
QString PluginDumper::buildQmltypesPath(const QString &name) const
|
|
|
|
|
{
|
2016-04-20 15:51:04 +02:00
|
|
|
QString qualifiedName;
|
2017-09-28 16:24:13 +02:00
|
|
|
QString version;
|
2016-04-20 15:51:04 +02:00
|
|
|
|
|
|
|
|
QRegularExpression import("^(?<name>[\\w|\\.]+)\\s+(?<major>\\d+)\\.(?<minor>\\d+)$");
|
|
|
|
|
QRegularExpressionMatch m = import.match(name);
|
|
|
|
|
if (m.hasMatch()) {
|
|
|
|
|
qualifiedName = m.captured("name");
|
2017-09-28 16:24:13 +02:00
|
|
|
version = m.captured("major") + QLatin1Char('.') + m.captured("minor");
|
2016-02-26 17:28:30 +01:00
|
|
|
}
|
|
|
|
|
|
2021-01-11 14:09:51 +01:00
|
|
|
const QStringList paths = modulePaths(qualifiedName, version, m_modelManager->importPathsNames());
|
2017-09-28 16:24:13 +02:00
|
|
|
|
2021-01-11 14:09:51 +01:00
|
|
|
if (paths.isEmpty())
|
2017-09-28 16:24:13 +02:00
|
|
|
return QString();
|
|
|
|
|
|
2021-01-11 14:09:51 +01:00
|
|
|
for (const QString &path : paths) {
|
|
|
|
|
QDirIterator it(path, QStringList { "*.qmltypes" }, QDir::Files);
|
2016-02-26 17:28:30 +01:00
|
|
|
|
2021-01-11 14:09:51 +01:00
|
|
|
if (it.hasNext())
|
|
|
|
|
return it.next();
|
|
|
|
|
}
|
2016-02-26 17:28:30 +01:00
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Recursively load dependencies.
|
|
|
|
|
* \param dependencies
|
|
|
|
|
* \param errors
|
|
|
|
|
* \param warnings
|
|
|
|
|
* \param objects
|
|
|
|
|
*
|
|
|
|
|
* Recursively load type descriptions of dependencies, collecting results
|
|
|
|
|
* in \a objects.
|
|
|
|
|
*/
|
2020-04-17 11:40:42 +02:00
|
|
|
QFuture<PluginDumper::DependencyInfo> PluginDumper::loadDependencies(const QStringList &dependencies,
|
|
|
|
|
QSharedPointer<QSet<QString>> visited) const
|
2016-02-26 17:28:30 +01:00
|
|
|
{
|
2020-04-17 11:40:42 +02:00
|
|
|
auto iface = QSharedPointer<QFutureInterface<PluginDumper::DependencyInfo>>(new QFutureInterface<PluginDumper::DependencyInfo>);
|
2016-07-13 16:38:36 +02:00
|
|
|
|
2020-04-17 11:40:42 +02:00
|
|
|
if (visited.isNull()) {
|
|
|
|
|
visited = QSharedPointer<QSet<QString>>(new QSet<QString>());
|
|
|
|
|
}
|
2016-07-13 16:38:36 +02:00
|
|
|
|
2016-02-26 17:28:30 +01:00
|
|
|
QStringList dependenciesPaths;
|
|
|
|
|
QString path;
|
|
|
|
|
for (const QString &name: dependencies) {
|
|
|
|
|
path = buildQmltypesPath(name);
|
|
|
|
|
if (!path.isNull())
|
|
|
|
|
dependenciesPaths << path;
|
2020-04-17 11:40:42 +02:00
|
|
|
visited->insert(name);
|
2016-02-26 17:28:30 +01:00
|
|
|
}
|
2020-04-17 11:40:42 +02:00
|
|
|
|
2020-04-24 16:08:25 +02:00
|
|
|
Utils::onFinished(loadQmlTypeDescription(dependenciesPaths), const_cast<PluginDumper*>(this), [=] (const QFuture<PluginDumper::QmlTypeDescription> &typesFuture) {
|
|
|
|
|
PluginDumper::QmlTypeDescription typesResult = typesFuture.result();
|
|
|
|
|
QStringList newDependencies = typesResult.dependencies;
|
2020-04-17 11:40:42 +02:00
|
|
|
newDependencies = Utils::toList(Utils::toSet(newDependencies) - *visited.data());
|
|
|
|
|
if (!newDependencies.isEmpty()) {
|
2020-04-24 16:08:25 +02:00
|
|
|
Utils::onFinished(loadDependencies(newDependencies, visited),
|
|
|
|
|
const_cast<PluginDumper*>(this), [typesResult, iface] (const QFuture<PluginDumper::DependencyInfo> &future) {
|
|
|
|
|
PluginDumper::DependencyInfo result = future.result();
|
2020-04-17 11:40:42 +02:00
|
|
|
|
2020-04-24 16:08:25 +02:00
|
|
|
result.errors += typesResult.errors;
|
|
|
|
|
result.objects += typesResult.objects;
|
|
|
|
|
result.warnings+= typesResult.warnings;
|
2020-04-17 11:40:42 +02:00
|
|
|
|
|
|
|
|
iface->reportFinished(&result);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
PluginDumper::DependencyInfo result;
|
2020-04-24 16:08:25 +02:00
|
|
|
result.errors += typesResult.errors;
|
|
|
|
|
result.objects += typesResult.objects;
|
|
|
|
|
result.warnings+= typesResult.warnings;
|
2020-04-17 11:40:42 +02:00
|
|
|
iface->reportFinished(&result);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return iface->future();
|
2016-02-26 17:28:30 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-10 16:06:57 +02:00
|
|
|
// Fills \a highestVersion with the largest export version for \a package
|
|
|
|
|
// and sets \a hasExportName to true if a type called \a exportName is found.
|
|
|
|
|
static void getHighestExportVersion(
|
|
|
|
|
const QList<LanguageUtils::FakeMetaObject::ConstPtr> &objects,
|
|
|
|
|
const QString &package,
|
|
|
|
|
const QString &exportName,
|
|
|
|
|
bool *hasExportName,
|
|
|
|
|
ComponentVersion *highestVersion)
|
|
|
|
|
{
|
|
|
|
|
*highestVersion = ComponentVersion();
|
|
|
|
|
*hasExportName = false;
|
|
|
|
|
for (const auto &object : objects) {
|
|
|
|
|
for (const auto &e : object->exports()) {
|
|
|
|
|
if (e.package == package) {
|
|
|
|
|
if (e.version > *highestVersion)
|
|
|
|
|
*highestVersion = e.version;
|
|
|
|
|
if (e.type == exportName)
|
|
|
|
|
*hasExportName = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*** Workaround for implicit dependencies in >= 5.15.0.
|
|
|
|
|
*
|
|
|
|
|
* When "QtQuick" is imported, "QtQml" is implicitly loaded as well.
|
|
|
|
|
* When "QtQml" is imported, "QtQml.Models" and "QtQml.WorkerScript" are implicitly loaded.
|
|
|
|
|
* Add these imports as if they were "import" commands in the qmldir file.
|
|
|
|
|
*
|
|
|
|
|
* Qt 6 is planned to have these included in the qmldir file.
|
|
|
|
|
*/
|
|
|
|
|
static void applyQt515MissingImportWorkaround(const QString &path, LibraryInfo &info)
|
|
|
|
|
{
|
|
|
|
|
if (!info.imports().isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const bool isQtQuick = path.endsWith(QStringLiteral("/QtQuick"))
|
|
|
|
|
|| path.endsWith(QStringLiteral("/QtQuick.2"));
|
|
|
|
|
const bool isQtQml = path.endsWith(QStringLiteral("/QtQml"))
|
|
|
|
|
|| path.endsWith(QStringLiteral("/QtQml.2"));
|
|
|
|
|
if (!isQtQuick && !isQtQml)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ComponentVersion highestVersion;
|
|
|
|
|
const auto package = isQtQuick ? QStringLiteral("QtQuick") : QStringLiteral("QtQml");
|
|
|
|
|
const auto missingTypeName = isQtQuick ? QStringLiteral("QtObject") : QStringLiteral("ListElement");
|
|
|
|
|
bool hasMissingType = false;
|
|
|
|
|
getHighestExportVersion(
|
|
|
|
|
info.metaObjects(),
|
|
|
|
|
package,
|
|
|
|
|
missingTypeName,
|
|
|
|
|
&hasMissingType,
|
|
|
|
|
&highestVersion);
|
|
|
|
|
|
|
|
|
|
// If the highest export version is < 2.15, we expect Qt <5.15
|
|
|
|
|
if (highestVersion.majorVersion() != 2 || highestVersion.minorVersion() < 15)
|
|
|
|
|
return;
|
|
|
|
|
// As an extra sanity check: if the type from the dependent module already exists,
|
|
|
|
|
// don't proceeed either.
|
|
|
|
|
if (hasMissingType)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (isQtQuick) {
|
2020-11-26 07:32:29 +01:00
|
|
|
info.setImports(QList<QmlDirParser::Import>(
|
2020-11-26 13:57:15 +01:00
|
|
|
{QmlDirParser::Import("QtQml", ComponentVersion(), {})}));
|
2020-05-10 16:06:57 +02:00
|
|
|
} else if (isQtQml) {
|
2020-11-26 07:32:29 +01:00
|
|
|
info.setImports(QList<QmlDirParser::Import>(
|
2020-11-26 13:57:15 +01:00
|
|
|
{ QmlDirParser::Import("QtQml.Models", ComponentVersion(), {}),
|
|
|
|
|
QmlDirParser::Import("QtQml.WorkerScript", ComponentVersion(), {}) }));
|
2020-05-10 16:06:57 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-24 16:08:25 +02:00
|
|
|
void PluginDumper::prepareLibraryInfo(LibraryInfo &libInfo,
|
|
|
|
|
const QString &libraryPath,
|
|
|
|
|
const QStringList &deps,
|
|
|
|
|
const QStringList &errors,
|
|
|
|
|
const QStringList &warnings,
|
|
|
|
|
const QList<ModuleApiInfo> &moduleApis,
|
|
|
|
|
QList<FakeMetaObject::ConstPtr> &objects)
|
2016-02-26 17:28:30 +01:00
|
|
|
{
|
2020-04-24 16:08:25 +02:00
|
|
|
QStringList errs = errors;
|
2020-04-17 11:40:42 +02:00
|
|
|
|
2020-04-24 16:08:25 +02:00
|
|
|
libInfo.setMetaObjects(objects);
|
|
|
|
|
libInfo.setModuleApis(moduleApis);
|
|
|
|
|
libInfo.setDependencies(deps);
|
2020-04-17 11:40:42 +02:00
|
|
|
|
2020-04-24 16:08:25 +02:00
|
|
|
if (errs.isEmpty()) {
|
|
|
|
|
libInfo.setPluginTypeInfoStatus(LibraryInfo::TypeInfoFileDone);
|
|
|
|
|
} else {
|
|
|
|
|
printParseWarnings(libraryPath, errors.join(QLatin1Char('\n')));
|
|
|
|
|
errs.prepend(tr("Errors while reading typeinfo files:"));
|
|
|
|
|
libInfo.setPluginTypeInfoStatus(LibraryInfo::TypeInfoFileError, errs.join(QLatin1Char('\n')));
|
|
|
|
|
}
|
2020-04-17 11:40:42 +02:00
|
|
|
|
2020-04-24 16:08:25 +02:00
|
|
|
if (!warnings.isEmpty())
|
|
|
|
|
printParseWarnings(libraryPath, warnings.join(QLatin1String("\n")));
|
2020-04-17 11:40:42 +02:00
|
|
|
|
2020-05-10 16:06:57 +02:00
|
|
|
applyQt515MissingImportWorkaround(libraryPath, libInfo);
|
|
|
|
|
|
2020-04-24 16:08:25 +02:00
|
|
|
libInfo.updateFingerprint();
|
|
|
|
|
}
|
2020-04-17 11:40:42 +02:00
|
|
|
|
2020-04-24 16:08:25 +02:00
|
|
|
void PluginDumper::loadQmltypesFile(const QStringList &qmltypesFilePaths,
|
|
|
|
|
const QString &libraryPath,
|
|
|
|
|
QmlJS::LibraryInfo libraryInfo)
|
|
|
|
|
{
|
Refactor tst_joinAllThreads, to be used in ModelManager d'tor
The idea in this approach is that we only collect those futures,
which have resulted from runAsync. The assumption is that
all tasks associated with those futures may sooner or
later finish, without the need to call qApp->processEvents().
OTOH, we don't collect fake futures coming from Utils::onFinished,
as these requires the spinning event loop in order to deliver
the onFinished signal.
So, the new joinAllThreads() method waits for all collected
futures to finish. We also _do_ want canceled and not finished
futures to finish, since even when they are canceled,
they may still be running and using the internals
of possibly destructed ModelManager. This means, we are only
waiting for other threads to be finished, without reporting
their results to e.g. onFinished() handlers.
Some tests require that all onFinished handlers are also processed.
In order to achieve this, we create a loop inside
tst_joinAllThreads() method and we call joinAllThreads(), so
it will wait for all pending queue to finish, and then we call process
events, in order to let finished futures propagate their results
to their respective onFinished() handlers.
Some handlers may have stared another threads when being processed,
so we may expect that some new futures will appear.
So, after processing the events we check if any new events
appeared, and in this case we repeat the loop.
Otherwise, we finish synchronization.
Amends: 96c860159b862460e21be16a6e2839c0b591e016
Task-number: QTCREATORBUG-25350
Change-Id: I5e44150c55f6be00445a5695938482d948990c94
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
2021-03-05 13:54:50 +01:00
|
|
|
Utils::onFinished(loadQmlTypeDescription(qmltypesFilePaths), this, [=](const QFuture<PluginDumper::QmlTypeDescription> &typesFuture)
|
2020-04-24 16:08:25 +02:00
|
|
|
{
|
|
|
|
|
PluginDumper::QmlTypeDescription typesResult = typesFuture.result();
|
|
|
|
|
if (!typesResult.dependencies.isEmpty())
|
|
|
|
|
{
|
Refactor tst_joinAllThreads, to be used in ModelManager d'tor
The idea in this approach is that we only collect those futures,
which have resulted from runAsync. The assumption is that
all tasks associated with those futures may sooner or
later finish, without the need to call qApp->processEvents().
OTOH, we don't collect fake futures coming from Utils::onFinished,
as these requires the spinning event loop in order to deliver
the onFinished signal.
So, the new joinAllThreads() method waits for all collected
futures to finish. We also _do_ want canceled and not finished
futures to finish, since even when they are canceled,
they may still be running and using the internals
of possibly destructed ModelManager. This means, we are only
waiting for other threads to be finished, without reporting
their results to e.g. onFinished() handlers.
Some tests require that all onFinished handlers are also processed.
In order to achieve this, we create a loop inside
tst_joinAllThreads() method and we call joinAllThreads(), so
it will wait for all pending queue to finish, and then we call process
events, in order to let finished futures propagate their results
to their respective onFinished() handlers.
Some handlers may have stared another threads when being processed,
so we may expect that some new futures will appear.
So, after processing the events we check if any new events
appeared, and in this case we repeat the loop.
Otherwise, we finish synchronization.
Amends: 96c860159b862460e21be16a6e2839c0b591e016
Task-number: QTCREATORBUG-25350
Change-Id: I5e44150c55f6be00445a5695938482d948990c94
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
2021-03-05 13:54:50 +01:00
|
|
|
Utils::onFinished(loadDependencies(typesResult.dependencies, QSharedPointer<QSet<QString>>()), this,
|
2020-04-24 16:08:25 +02:00
|
|
|
[typesResult, libraryInfo, libraryPath, this] (const QFuture<PluginDumper::DependencyInfo> &loadFuture)
|
|
|
|
|
{
|
|
|
|
|
PluginDumper::DependencyInfo loadResult = loadFuture.result();
|
|
|
|
|
QStringList errors = typesResult.errors;
|
|
|
|
|
QStringList warnings = typesResult.errors;
|
|
|
|
|
QList<FakeMetaObject::ConstPtr> objects = typesResult.objects;
|
|
|
|
|
|
|
|
|
|
errors += loadResult.errors;
|
|
|
|
|
warnings += loadResult.warnings;
|
|
|
|
|
objects += loadResult.objects;
|
|
|
|
|
|
|
|
|
|
QmlJS::LibraryInfo libInfo = libraryInfo;
|
|
|
|
|
prepareLibraryInfo(libInfo, libraryPath, typesResult.dependencies,
|
|
|
|
|
errors, warnings,
|
|
|
|
|
typesResult.moduleApis, objects);
|
|
|
|
|
m_modelManager->updateLibraryInfo(libraryPath, libInfo);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
QmlJS::LibraryInfo libInfo = libraryInfo;
|
|
|
|
|
prepareLibraryInfo(libInfo, libraryPath, typesResult.dependencies,
|
|
|
|
|
typesResult.errors, typesResult.warnings,
|
|
|
|
|
typesResult.moduleApis, typesResult.objects);
|
2020-05-09 12:46:05 +02:00
|
|
|
m_modelManager->updateLibraryInfo(libraryPath, libInfo);
|
2020-04-17 11:40:42 +02:00
|
|
|
}
|
|
|
|
|
});
|
2011-06-28 12:01:56 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-20 12:38:56 +01:00
|
|
|
void PluginDumper::runQmlDump(const QmlJS::ModelManagerInterface::ProjectInfo &info,
|
|
|
|
|
const QStringList &arguments, const QString &importPath)
|
|
|
|
|
{
|
2016-09-21 09:00:05 +02:00
|
|
|
QDir wd = QDir(importPath);
|
|
|
|
|
wd.cdUp();
|
2016-01-20 12:38:56 +01:00
|
|
|
QProcess *process = new QProcess(this);
|
|
|
|
|
process->setEnvironment(info.qmlDumpEnvironment.toStringList());
|
2016-09-21 09:00:05 +02:00
|
|
|
QString workingDir = wd.canonicalPath();
|
|
|
|
|
process->setWorkingDirectory(workingDir);
|
2019-02-11 10:17:53 +01:00
|
|
|
connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
2016-06-27 22:25:11 +03:00
|
|
|
this, &PluginDumper::qmlPluginTypeDumpDone);
|
2016-08-03 19:43:54 +03:00
|
|
|
connect(process, &QProcess::errorOccurred, this, &PluginDumper::qmlPluginTypeDumpError);
|
2016-01-20 12:38:56 +01:00
|
|
|
process->start(info.qmlDumpPath, arguments);
|
|
|
|
|
m_runningQmldumps.insert(process, importPath);
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-10 15:07:53 +01:00
|
|
|
void PluginDumper::dump(const Plugin &plugin)
|
|
|
|
|
{
|
2014-11-19 15:23:32 +01:00
|
|
|
ModelManagerInterface::ProjectInfo info = m_modelManager->defaultProjectInfo();
|
|
|
|
|
const Snapshot snapshot = m_modelManager->snapshot();
|
|
|
|
|
LibraryInfo libraryInfo = snapshot.libraryInfo(plugin.qmldirPath);
|
|
|
|
|
|
2011-09-02 13:25:08 +02:00
|
|
|
// if there are type infos, don't dump!
|
|
|
|
|
if (!plugin.typeInfoPaths.isEmpty()) {
|
2010-11-26 14:24:59 +01:00
|
|
|
if (!libraryInfo.isValid())
|
|
|
|
|
return;
|
|
|
|
|
|
2011-09-02 13:25:08 +02:00
|
|
|
loadQmltypesFile(plugin.typeInfoPaths, plugin.qmldirPath, libraryInfo);
|
2010-11-26 14:24:59 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-24 19:50:31 +01:00
|
|
|
if (plugin.importUri.isEmpty())
|
|
|
|
|
return; // initial scan without uri, ignore
|
|
|
|
|
|
2011-09-21 15:54:07 +02:00
|
|
|
if (!info.tryQmlDump || info.qmlDumpPath.isEmpty()) {
|
2010-11-24 09:30:46 +01:00
|
|
|
if (!libraryInfo.isValid())
|
|
|
|
|
return;
|
|
|
|
|
|
2011-09-21 15:54:07 +02:00
|
|
|
QString errorMessage;
|
|
|
|
|
if (!info.tryQmlDump) {
|
|
|
|
|
errorMessage = noTypeinfoError(plugin.qmldirPath);
|
|
|
|
|
} else {
|
|
|
|
|
errorMessage = qmldumpErrorMessage(plugin.qmldirPath,
|
2011-09-09 13:56:41 +02:00
|
|
|
tr("Could not locate the helper application for dumping type information from C++ plugins.\n"
|
2011-09-26 16:48:54 +02:00
|
|
|
"Please build the qmldump application on the Qt version options page."));
|
2011-09-21 15:54:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
libraryInfo.setPluginTypeInfoStatus(LibraryInfo::DumpError, errorMessage);
|
2013-11-13 16:31:04 +01:00
|
|
|
libraryInfo.updateFingerprint();
|
2010-11-24 09:30:46 +01:00
|
|
|
m_modelManager->updateLibraryInfo(plugin.qmldirPath, libraryInfo);
|
2010-11-10 15:07:53 +01:00
|
|
|
return;
|
2010-11-24 09:30:46 +01:00
|
|
|
}
|
2010-11-10 15:07:53 +01:00
|
|
|
|
|
|
|
|
QStringList args;
|
2014-07-31 15:11:58 +02:00
|
|
|
if (info.qmlDumpHasRelocatableFlag)
|
2014-11-24 17:07:24 +01:00
|
|
|
args << QLatin1String("-nonrelocatable");
|
2014-07-31 15:11:58 +02:00
|
|
|
args << plugin.importUri;
|
|
|
|
|
args << plugin.importVersion;
|
2016-09-21 09:00:05 +02:00
|
|
|
args << (plugin.importPath.isEmpty() ? QLatin1String(".") : plugin.importPath);
|
2016-01-20 12:38:56 +01:00
|
|
|
runQmlDump(info, args, plugin.qmldirPath);
|
2010-11-10 15:07:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Returns the result of the merge of \a baseName with \a path, \a suffixes, and \a prefix.
|
|
|
|
|
The \a prefix must contain the dot.
|
|
|
|
|
|
|
|
|
|
\a qmldirPath is the location of the qmldir file.
|
|
|
|
|
|
|
|
|
|
Adapted from QDeclarativeImportDatabase::resolvePlugin.
|
|
|
|
|
*/
|
|
|
|
|
QString PluginDumper::resolvePlugin(const QDir &qmldirPath, const QString &qmldirPluginPath,
|
|
|
|
|
const QString &baseName, const QStringList &suffixes,
|
|
|
|
|
const QString &prefix)
|
|
|
|
|
{
|
|
|
|
|
QStringList searchPaths;
|
|
|
|
|
searchPaths.append(QLatin1String("."));
|
|
|
|
|
|
|
|
|
|
bool qmldirPluginPathIsRelative = QDir::isRelativePath(qmldirPluginPath);
|
|
|
|
|
if (!qmldirPluginPathIsRelative)
|
|
|
|
|
searchPaths.prepend(qmldirPluginPath);
|
|
|
|
|
|
|
|
|
|
foreach (const QString &pluginPath, searchPaths) {
|
|
|
|
|
|
|
|
|
|
QString resolvedPath;
|
|
|
|
|
|
|
|
|
|
if (pluginPath == QLatin1String(".")) {
|
|
|
|
|
if (qmldirPluginPathIsRelative)
|
|
|
|
|
resolvedPath = qmldirPath.absoluteFilePath(qmldirPluginPath);
|
|
|
|
|
else
|
|
|
|
|
resolvedPath = qmldirPath.absolutePath();
|
|
|
|
|
} else {
|
|
|
|
|
resolvedPath = pluginPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QDir dir(resolvedPath);
|
|
|
|
|
foreach (const QString &suffix, suffixes) {
|
|
|
|
|
QString pluginFileName = prefix;
|
|
|
|
|
|
|
|
|
|
pluginFileName += baseName;
|
|
|
|
|
pluginFileName += suffix;
|
|
|
|
|
|
|
|
|
|
QFileInfo fileInfo(dir, pluginFileName);
|
|
|
|
|
|
|
|
|
|
if (fileInfo.exists())
|
|
|
|
|
return fileInfo.absoluteFilePath();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Returns the result of the merge of \a baseName with \a dir and the platform suffix.
|
|
|
|
|
|
|
|
|
|
Adapted from QDeclarativeImportDatabase::resolvePlugin.
|
|
|
|
|
|
|
|
|
|
\table
|
2013-02-06 08:50:23 +01:00
|
|
|
\header \li Platform \li Valid suffixes
|
|
|
|
|
\row \li Windows \li \c .dll
|
|
|
|
|
\row \li Unix/Linux \li \c .so
|
|
|
|
|
\row \li AIX \li \c .a
|
|
|
|
|
\row \li HP-UX \li \c .sl, \c .so (HP-UXi)
|
|
|
|
|
\row \li Mac OS X \li \c .dylib, \c .bundle, \c .so
|
2010-11-10 15:07:53 +01:00
|
|
|
\endtable
|
|
|
|
|
|
|
|
|
|
Version number on unix are ignored.
|
|
|
|
|
*/
|
|
|
|
|
QString PluginDumper::resolvePlugin(const QDir &qmldirPath, const QString &qmldirPluginPath,
|
|
|
|
|
const QString &baseName)
|
|
|
|
|
{
|
|
|
|
|
QStringList validSuffixList;
|
2016-09-10 22:56:52 +03:00
|
|
|
QString prefix;
|
|
|
|
|
if (Utils::HostOsInfo::isWindowsHost()) {
|
|
|
|
|
// try a qmake-style debug build first
|
2017-02-22 15:09:35 +01:00
|
|
|
validSuffixList = QStringList({"d.dll", ".dll"});
|
2016-09-10 22:56:52 +03:00
|
|
|
} else if (Utils::HostOsInfo::isMacHost()) {
|
|
|
|
|
// try a qmake-style debug build first
|
2017-02-22 15:09:35 +01:00
|
|
|
validSuffixList = QStringList({"_debug.dylib", ".dylib", ".so", ".bundle", "lib"});
|
2016-09-10 22:56:52 +03:00
|
|
|
} else {
|
|
|
|
|
// Examples of valid library names:
|
|
|
|
|
// libfoo.so
|
|
|
|
|
prefix = "lib";
|
|
|
|
|
#if defined(Q_OS_HPUX)
|
2010-11-10 15:07:53 +01:00
|
|
|
/*
|
|
|
|
|
See "HP-UX Linker and Libraries User's Guide", section "Link-time Differences between PA-RISC and IPF":
|
|
|
|
|
"In PA-RISC (PA-32 and PA-64) shared libraries are suffixed with .sl. In IPF (32-bit and 64-bit),
|
|
|
|
|
the shared libraries are suffixed with .so. For compatibility, the IPF linker also supports the .sl suffix."
|
|
|
|
|
*/
|
2016-09-10 22:56:52 +03:00
|
|
|
validSuffixList << QLatin1String(".sl");
|
|
|
|
|
# if defined __ia64
|
|
|
|
|
validSuffixList << QLatin1String(".so");
|
|
|
|
|
# endif
|
|
|
|
|
#elif defined(Q_OS_AIX)
|
|
|
|
|
validSuffixList << QLatin1String(".a") << QLatin1String(".so");
|
|
|
|
|
#else
|
|
|
|
|
validSuffixList << QLatin1String(".so");
|
2010-11-10 15:07:53 +01:00
|
|
|
#endif
|
2016-09-10 22:56:52 +03:00
|
|
|
}
|
|
|
|
|
return resolvePlugin(qmldirPath, qmldirPluginPath, baseName, validSuffixList, prefix);
|
2010-11-10 15:07:53 +01:00
|
|
|
}
|