diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2021-10-18 18:12:39 +0200 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2021-10-25 14:57:18 +0200 |
commit | 2a72f0f15d9c433d8d03873637e84fe2e10735b7 (patch) | |
tree | 08aab5b27314c71f303c598687b3faf28ea31904 | |
parent | 623e396e881f383950b78518a193aff602d8568e (diff) |
Fix compilation with QT_NAMESPACE and tracing on Linux
The tracegen tool was not taking into account that Qt could be build
with a custom namespace. As a result, the combination of namespace
build and tracing enabled was not working, because tracegen generated
classes without the namespace.
This patch fixes it.
We cannot add QT_BEGIN_NAMESPACE/QT_END_NAMESPACE because of the
tricky logic that recursively includes the generated header file
multiple times, also including the code like
static const struct lttng_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = {
(hash)include TRACEPOINT_INCLUDE
NULL, /* Dummy, C99 forbids 0-len array. */
};
where TRACEPOINT_INCLUDE is the path to the generated header.
This patch is using QT_USE_NAMESPACE, wrapped into some #ifdefs.
This should be safe, considering that the generated trace headers
are only used as private API.
The windows tracing support seems to be broken even in a
non-namespace build, so it's not handled in this patch.
Task-number: QTBUG-97246
Pick-to: 6.2
Change-Id: I12db76e199a3aa3abde641fbf99a6e1a3d7de203
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
-rw-r--r-- | src/tools/tracegen/lttng.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/tools/tracegen/lttng.cpp b/src/tools/tracegen/lttng.cpp index e628fbd680..9a8dfc9f4a 100644 --- a/src/tools/tracegen/lttng.cpp +++ b/src/tools/tracegen/lttng.cpp @@ -130,6 +130,12 @@ static void writePrologue(QTextStream &stream, const QString &fileName, const Pr << "#define TRACEPOINT_INCLUDE \"" << fileName << "\"\n\n"; stream << "#include <lttng/tracepoint.h>\n\n"; + + const QString namespaceGuard = guard + QStringLiteral("_USE_NAMESPACE"); + stream << "#if !defined(" << namespaceGuard << ")\n" + << "#define " << namespaceGuard << "\n" + << "QT_USE_NAMESPACE\n" + << "#endif // " << namespaceGuard << "\n\n"; } static void writeEpilogue(QTextStream &stream, const QString &fileName) @@ -154,6 +160,7 @@ static void writeWrapper(QTextStream &stream, stream << "\n" << "#ifndef " << includeGuard << "\n" << "#define " << includeGuard << "\n" + << "QT_BEGIN_NAMESPACE\n" << "namespace QtPrivate {\n"; stream << "inline void trace_" << name << "(" << argList << ")\n" @@ -172,6 +179,7 @@ static void writeWrapper(QTextStream &stream, << "}\n"; stream << "} // namespace QtPrivate\n" + << "QT_END_NAMESPACE\n" << "#endif // " << includeGuard << "\n\n"; } |