aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/ApiExtractor
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-10-01 08:53:29 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-10-02 07:35:30 +0200
commit62c21af778b7bff6c86e7f89ef03a87efa6c51cb (patch)
tree8d81d10c06338484b171e819afffbe5aa1b30d26 /sources/shiboken2/ApiExtractor
parent430d02db24b95a56ae0acc6a9df6a0effe49da0d (diff)
Move the annotations for parsing Qt-based headers to shiboken2
It is one of the lesser known things that any project generating bindings for Qt-based code needs to include pyside2_global.h in order for signals, slots and properties to be recognized, since the annotation macro definitions are in this file. Move the definitions over to shiboken2 to remove the need to include it. [ChangeLog][shiboken2] Projects generating bindings for Qt-based code no longer need to include pyside2_global.h. Change-Id: I531bb7444561ccfc352f3be09ecdf854f9f7dd3d Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken2/ApiExtractor')
-rw-r--r--sources/shiboken2/ApiExtractor/apiextractor.cpp19
-rw-r--r--sources/shiboken2/ApiExtractor/apiextractor.h2
2 files changed, 19 insertions, 2 deletions
diff --git a/sources/shiboken2/ApiExtractor/apiextractor.cpp b/sources/shiboken2/ApiExtractor/apiextractor.cpp
index 3fdd613ae..aa552cdd3 100644
--- a/sources/shiboken2/ApiExtractor/apiextractor.cpp
+++ b/sources/shiboken2/ApiExtractor/apiextractor.cpp
@@ -172,7 +172,20 @@ int ApiExtractor::classCount() const
return m_builder->classes().count();
}
-bool ApiExtractor::run()
+// Add defines required for parsing Qt code headers
+static void addPySideExtensions(QByteArrayList *a)
+{
+ // Make "signals:", "slots:" visible as access specifiers
+ a->append(QByteArrayLiteral("-DQT_ANNOTATE_ACCESS_SPECIFIER(a)=__attribute__((annotate(#a)))"));
+
+ // Q_PROPERTY is defined as class annotation which does not work since a
+ // sequence of properties will to expand to a sequence of annotations
+ // annotating nothing, causing clang to complain. Instead, define it away in a
+ // static assert with the stringified argument in a ','-operator (cf qdoc).
+ a->append(QByteArrayLiteral("-DQT_ANNOTATE_CLASS(type,...)=static_assert(sizeof(#__VA_ARGS__),#type);"));
+}
+
+bool ApiExtractor::run(bool usePySideExtensions)
{
if (m_builder)
return false;
@@ -215,6 +228,10 @@ bool ApiExtractor::run()
<< "clang language level: " << int(m_languageLevel)
<< "\nclang arguments: " << arguments;
}
+
+ if (usePySideExtensions)
+ addPySideExtensions(&arguments);
+
const bool result = m_builder->build(arguments, m_languageLevel);
if (!result)
autoRemove = false;
diff --git a/sources/shiboken2/ApiExtractor/apiextractor.h b/sources/shiboken2/ApiExtractor/apiextractor.h
index b0c2c696f..9c79ae7a5 100644
--- a/sources/shiboken2/ApiExtractor/apiextractor.h
+++ b/sources/shiboken2/ApiExtractor/apiextractor.h
@@ -93,7 +93,7 @@ public:
int classCount() const;
- bool run();
+ bool run(bool usePySideExtensions);
private:
QString m_typeSystemFileName;
QFileInfoList m_cppFileNames;