From 80662934302f365b32b63a82cd8299d8efc61dc4 Mon Sep 17 00:00:00 2001 From: David Redondo Date: Thu, 8 Feb 2024 09:09:10 +0100 Subject: [PATCH] scanner: Make it work with mismatching protocol and file name The names of the files that wayland-scanner generates are based on the protocol file name not the protocol name that is defined in the xml. When those two mismatch qtwaylandscanner would generate code that fails to build. Pick-to: 6.7 Change-Id: Ieecd7a122177530ab1ff890367ce53809a8bb7b9 Reviewed-by: David Edmundson --- .../qtwaylandscanner/qtwaylandscanner.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/tools/qtwaylandscanner/qtwaylandscanner.cpp b/src/tools/qtwaylandscanner/qtwaylandscanner.cpp index 273a0012e09..6bdcb8da5ce 100644 --- a/src/tools/qtwaylandscanner/qtwaylandscanner.cpp +++ b/src/tools/qtwaylandscanner/qtwaylandscanner.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -422,6 +423,8 @@ bool Scanner::process() //QByteArray preProcessorProtocolName = QByteArray(m_protocolName).replace('-', '_').toUpper(); QByteArray preProcessorProtocolName = QByteArray(m_protocolName).toUpper(); + const QByteArray fileBaseName = QFileInfo(file).completeBaseName().toLocal8Bit(); + std::vector interfaces; while (m_xml->readNextStartElement()) { @@ -467,9 +470,9 @@ bool Scanner::process() printf("\n"); printf("#include \"wayland-server-core.h\"\n"); if (m_headerPath.isEmpty()) - printf("#include \"wayland-%s-server-protocol.h\"\n", QByteArray(m_protocolName).replace('_', '-').constData()); + printf("#include \"wayland-%s-server-protocol.h\"\n", fileBaseName.constData()); else - printf("#include <%s/wayland-%s-server-protocol.h>\n", m_headerPath.constData(), QByteArray(m_protocolName).replace('_', '-').constData()); + printf("#include <%s/wayland-%s-server-protocol.h>\n", m_headerPath.constData(), fileBaseName.constData()); printf("#include \n"); printf("#include \n"); printf("#include \n"); @@ -632,9 +635,9 @@ bool Scanner::process() if (m_option == ServerCode) { if (m_headerPath.isEmpty()) - printf("#include \"qwayland-server-%s.h\"\n", QByteArray(m_protocolName).replace('_', '-').constData()); + printf("#include \"qwayland-server-%s.h\"\n", fileBaseName.constData()); else - printf("#include <%s/qwayland-server-%s.h>\n", m_headerPath.constData(), QByteArray(m_protocolName).replace('_', '-').constData()); + printf("#include <%s/qwayland-server-%s.h>\n", m_headerPath.constData(), fileBaseName.constData()); printf("\n"); printf("QT_BEGIN_NAMESPACE\n"); printf("QT_WARNING_PUSH\n"); @@ -965,9 +968,9 @@ bool Scanner::process() printf("#define %s\n", inclusionGuard.constData()); printf("\n"); if (m_headerPath.isEmpty()) - printf("#include \"wayland-%s-client-protocol.h\"\n", QByteArray(m_protocolName).replace('_', '-').constData()); + printf("#include \"wayland-%s-client-protocol.h\"\n", fileBaseName.constData()); else - printf("#include <%s/wayland-%s-client-protocol.h>\n", m_headerPath.constData(), QByteArray(m_protocolName).replace('_', '-').constData()); + printf("#include <%s/wayland-%s-client-protocol.h>\n", m_headerPath.constData(), fileBaseName.constData()); printf("#include \n"); printf("#include \n"); printf("\n"); @@ -1077,9 +1080,9 @@ bool Scanner::process() if (m_option == ClientCode) { if (m_headerPath.isEmpty()) - printf("#include \"qwayland-%s.h\"\n", QByteArray(m_protocolName).replace('_', '-').constData()); + printf("#include \"qwayland-%s.h\"\n", fileBaseName.constData()); else - printf("#include <%s/qwayland-%s.h>\n", m_headerPath.constData(), QByteArray(m_protocolName).replace('_', '-').constData()); + printf("#include <%s/qwayland-%s.h>\n", m_headerPath.constData(), fileBaseName.constData()); printf("\n"); printf("QT_BEGIN_NAMESPACE\n"); printf("QT_WARNING_PUSH\n");