aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sources/shiboken2/ApiExtractor/typedatabase.cpp25
-rw-r--r--sources/shiboken2/ApiExtractor/typedatabase.h4
-rw-r--r--sources/shiboken2/ApiExtractor/typesystem.cpp21
-rw-r--r--sources/shiboken2/ApiExtractor/typesystem_p.h1
4 files changed, 40 insertions, 11 deletions
diff --git a/sources/shiboken2/ApiExtractor/typedatabase.cpp b/sources/shiboken2/ApiExtractor/typedatabase.cpp
index 4a96240c..0ed016d3 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 &currentPath) 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 &currentPath, 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 63f4cc73..dfddfc30 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 &currentPath, 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 &currentPath = 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 9c80a6c0..c20b0675 100644
--- a/sources/shiboken2/ApiExtractor/typesystem.cpp
+++ b/sources/shiboken2/ApiExtractor/typesystem.cpp
@@ -32,6 +32,7 @@
#include "reporthandler.h"
#include <QtCore/QDir>
#include <QtCore/QFile>
+#include <QtCore/QFileInfo>
#include <QtCore/QRegularExpression>
#include <QtCore/QSet>
#include <QtCore/QXmlStreamAttributes>
@@ -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<const QFile *>(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<const QFile *>(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 d485aad4..fd67ef49 100644
--- a/sources/shiboken2/ApiExtractor/typesystem_p.h
+++ b/sources/shiboken2/ApiExtractor/typesystem_p.h
@@ -172,6 +172,7 @@ private:
QHash<QString, StackElement::ElementType> tagNames;
QString m_currentSignature;
+ QString m_currentPath;
};
#endif