forked from qt-creator/qt-creator
qmljs: (QString -> Utils::FilePath)++
convert more QString containing paths to Utils::FilePath Change-Id: I1219d7d147993e48cfa641dc9bea72ab38c90f51 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
committed by
Tim Jenssen
parent
0bb272d411
commit
fd89043de2
@@ -32,6 +32,8 @@
|
||||
#include "qmljsmodelmanagerinterface.h"
|
||||
#include "qmljsconstants.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/filepath.h>
|
||||
#include <utils/porting.h>
|
||||
#include <utils/qrcparser.h>
|
||||
|
||||
@@ -93,14 +95,15 @@ public:
|
||||
const ImportInfo &importInfo);
|
||||
|
||||
bool importLibrary(const Document::Ptr &doc,
|
||||
const QString &libraryPath,
|
||||
Import *import, ObjectValue *targetObject,
|
||||
const QString &importPath = QString(),
|
||||
const Utils::FilePath &libraryPath,
|
||||
Import *import,
|
||||
ObjectValue *targetObject,
|
||||
const Utils::FilePath &importPath = Utils::FilePath(),
|
||||
bool optional = false);
|
||||
void loadQmldirComponents(ObjectValue *import,
|
||||
LanguageUtils::ComponentVersion version,
|
||||
const LibraryInfo &libraryInfo,
|
||||
const QString &libraryPath);
|
||||
const Utils::FilePath &libraryPath);
|
||||
void loadImplicitDirectoryImports(Imports *imports, const Document::Ptr &doc);
|
||||
void loadImplicitDefaultImports(Imports *imports);
|
||||
|
||||
@@ -113,8 +116,8 @@ private:
|
||||
|
||||
Snapshot m_snapshot;
|
||||
ValueOwner *m_valueOwner = nullptr;
|
||||
QStringList m_importPaths;
|
||||
QStringList m_applicationDirectories;
|
||||
QList<Utils::FilePath> m_importPaths;
|
||||
QList<Utils::FilePath> m_applicationDirectories;
|
||||
LibraryInfo m_builtins;
|
||||
ViewerContext m_vContext;
|
||||
|
||||
@@ -124,7 +127,7 @@ private:
|
||||
Document::Ptr document;
|
||||
|
||||
QList<DiagnosticMessage> *diagnosticMessages = nullptr;
|
||||
QHash<QString, QList<DiagnosticMessage>> *allDiagnosticMessages = nullptr;
|
||||
QHash<Utils::FilePath, QList<DiagnosticMessage>> *allDiagnosticMessages = nullptr;
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -182,7 +185,7 @@ Link::Link(const Snapshot &snapshot, const ViewerContext &vContext, const Librar
|
||||
fi.reportFinished();
|
||||
}
|
||||
|
||||
ContextPtr Link::operator()(QHash<QString, QList<DiagnosticMessage> > *messages)
|
||||
ContextPtr Link::operator()(QHash<Utils::FilePath, QList<DiagnosticMessage>> *messages)
|
||||
{
|
||||
d->allDiagnosticMessages = messages;
|
||||
return Context::create(d->m_snapshot, d->m_valueOwner, d->linkImports(), d->m_vContext);
|
||||
@@ -339,7 +342,8 @@ Import LinkPrivate::importFileOrDirectory(const Document::Ptr &doc, const Import
|
||||
import.object = nullptr;
|
||||
import.valid = true;
|
||||
|
||||
QString path = importInfo.path();
|
||||
QString pathStr = importInfo.path();
|
||||
Utils::FilePath path = Utils::FilePath::fromString(pathStr);
|
||||
|
||||
if (importInfo.type() == ImportType::Directory
|
||||
|| importInfo.type() == ImportType::ImplicitDirectory) {
|
||||
@@ -360,11 +364,15 @@ Import LinkPrivate::importFileOrDirectory(const Document::Ptr &doc, const Import
|
||||
} else if (importInfo.type() == ImportType::QrcFile) {
|
||||
QLocale locale;
|
||||
QStringList filePaths = ModelManagerInterface::instance()
|
||||
->filesAtQrcPath(path, &locale, nullptr, ModelManagerInterface::ActiveQrcResources);
|
||||
->filesAtQrcPath(pathStr,
|
||||
&locale,
|
||||
nullptr,
|
||||
ModelManagerInterface::ActiveQrcResources);
|
||||
if (filePaths.isEmpty())
|
||||
filePaths = ModelManagerInterface::instance()->filesAtQrcPath(path);
|
||||
filePaths = ModelManagerInterface::instance()->filesAtQrcPath(pathStr);
|
||||
if (!filePaths.isEmpty()) {
|
||||
if (Document::Ptr importedDoc = m_snapshot.document(filePaths.at(0)))
|
||||
if (Document::Ptr importedDoc = m_snapshot.document(
|
||||
Utils::FilePath::fromString(filePaths.at(0))))
|
||||
import.object = importedDoc->bind()->rootObjectValue();
|
||||
}
|
||||
} else if (importInfo.type() == ImportType::QrcDirectory){
|
||||
@@ -372,11 +380,13 @@ Import LinkPrivate::importFileOrDirectory(const Document::Ptr &doc, const Import
|
||||
|
||||
importLibrary(doc, path, &import, import.object);
|
||||
|
||||
const QMap<QString, QStringList> paths
|
||||
= ModelManagerInterface::instance()->filesInQrcPath(path);
|
||||
const QMap<QString, QStringList> paths = ModelManagerInterface::instance()->filesInQrcPath(
|
||||
pathStr);
|
||||
for (auto iter = paths.cbegin(), end = paths.cend(); iter != end; ++iter) {
|
||||
if (ModelManagerInterface::guessLanguageOfFile(iter.key()).isQmlLikeLanguage()) {
|
||||
Document::Ptr importedDoc = m_snapshot.document(iter.value().at(0));
|
||||
if (ModelManagerInterface::guessLanguageOfFile(Utils::FilePath::fromString(iter.key()))
|
||||
.isQmlLikeLanguage()) {
|
||||
Document::Ptr importedDoc = m_snapshot.document(
|
||||
Utils::FilePath::fromString(iter.value().at(0)));
|
||||
if (importedDoc && importedDoc->bind()->rootObjectValue()) {
|
||||
const QString targetName = QFileInfo(iter.key()).baseName();
|
||||
import.object->setMember(targetName, importedDoc->bind()->rootObjectValue());
|
||||
@@ -414,21 +424,24 @@ Import LinkPrivate::importNonFile(const Document::Ptr &doc, const ImportInfo &im
|
||||
const QString packageName = importInfo.name();
|
||||
const ComponentVersion version = importInfo.version();
|
||||
|
||||
QStringList libraryPaths = modulePaths(packageName, version.toString(), m_importPaths + m_applicationDirectories);
|
||||
QList<Utils::FilePath> libraryPaths = modulePaths(packageName,
|
||||
version.toString(),
|
||||
m_importPaths + m_applicationDirectories);
|
||||
|
||||
bool importFound = false;
|
||||
for (const QString &libPath : libraryPaths) {
|
||||
for (const Utils::FilePath &libPath : libraryPaths) {
|
||||
importFound = !libPath.isEmpty() && importLibrary(doc, libPath, &import, import.object);
|
||||
if (importFound)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!importFound) {
|
||||
for (const QString &dir : qAsConst(m_applicationDirectories)) {
|
||||
QDirIterator it(dir, QStringList { "*.qmltypes" }, QDir::Files);
|
||||
for (const Utils::FilePath &dir : qAsConst(m_applicationDirectories)) {
|
||||
auto qmltypes = dir.dirEntries(
|
||||
Utils::FileFilter(QStringList{"*.qmltypes"}, QDir::Files));
|
||||
|
||||
// This adds the types to the C++ types, to be found below if applicable.
|
||||
if (it.hasNext())
|
||||
if (!qmltypes.isEmpty())
|
||||
importLibrary(doc, dir, &import, import.object);
|
||||
}
|
||||
}
|
||||
@@ -455,8 +468,9 @@ Import LinkPrivate::importNonFile(const Document::Ptr &doc, const ImportInfo &im
|
||||
|
||||
if (!importFound && importInfo.ast()) {
|
||||
import.valid = false;
|
||||
error(doc, locationFromRange(importInfo.ast()->firstSourceLocation(),
|
||||
importInfo.ast()->lastSourceLocation()),
|
||||
error(doc,
|
||||
locationFromRange(importInfo.ast()->firstSourceLocation(),
|
||||
importInfo.ast()->lastSourceLocation()),
|
||||
Link::tr(
|
||||
"QML module not found (%1).\n\n"
|
||||
"Import paths:\n"
|
||||
@@ -467,19 +481,21 @@ Import LinkPrivate::importNonFile(const Document::Ptr &doc, const ImportInfo &im
|
||||
"For qmlproject projects, use the importPaths property to add import paths.\n"
|
||||
"For CMake projects, make sure QML_IMPORT_PATH variable is in CMakeCache.txt.\n"
|
||||
"For qmlRegister... calls, make sure that you define the Module URI as a string literal.\n")
|
||||
.arg(importInfo.name(), m_importPaths.join(QLatin1Char('\n'))));
|
||||
.arg(importInfo.name(),
|
||||
Utils::transform(m_importPaths, [](const Utils::FilePath &p) {
|
||||
return p.toString();
|
||||
}).join("\n")));
|
||||
}
|
||||
|
||||
return import;
|
||||
}
|
||||
|
||||
bool LinkPrivate::importLibrary(const Document::Ptr &doc,
|
||||
const QString &libraryPath,
|
||||
const Utils::FilePath &libraryPath,
|
||||
Import *import,
|
||||
ObjectValue *targetObject,
|
||||
const QString &importPath,
|
||||
bool optional
|
||||
)
|
||||
const Utils::FilePath &importPath,
|
||||
bool optional)
|
||||
{
|
||||
const ImportInfo &importInfo = import->info;
|
||||
|
||||
@@ -513,25 +529,36 @@ bool LinkPrivate::importLibrary(const Document::Ptr &doc,
|
||||
subImport.valid = true;
|
||||
subImport.info = ImportInfo::moduleImport(importName, vNow, importInfo.as(), importInfo.ast());
|
||||
|
||||
const QStringList libraryPaths = modulePaths(importName, vNow.toString(), m_importPaths);
|
||||
const QList<Utils::FilePath> libraryPaths = modulePaths(importName,
|
||||
vNow.toString(),
|
||||
m_importPaths);
|
||||
subImport.libraryPath = libraryPaths.value(0); // first is the best match
|
||||
|
||||
bool subImportFound = importLibrary(doc, subImport.libraryPath, &subImport, targetObject, importPath, true);
|
||||
|
||||
if (!subImportFound && errorLoc.isValid()) {
|
||||
import->valid = false;
|
||||
if (!(optional || (toImport.flags & QmlDirParser::Import::Optional)))
|
||||
error(doc, errorLoc,
|
||||
Link::tr(
|
||||
"Implicit import '%1' of QML module '%2' not found.\n\n"
|
||||
"Import paths:\n"
|
||||
"%3\n\n"
|
||||
"For qmake projects, use the QML_IMPORT_PATH variable to add import paths.\n"
|
||||
"For Qbs projects, declare and set a qmlImportPaths property in your product "
|
||||
"to add import paths.\n"
|
||||
"For qmlproject projects, use the importPaths property to add import paths.\n"
|
||||
"For CMake projects, make sure QML_IMPORT_PATH variable is in CMakeCache.txt.\n")
|
||||
.arg(importName, importInfo.name(), m_importPaths.join(QLatin1Char('\n'))));
|
||||
if (!(optional || (toImport.flags & QmlDirParser::Import::Optional))) {
|
||||
error(doc,
|
||||
errorLoc,
|
||||
Link::tr("Implicit import '%1' of QML module '%2' not found.\n\n"
|
||||
"Import paths:\n"
|
||||
"%3\n\n"
|
||||
"For qmake projects, use the QML_IMPORT_PATH variable to add import "
|
||||
"paths.\n"
|
||||
"For Qbs projects, declare and set a qmlImportPaths property in "
|
||||
"your product "
|
||||
"to add import paths.\n"
|
||||
"For qmlproject projects, use the importPaths property to add "
|
||||
"import paths.\n"
|
||||
"For CMake projects, make sure QML_IMPORT_PATH variable is in "
|
||||
"CMakeCache.txt.\n")
|
||||
.arg(importName,
|
||||
importInfo.name(),
|
||||
Utils::transform(m_importPaths, [](const Utils::FilePath &p) {
|
||||
return p.toString();
|
||||
}).join(QLatin1Char('\n'))));
|
||||
}
|
||||
} else if (!subImport.valid) {
|
||||
import->valid = false;
|
||||
}
|
||||
@@ -576,7 +603,9 @@ bool LinkPrivate::importLibrary(const Document::Ptr &doc,
|
||||
}
|
||||
} else {
|
||||
const QString packageName = importInfo.name();
|
||||
m_valueOwner->cppQmlTypes().load(libraryPath, libraryInfo.metaObjects(), packageName);
|
||||
m_valueOwner->cppQmlTypes().load(libraryPath.toString(),
|
||||
libraryInfo.metaObjects(),
|
||||
packageName);
|
||||
const auto objects = m_valueOwner->cppQmlTypes().createObjectsForImport(packageName,
|
||||
version);
|
||||
for (const CppComponentValue *object : objects)
|
||||
@@ -627,8 +656,10 @@ void LinkPrivate::appendDiagnostic(const Document::Ptr &doc, const DiagnosticMes
|
||||
(*allDiagnosticMessages)[doc->fileName()].append(message);
|
||||
}
|
||||
|
||||
void LinkPrivate::loadQmldirComponents(ObjectValue *import, ComponentVersion version,
|
||||
const LibraryInfo &libraryInfo, const QString &libraryPath)
|
||||
void LinkPrivate::loadQmldirComponents(ObjectValue *import,
|
||||
ComponentVersion version,
|
||||
const LibraryInfo &libraryInfo,
|
||||
const Utils::FilePath &libraryPath)
|
||||
{
|
||||
// if the version isn't valid, import the latest
|
||||
if (!version.isValid())
|
||||
@@ -647,7 +678,7 @@ void LinkPrivate::loadQmldirComponents(ObjectValue *import, ComponentVersion ver
|
||||
|
||||
importedTypes.insert(component.typeName);
|
||||
if (Document::Ptr importedDoc = m_snapshot.document(
|
||||
libraryPath + QLatin1Char('/') + component.fileName)) {
|
||||
libraryPath.pathAppended(component.fileName))) {
|
||||
if (ObjectValue *v = importedDoc->bind()->rootObjectValue())
|
||||
import->setMember(component.typeName, v);
|
||||
}
|
||||
@@ -667,7 +698,7 @@ void LinkPrivate::loadImplicitDirectoryImports(Imports *imports, const Document:
|
||||
imports->append(directoryImport);
|
||||
};
|
||||
|
||||
processImport(ImportInfo::implicitDirectoryImport(doc->path()));
|
||||
processImport(ImportInfo::implicitDirectoryImport(doc->path().path()));
|
||||
const auto qrcPaths = ModelManagerInterface::instance()->qrcPathsForFile(doc->fileName());
|
||||
for (const QString &path : qrcPaths) {
|
||||
processImport(ImportInfo::qrcDirectoryImport(
|
||||
|
||||
Reference in New Issue
Block a user