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>
This commit is contained in:
parent
623e396e88
commit
2a72f0f15d
@ -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";
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user