From 0de4dffa0c5abc80df7063daf6bc9d1754891a9d Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 2 Nov 2017 14:13:37 +0100 Subject: shikoben2: Extend type system path resolution - Remove stripping of directory components from the file names so that for example QtCore/typesystem_core.xml can also be resolved via type system path. - In addition, pass in the path of the current file being parsed so that for example typesystem_core_x11.xml is found from the directory of typesystem_core.xml while parsing Change-Id: Id10aafaf21750aa87460ccfe9ee3c3764086eda6 Reviewed-by: Alexandru Croitor --- sources/shiboken2/ApiExtractor/typedatabase.cpp | 25 +++++++++++++++++++------ sources/shiboken2/ApiExtractor/typedatabase.h | 4 +++- sources/shiboken2/ApiExtractor/typesystem.cpp | 21 +++++++++++++++++---- sources/shiboken2/ApiExtractor/typesystem_p.h | 1 + 4 files changed, 40 insertions(+), 11 deletions(-) (limited to 'sources/shiboken2') diff --git a/sources/shiboken2/ApiExtractor/typedatabase.cpp b/sources/shiboken2/ApiExtractor/typedatabase.cpp index 4a96240c4..0ed016d3d 100644 --- a/sources/shiboken2/ApiExtractor/typedatabase.cpp +++ b/sources/shiboken2/ApiExtractor/typedatabase.cpp @@ -451,16 +451,20 @@ bool TypeDatabase::isSuppressedWarning(const QString& s) const return false; } -QString TypeDatabase::modifiedTypesystemFilepath(const QString& tsFile, bool stripPath) const +QString TypeDatabase::modifiedTypesystemFilepath(const QString& tsFile, const QString ¤tPath) const { const QFileInfo tsFi(tsFile); if (tsFi.isAbsolute()) // No point in further lookups return tsFi.absoluteFilePath(); if (tsFi.isFile()) // Make path absolute return tsFi.absoluteFilePath(); - const QString fileName = stripPath ? tsFi.fileName() : tsFile; + if (!currentPath.isEmpty()) { + const QFileInfo fi(currentPath + QLatin1Char('/') + tsFile); + if (fi.isFile()) + return fi.absoluteFilePath(); + } for (const QString &path : m_typesystemPaths) { - const QFileInfo fi(path + QLatin1Char('/') + fileName); + const QFileInfo fi(path + QLatin1Char('/') + tsFile); if (fi.isFile()) return fi.absoluteFilePath(); } @@ -469,7 +473,13 @@ QString TypeDatabase::modifiedTypesystemFilepath(const QString& tsFile, bool str bool TypeDatabase::parseFile(const QString &filename, bool generate) { - QString filepath = modifiedTypesystemFilepath(filename); + return parseFile(filename, QString(), generate); +} + +bool TypeDatabase::parseFile(const QString &filename, const QString ¤tPath, bool generate) +{ + + QString filepath = modifiedTypesystemFilepath(filename, currentPath); if (m_parsedTypesystemFiles.contains(filepath)) return m_parsedTypesystemFiles[filepath]; @@ -478,8 +488,11 @@ bool TypeDatabase::parseFile(const QString &filename, bool generate) QFile file(filepath); if (!file.exists()) { m_parsedTypesystemFiles[filepath] = false; - qCWarning(lcShiboken).noquote().nospace() - << "Can't find " << filename << ", typesystem paths: " << m_typesystemPaths.join(QLatin1String(", ")); + QString message = QLatin1String("Can't find ") + filename; + if (!currentPath.isEmpty()) + message += QLatin1String(", current path: ") + currentPath; + message += QLatin1String(", typesystem paths: ") + m_typesystemPaths.join(QLatin1String(", ")); + qCWarning(lcShiboken).noquote().nospace() << message; return false; } if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { diff --git a/sources/shiboken2/ApiExtractor/typedatabase.h b/sources/shiboken2/ApiExtractor/typedatabase.h index 63f4cc73d..dfddfc300 100644 --- a/sources/shiboken2/ApiExtractor/typedatabase.h +++ b/sources/shiboken2/ApiExtractor/typedatabase.h @@ -142,6 +142,8 @@ public: static QString globalNamespaceClassName(const TypeEntry *te); bool parseFile(const QString &filename, bool generate = true); + bool parseFile(const QString &filename, const QString ¤tPath, bool generate); + bool parseFile(QIODevice* device, bool generate = true); bool setApiVersion(const QString& package, const QString& version); @@ -154,7 +156,7 @@ public: void setDropTypeEntries(QStringList dropTypeEntries); - QString modifiedTypesystemFilepath(const QString &tsFile, bool stripPath = true) const; + QString modifiedTypesystemFilepath(const QString &tsFile, const QString ¤tPath = QString()) const; #ifndef QT_NO_DEBUG_STREAM void formatDebug(QDebug &d) const; diff --git a/sources/shiboken2/ApiExtractor/typesystem.cpp b/sources/shiboken2/ApiExtractor/typesystem.cpp index 9c80a6c0b..c20b06750 100644 --- a/sources/shiboken2/ApiExtractor/typesystem.cpp +++ b/sources/shiboken2/ApiExtractor/typesystem.cpp @@ -32,6 +32,7 @@ #include "reporthandler.h" #include #include +#include #include #include #include @@ -183,13 +184,20 @@ Handler::Handler(TypeDatabase* database, bool generate) tagNames.insert(QLatin1String("add-function"), StackElement::AddFunction); } +static QString readerFileName(const QXmlStreamReader &reader) +{ + const QFile *file = qobject_cast(reader.device()); + return file != nullptr ? file->fileName() : QString(); +} + static QString msgReaderError(const QXmlStreamReader &reader, const QString &what) { QString message; QTextStream str(&message); str << "Error: "; - if (const QFile *file = qobject_cast(reader.device())) - str << "file=" << QDir::toNativeSeparators(file->fileName()) << ", "; + const QString fileName = readerFileName(reader); + if (!fileName.isEmpty()) + str << "file=" << QDir::toNativeSeparators(fileName) << ", "; str << "line=" << reader.lineNumber() << ", column=" << reader.columnNumber() << ", message=" << what; return message; @@ -203,6 +211,11 @@ static QString msgReaderError(const QXmlStreamReader &reader) bool Handler::parse(QXmlStreamReader &reader) { m_error.clear(); + m_currentPath.clear(); + const QString fileName = readerFileName(reader); + if (!fileName.isEmpty()) + m_currentPath = QFileInfo(fileName).absolutePath(); + while (!reader.atEnd()) { switch (reader.readNext()) { case QXmlStreamReader::NoToken: @@ -1325,7 +1338,7 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts return false; } bool generateChild = (convertBoolean(attributes[QLatin1String("generate")], QLatin1String("generate"), true) && (m_generate == TypeEntry::GenerateAll)); - if (!m_database->parseFile(name, generateChild)) { + if (!m_database->parseFile(name, m_currentPath, generateChild)) { m_error = QStringLiteral("Failed to parse: '%1'").arg(name); return false; } @@ -1947,7 +1960,7 @@ bool Handler::startElement(const QStringRef &n, const QXmlStreamAttributes &atts if (m_generate != TypeEntry::GenerateForSubclass && m_generate != TypeEntry::GenerateNothing && !file_name.isEmpty()) { - const QString resolved = m_database->modifiedTypesystemFilepath(file_name, false); + const QString resolved = m_database->modifiedTypesystemFilepath(file_name, m_currentPath); if (QFile::exists(resolved)) { QFile codeFile(resolved); if (codeFile.open(QIODevice::Text | QIODevice::ReadOnly)) { diff --git a/sources/shiboken2/ApiExtractor/typesystem_p.h b/sources/shiboken2/ApiExtractor/typesystem_p.h index d485aad42..fd67ef49b 100644 --- a/sources/shiboken2/ApiExtractor/typesystem_p.h +++ b/sources/shiboken2/ApiExtractor/typesystem_p.h @@ -172,6 +172,7 @@ private: QHash tagNames; QString m_currentSignature; + QString m_currentPath; }; #endif -- cgit v1.2.3