QmlJS: Proliferate FilePath and QtcProcess use in QmlJSPluginDumper

Change-Id: Ie483bb2e9b5d812d380470949564a6bc57801fa9
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-10-12 17:32:48 +02:00
parent d6c3a7297d
commit d68bb4687c
5 changed files with 54 additions and 57 deletions

View File

@@ -133,8 +133,8 @@ ModelManagerInterface::ModelManagerInterface(QObject *parent)
qRegisterMetaType<QmlJS::PathAndLanguage>("QmlJS::PathAndLanguage");
qRegisterMetaType<QmlJS::PathsAndLanguages>("QmlJS::PathsAndLanguages");
m_defaultProjectInfo.qtQmlPath = QFileInfo(
QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath)).canonicalFilePath();
m_defaultProjectInfo.qtQmlPath =
FilePath::fromUserInput(QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath));
m_defaultProjectInfo.qtVersionString = QLibraryInfo::version().toString();
updateImportPaths();
@@ -1217,16 +1217,14 @@ void ModelManagerInterface::updateImportPaths()
}
for (const ProjectInfo &pInfo : qAsConst(m_projects)) {
if (!pInfo.qtQmlPath.isEmpty()) {
allImportPaths.maybeInsert(Utils::FilePath::fromString(pInfo.qtQmlPath),
Dialect::QmlQtQuick2);
}
if (!pInfo.qtQmlPath.isEmpty())
allImportPaths.maybeInsert(pInfo.qtQmlPath, Dialect::QmlQtQuick2);
}
{
const QString pathAtt = defaultProjectInfo().qtQmlPath;
const FilePath pathAtt = defaultProjectInfo().qtQmlPath;
if (!pathAtt.isEmpty())
allImportPaths.maybeInsert(Utils::FilePath::fromString(pathAtt), Dialect::QmlQtQuick2);
allImportPaths.maybeInsert(pathAtt, Dialect::QmlQtQuick2);
}
for (const auto &importPath : defaultProjectInfo().importPaths) {
@@ -1435,7 +1433,7 @@ LibraryInfo ModelManagerInterface::builtins(const Document::Ptr &doc) const
{
const ProjectInfo info = projectInfoForPath(doc->fileName());
if (!info.qtQmlPath.isEmpty())
return m_validSnapshot.libraryInfo(info.qtQmlPath);
return m_validSnapshot.libraryInfo(info.qtQmlPath.toString());
return LibraryInfo();
}
@@ -1483,13 +1481,13 @@ ViewerContext ModelManagerInterface::getVContext(const ViewerContext &vCtx,
switch (res.language.dialect()) {
case Dialect::AnyLanguage:
case Dialect::Qml:
maybeAddPath(res, info.qtQmlPath);
maybeAddPath(res, info.qtQmlPath.toString());
Q_FALLTHROUGH();
case Dialect::QmlQtQuick2:
case Dialect::QmlQtQuick2Ui:
{
if (res.language == Dialect::QmlQtQuick2 || res.language == Dialect::QmlQtQuick2Ui)
maybeAddPath(res, info.qtQmlPath);
maybeAddPath(res, info.qtQmlPath.toString());
QList<Dialect> languages = res.language.companionLanguages();
auto addPathsOnLanguageMatch = [&](const PathsAndLanguages &importPaths) {
@@ -1534,7 +1532,7 @@ ViewerContext ModelManagerInterface::getVContext(const ViewerContext &vCtx,
for (const QString &path : qAsConst(defaultVCtx.paths))
maybeAddPath(res, path);
if (res.language == Dialect::AnyLanguage || res.language == Dialect::Qml)
maybeAddPath(res, info.qtQmlPath);
maybeAddPath(res, info.qtQmlPath.toString());
if (res.language == Dialect::AnyLanguage || res.language == Dialect::Qml
|| res.language == Dialect::QmlQtQuick2 || res.language == Dialect::QmlQtQuick2Ui) {
const auto environemntPaths = environmentImportPaths();

View File

@@ -78,10 +78,10 @@ public:
// whether trying to run qmldump makes sense
bool tryQmlDump = false;
bool qmlDumpHasRelocatableFlag = true;
QString qmlDumpPath;
::Utils::Environment qmlDumpEnvironment;
Utils::FilePath qmlDumpPath;
Utils::Environment qmlDumpEnvironment;
QString qtQmlPath;
Utils::FilePath qtQmlPath;
QString qtVersionString;
QmlJS::QmlLanguageBundles activeBundle;
QmlJS::QmlLanguageBundles extendedBundle;

View File

@@ -34,6 +34,7 @@
#include <utils/filesystemwatcher.h>
#include <utils/fileutils.h>
#include <utils/hostosinfo.h>
#include <utils/qtcprocess.h>
#include <utils/runextensions.h>
#include <QDir>
@@ -41,7 +42,9 @@
#include <QRegularExpression>
using namespace LanguageUtils;
using namespace QmlJS;
using namespace Utils;
namespace QmlJS {
PluginDumper::PluginDumper(ModelManagerInterface *modelManager)
: QObject(modelManager)
@@ -86,29 +89,30 @@ void PluginDumper::onLoadBuiltinTypes(const QmlJS::ModelManagerInterface::Projec
if (info.qmlDumpPath.isEmpty() || info.qtQmlPath.isEmpty())
return;
const QString importsPath = QDir::cleanPath(info.qtQmlPath);
// FIXME: This doesn't work for non-local paths.
const QString importsPath = QDir::cleanPath(info.qtQmlPath.toString());
if (m_runningQmldumps.values().contains(importsPath))
return;
LibraryInfo builtinInfo;
if (!force) {
const Snapshot snapshot = m_modelManager->snapshot();
builtinInfo = snapshot.libraryInfo(info.qtQmlPath);
builtinInfo = snapshot.libraryInfo(info.qtQmlPath.toString());
if (builtinInfo.isValid())
return;
}
builtinInfo = LibraryInfo(LibraryInfo::Found);
m_modelManager->updateLibraryInfo(info.qtQmlPath, builtinInfo);
m_modelManager->updateLibraryInfo(info.qtQmlPath.toString(), builtinInfo);
// prefer QTDIR/qml/builtins.qmltypes if available
const QString builtinQmltypesPath = info.qtQmlPath + QLatin1String("/builtins.qmltypes");
const QString builtinQmltypesPath = info.qtQmlPath.toString() + QLatin1String("/builtins.qmltypes");
if (QFile::exists(builtinQmltypesPath)) {
loadQmltypesFile(QStringList(builtinQmltypesPath), info.qtQmlPath, builtinInfo);
loadQmltypesFile(QStringList(builtinQmltypesPath), info.qtQmlPath.toString(), builtinInfo);
return;
}
runQmlDump(info, QStringList(QLatin1String("--builtins")), info.qtQmlPath);
m_qtToInfo.insert(info.qtQmlPath, info);
m_qtToInfo.insert(info.qtQmlPath.toString(), info);
}
static QString makeAbsolute(const QString &path, const QString &base)
@@ -227,10 +231,10 @@ static void printParseWarnings(const QString &libraryPath, const QString &warnin
"%2").arg(libraryPath, warning));
}
static QString qmlPluginDumpErrorMessage(QProcess *process)
static QString qmlPluginDumpErrorMessage(QtcProcess *process)
{
QString errorMessage;
const QString binary = QDir::toNativeSeparators(process->program());
const QString binary = process->commandLine().executable().toUserOutput();
switch (process->error()) {
case QProcess::FailedToStart:
errorMessage = PluginDumper::tr("\"%1\" failed to start: %2").arg(binary, process->errorString());
@@ -250,7 +254,7 @@ static QString qmlPluginDumpErrorMessage(QProcess *process)
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(' ')));
errorMessage += '\n' + PluginDumper::tr("Arguments: %1").arg(process->commandLine().arguments());
if (process->error() != QProcess::FailedToStart) {
const QString stdErr = QString::fromLocal8Bit(process->readAllStandardError());
if (!stdErr.isEmpty()) {
@@ -261,11 +265,8 @@ static QString qmlPluginDumpErrorMessage(QProcess *process)
return errorMessage;
}
void PluginDumper::qmlPluginTypeDumpDone(int exitCode)
void PluginDumper::qmlPluginTypeDumpDone(QtcProcess *process)
{
QProcess *process = qobject_cast<QProcess *>(sender());
if (!process)
return;
process->deleteLater();
const QString libraryPath = m_runningQmldumps.take(process);
@@ -275,7 +276,7 @@ void PluginDumper::qmlPluginTypeDumpDone(int exitCode)
LibraryInfo libraryInfo = snapshot.libraryInfo(libraryPath);
bool privatePlugin = libraryPath.endsWith(QLatin1String("private"));
if (exitCode != 0) {
if (process->exitCode() != 0) {
const QString errorMessages = qmlPluginDumpErrorMessage(process);
if (!privatePlugin)
ModelManagerInterface::writeWarning(qmldumpErrorMessage(libraryPath, errorMessages));
@@ -333,11 +334,8 @@ void PluginDumper::qmlPluginTypeDumpDone(int exitCode)
}
}
void PluginDumper::qmlPluginTypeDumpError(QProcess::ProcessError)
void PluginDumper::qmlPluginTypeDumpError(QtcProcess *process)
{
QProcess *process = qobject_cast<QProcess *>(sender());
if (!process)
return;
process->deleteLater();
const QString libraryPath = m_runningQmldumps.take(process);
@@ -632,20 +630,17 @@ void PluginDumper::loadQmltypesFile(const QStringList &qmltypesFilePaths,
});
}
void PluginDumper::runQmlDump(const QmlJS::ModelManagerInterface::ProjectInfo &info,
const QStringList &arguments, const QString &importPath)
void PluginDumper::runQmlDump(const ModelManagerInterface::ProjectInfo &info,
const QStringList &arguments, const FilePath &importPath)
{
QDir wd = QDir(importPath);
wd.cdUp();
QProcess *process = new QProcess(this);
process->setEnvironment(info.qmlDumpEnvironment.toStringList());
QString workingDir = wd.canonicalPath();
process->setWorkingDirectory(workingDir);
connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this, &PluginDumper::qmlPluginTypeDumpDone);
connect(process, &QProcess::errorOccurred, this, &PluginDumper::qmlPluginTypeDumpError);
process->start(info.qmlDumpPath, arguments);
m_runningQmldumps.insert(process, importPath);
auto process = new QtcProcess(this);
process->setEnvironment(info.qmlDumpEnvironment);
process->setWorkingDirectory(importPath);
process->setCommand({info.qmlDumpPath, arguments});
connect(process, &QtcProcess::finished, this, [this, process] { qmlPluginTypeDumpDone(process); });
connect(process, &QtcProcess::errorOccurred, this, [this, process] { qmlPluginTypeDumpError(process); });
process->start();
m_runningQmldumps.insert(process, importPath.toString());
}
void PluginDumper::dump(const Plugin &plugin)
@@ -691,7 +686,7 @@ void PluginDumper::dump(const Plugin &plugin)
args << plugin.importUri;
args << plugin.importVersion;
args << (plugin.importPath.isEmpty() ? QLatin1String(".") : plugin.importPath);
runQmlDump(info, args, plugin.qmldirPath);
runQmlDump(info, args, FilePath::fromString(plugin.qmldirPath));
}
/*!
@@ -792,3 +787,5 @@ QString PluginDumper::resolvePlugin(const QDir &qmldirPath, const QString &qmldi
}
return resolvePlugin(qmldirPath, qmldirPluginPath, baseName, validSuffixList, prefix);
}
} // QmlJS

View File

@@ -27,9 +27,10 @@
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <utils/qtcprocess.h>
#include <QObject>
#include <QHash>
#include <QProcess>
QT_BEGIN_NAMESPACE
class QDir;
@@ -57,8 +58,8 @@ private:
Q_INVOKABLE void onLoadPluginTypes(const QString &libraryPath, const QString &importPath,
const QString &importUri, const QString &importVersion);
Q_INVOKABLE void dumpAllPlugins();
void qmlPluginTypeDumpDone(int exitCode);
void qmlPluginTypeDumpError(QProcess::ProcessError error);
void qmlPluginTypeDumpDone(Utils::QtcProcess *process);
void qmlPluginTypeDumpError(Utils::QtcProcess *process);
void pluginChanged(const QString &pluginLibrary);
private:
@@ -87,7 +88,8 @@ private:
QList<LanguageUtils::FakeMetaObject::ConstPtr> objects;
};
void runQmlDump(const QmlJS::ModelManagerInterface::ProjectInfo &info, const QStringList &arguments, const QString &importPath);
void runQmlDump(const QmlJS::ModelManagerInterface::ProjectInfo &info, const QStringList &arguments,
const Utils::FilePath &importPath);
void dump(const Plugin &plugin);
QFuture<QmlTypeDescription> loadQmlTypeDescription(const QStringList &path) const;
QString buildQmltypesPath(const QString &name) const;
@@ -116,7 +118,7 @@ private:
ModelManagerInterface *m_modelManager;
Utils::FileSystemWatcher *m_pluginWatcher;
QHash<QProcess *, QString> m_runningQmldumps;
QHash<Utils::QtcProcess *, QString> m_runningQmldumps;
QList<Plugin> m_plugins;
QHash<QString, int> m_libraryToPluginIndex;
QHash<QString, QmlJS::ModelManagerInterface::ProjectInfo> m_qtToInfo;

View File

@@ -83,7 +83,7 @@ static void setupProjectInfoQmlBundles(ModelManagerInterface::ProjectInfo &proje
if (projectInfo.project)
activeTarget = projectInfo.project->activeTarget();
Kit *activeKit = activeTarget ? activeTarget->kit() : KitManager::defaultKit();
const QHash<QString, QString> replacements = {{QLatin1String("$(QT_INSTALL_QML)"), projectInfo.qtQmlPath}};
const QHash<QString, QString> replacements = {{QLatin1String("$(QT_INSTALL_QML)"), projectInfo.qtQmlPath.toString()}};
for (IBundleProvider *bp : IBundleProvider::allBundleProviders())
bp->mergeBundlesForKit(activeKit, projectInfo.activeBundle, replacements);
@@ -146,17 +146,17 @@ ModelManagerInterface::ProjectInfo ModelManager::defaultProjectInfoForProject(
}
if (qtVersion && qtVersion->isValid()) {
projectInfo.tryQmlDump = project && qtVersion->type() == QLatin1String(QtSupport::Constants::DESKTOPQT);
projectInfo.qtQmlPath = qtVersion->qmlPath().toFileInfo().canonicalFilePath();
projectInfo.qtQmlPath = qtVersion->qmlPath();
projectInfo.qtVersionString = qtVersion->qtVersionString();
} else if (!activeKit || !activeKit->value(QtSupport::SuppliesQtQuickImportPath::id(), false).toBool()) {
projectInfo.qtQmlPath = QFileInfo(QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath)).canonicalFilePath();
projectInfo.qtQmlPath = FilePath::fromUserInput(QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath));
projectInfo.qtVersionString = QLatin1String(qVersion());
}
projectInfo.qmlDumpPath.clear();
const QtSupport::BaseQtVersion *version = QtSupport::QtKitAspect::qtVersion(activeKit);
if (version && projectInfo.tryQmlDump) {
projectInfo.qmlDumpPath = version->qmlplugindumpFilePath().toString();
projectInfo.qmlDumpPath = version->qmlplugindumpFilePath();
projectInfo.qmlDumpHasRelocatableFlag = version->hasQmlDumpWithRelocatableFlag();
}