aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-05-10 08:31:46 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-05-10 13:06:09 +0000
commitdc34a24ffaf8cb76699cefc53d0ba8a1cfcbf08e (patch)
tree10bbc795cbe088a25d97cf8c896e2fd80536f2bb
parent86d25d548564b4228d5829aafc3a168b329c0812 (diff)
shiboken6: Add option to use global headers
shiboken6 historically expected a global header consisting of #include directives for the desired headers which was excluded from the generated code. Make it possible to use class headers directly with a command line option. Task-number: PYSIDE-1338 Change-Id: I4543be888136736deb2612abc27dfc04e177e469 Reviewed-by: Christian Tismer <tismer@stackless.com> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> (cherry picked from commit d075757286e0b7fbbef118eee4720671d48fc91b) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp14
-rw-r--r--sources/shiboken6/ApiExtractor/abstractmetabuilder.h2
-rw-r--r--sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h1
-rw-r--r--sources/shiboken6/ApiExtractor/apiextractor.cpp5
-rw-r--r--sources/shiboken6/ApiExtractor/apiextractor.h1
-rw-r--r--sources/shiboken6/doc/shibokengenerator.rst15
-rw-r--r--sources/shiboken6/generator/main.cpp9
7 files changed, 42 insertions, 5 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp
index 8e83a2df4..dafbed00e 100644
--- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp
+++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp
@@ -67,6 +67,8 @@ static QString stripTemplateArgs(const QString &name)
return pos < 0 ? name : name.left(pos);
}
+bool AbstractMetaBuilderPrivate::m_useGlobalHeader = false;
+
AbstractMetaBuilderPrivate::AbstractMetaBuilderPrivate() :
m_logDirectory(QLatin1String(".") + QDir::separator())
{
@@ -3147,6 +3149,11 @@ void AbstractMetaBuilder::setHeaderPaths(const HeaderPaths &hp)
}
}
+void AbstractMetaBuilder::setUseGlobalHeader(bool h)
+{
+ AbstractMetaBuilderPrivate::m_useGlobalHeader = h;
+}
+
void AbstractMetaBuilder::setSkipDeprecated(bool value)
{
d->m_skipDeprecated = value;
@@ -3180,9 +3187,10 @@ void AbstractMetaBuilderPrivate::setInclude(TypeEntry *te, const QString &path)
if (it == m_resolveIncludeHash.end()) {
QFileInfo info(path);
const QString fileName = info.fileName();
- if (std::any_of(m_globalHeaders.cbegin(), m_globalHeaders.cend(),
- [fileName] (const QFileInfo &fi) {
- return fi.fileName() == fileName; })) {
+ if (!m_useGlobalHeader
+ && std::any_of(m_globalHeaders.cbegin(), m_globalHeaders.cend(),
+ [fileName] (const QFileInfo &fi) {
+ return fi.fileName() == fileName; })) {
return;
}
diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.h b/sources/shiboken6/ApiExtractor/abstractmetabuilder.h
index 4fe6741b1..97c324f51 100644
--- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.h
+++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.h
@@ -86,6 +86,8 @@ public:
void setGlobalHeaders(const QFileInfoList& globalHeaders);
void setHeaderPaths(const HeaderPaths &h);
+ static void setUseGlobalHeader(bool h);
+
void setSkipDeprecated(bool value);
enum TranslateTypeFlag {
diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h b/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h
index 6256d078c..bcfd7bc73 100644
--- a/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h
+++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h
@@ -220,6 +220,7 @@ public:
mutable QHash<QString, Include> m_resolveIncludeHash;
QList<TypeClassEntry> m_typeSystemTypeDefs; // look up metatype->class for type system typedefs
bool m_skipDeprecated = false;
+ static bool m_useGlobalHeader;
};
#endif // ABSTRACTMETBUILDER_P_H
diff --git a/sources/shiboken6/ApiExtractor/apiextractor.cpp b/sources/shiboken6/ApiExtractor/apiextractor.cpp
index fb4e30c9f..f91844126 100644
--- a/sources/shiboken6/ApiExtractor/apiextractor.cpp
+++ b/sources/shiboken6/ApiExtractor/apiextractor.cpp
@@ -276,6 +276,11 @@ void ApiExtractor::setClangOptions(const QStringList &co)
m_clangOptions = co;
}
+void ApiExtractor::setUseGlobalHeader(bool h)
+{
+ AbstractMetaBuilder::setUseGlobalHeader(h);
+}
+
#ifndef QT_NO_DEBUG_STREAM
template <class Container>
static void debugFormatSequence(QDebug &d, const char *key, const Container& c)
diff --git a/sources/shiboken6/ApiExtractor/apiextractor.h b/sources/shiboken6/ApiExtractor/apiextractor.h
index a3d25540a..c0788462f 100644
--- a/sources/shiboken6/ApiExtractor/apiextractor.h
+++ b/sources/shiboken6/ApiExtractor/apiextractor.h
@@ -83,6 +83,7 @@ public:
void setLanguageLevel(LanguageLevel languageLevel);
QStringList clangOptions() const;
void setClangOptions(const QStringList &co);
+ static void setUseGlobalHeader(bool h);
const AbstractMetaEnumList &globalEnums() const;
const AbstractMetaFunctionCList &globalFunctions() const;
diff --git a/sources/shiboken6/doc/shibokengenerator.rst b/sources/shiboken6/doc/shibokengenerator.rst
index ee0b54800..a5092bfd6 100644
--- a/sources/shiboken6/doc/shibokengenerator.rst
+++ b/sources/shiboken6/doc/shibokengenerator.rst
@@ -49,8 +49,16 @@ care of interfacing Python and the underlying C++ library.
Handwritten inputs
==================
-Creating new bindings involves creating two pieces of "code": the typesystem and
-the inject code.
+Creating new bindings involves creating several pieces of "code": the header,
+the typesystem and, in most cases, the injected code.
+
+:header: A header with ``#include`` directives listing all the headers of the
+ desired classes. This header is not referenced by the generated code.
+ Alternatively, it is possible to pass a list of the headers of the
+ desired classes directly on the command line. In this case,
+ the command line option ``--use-global-header`` should be passed as
+ well to prevent the headers from being suppressed in the generated
+ code.
:typesystem: XML files that provides the developer with a tool to customize the
way that the generators will see the classes and functions. For
@@ -127,6 +135,9 @@ Options
fully qualified Python type names ('Module.Class'), but the module can
be omitted ('Class').
+``--use-global-header``
+ Use the global headers passed on the command line in generated code.
+
.. _generation-set:
``--generation-set``
diff --git a/sources/shiboken6/generator/main.cpp b/sources/shiboken6/generator/main.cpp
index e13b71eb4..73b1a9658 100644
--- a/sources/shiboken6/generator/main.cpp
+++ b/sources/shiboken6/generator/main.cpp
@@ -61,6 +61,7 @@ static inline QString systemIncludePathOption() { return QStringLiteral("system-
static inline QString typesystemPathOption() { return QStringLiteral("typesystem-paths"); }
static inline QString helpOption() { return QStringLiteral("help"); }
static inline QString diffOption() { return QStringLiteral("diff"); }
+static inline QString useGlobalHeaderOption() { return QStringLiteral("use-global-header"); }
static inline QString dryrunOption() { return QStringLiteral("dry-run"); }
static inline QString skipDeprecatedOption() { return QStringLiteral("skip-deprecated"); }
@@ -353,6 +354,8 @@ void printUsage()
{QLatin1String("-isystem<path>"), {} },
{QLatin1String("system-include-paths=") + pathSyntax,
QLatin1String("System include paths used by the C++ parser")},
+ {useGlobalHeaderOption(),
+ QLatin1String("Use the global headers in generated code.")},
{QLatin1String("generator-set=<\"generator module\">"),
QLatin1String("generator-set to be used. e.g. qtdoc")},
{skipDeprecatedOption(),
@@ -487,6 +490,12 @@ int shibokenMain(int argc, char *argv[])
FileOut::setDiff(true);
}
+ ait = args.options.find(useGlobalHeaderOption());
+ if (ait != args.options.end()) {
+ args.options.erase(ait);
+ ApiExtractor::setUseGlobalHeader(true);
+ }
+
ait = args.options.find(dryrunOption());
if (ait != args.options.end()) {
args.options.erase(ait);