diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-04-14 08:50:01 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-04-16 15:59:19 +0200 |
commit | 617282b3a89cb557900343b262859bb6eaa9b2ed (patch) | |
tree | 3942f7bc8980c2c4bb900f2832915c26f1e061c0 | |
parent | 6d449e9effd92686704fd2d3685da9b018a96f4d (diff) |
shiboken: Allow for parsing headers under system include paths
Extend the <system-include> element for a trailing slash to indicate
an absolute path against which a file is matched.
Change-Id: I9557e26b941a7d5d5cab575cd978c158c6859b97
Fixes: PYSIDE-1267
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r-- | sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp | 19 | ||||
-rw-r--r-- | sources/shiboken2/doc/typesystem_specifying_types.rst | 6 |
2 files changed, 21 insertions, 4 deletions
diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp index 7c188535f..ebec8770e 100644 --- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp +++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp @@ -222,7 +222,8 @@ public: FunctionModelItem m_currentFunction; ArgumentModelItem m_currentArgument; VariableModelItem m_currentField; - QByteArrayList m_systemIncludes; + QByteArrayList m_systemIncludes; // files, like "memory" + QByteArrayList m_systemIncludePaths; // paths, like "/usr/include/Qt/" int m_anonymousEnumCount = 0; CodeModel::FunctionType m_currentFunctionType = CodeModel::Normal; @@ -696,6 +697,11 @@ static bool cStringStartsWith(const char *str, const char (&prefix)[N]) } #endif +static bool cStringStartsWith(const char *str, const QByteArray &prefix) +{ + return std::strncmp(prefix.constData(), str, int(prefix.size())) == 0; +} + bool BuilderPrivate::visitHeader(const char *cFileName) const { // Resolve OpenGL typedefs although the header is considered a system header. @@ -728,6 +734,10 @@ bool BuilderPrivate::visitHeader(const char *cFileName) const return true; } } + for (const auto &systemIncludePath : m_systemIncludePaths) { + if (cStringStartsWith(cFileName, systemIncludePath)) + return true; + } return false; } @@ -752,7 +762,12 @@ bool Builder::visitLocation(const CXSourceLocation &location) const void Builder::setSystemIncludes(const QByteArrayList &systemIncludes) { - d->m_systemIncludes = systemIncludes; + for (const auto &i : systemIncludes) { + if (i.endsWith('/')) + d->m_systemIncludePaths.append(i); + else + d->m_systemIncludes.append(i); + } } FileModelItem Builder::dom() const diff --git a/sources/shiboken2/doc/typesystem_specifying_types.rst b/sources/shiboken2/doc/typesystem_specifying_types.rst index 5d086f4d3..27267faab 100644 --- a/sources/shiboken2/doc/typesystem_specifying_types.rst +++ b/sources/shiboken2/doc/typesystem_specifying_types.rst @@ -468,12 +468,14 @@ system-include ^^^^^^^^^^^^^^ The optional **system-include** specifies the name of a system include - file to be parsed. Normally, include files considered to be system - include files are skipped by the C++ code parser. Its primary use case + file or a system include path (indicated by a trailing slash) to be + parsed. Normally, include files considered to be system include + files are skipped by the C++ code parser. Its primary use case is exposing classes from the STL library. .. code-block:: xml <typesystem> <system-include file-name="memory"/> + <system-include file-name="/usr/include/Qt/"/> </typesystem> |