From cb9ae6ace2805e284725512cda360a3cc8269365 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Wed, 14 Dec 2022 14:50:07 +0000 Subject: [PATCH] dbus: Fix path to moc file in generated qdbusxml2cpp qdbusxml2cpp takes a filename to use for generated output. It may be in the form 'name.cpp' or just 'name'. For the moc file we need to convert this from a path to a name of a file in the same relative folder. It's not uncommon for this name to contain dots as sometimes a dbus interface name is used directly. For the cases where a suffix is not provided the whole name should be used. Fixes: QTBUG-110744 Change-Id: I3bf4ae8b2b9121184c2786009e8b5abcc5e3e410 Reviewed-by: Mate Barany Reviewed-by: Qt CI Bot Reviewed-by: Fabian Kosmale (cherry picked from commit c7425aa2950bfd47fdf390478616d1a383528886) Reviewed-by: Alexandru Croitor --- src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp | 10 +++++----- tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp | 10 ++++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp b/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp index 4f23b8604d0..0bfaf6eb1eb 100644 --- a/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp +++ b/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp @@ -142,12 +142,12 @@ static QString moc(const QString &name) QFileInfo fi{fileNames.front()}; if (isSupportedSuffix(fi.suffix())) { // Generates a file that contains the header and the implementation: include "filename.moc" - retval += fi.baseName(); + retval += fi.completeBaseName(); retval += ".moc"_L1; } else { // Separate source and header files are generated: include "moc_filename.cpp" retval += "moc_"_L1; - retval += fi.baseName(); + retval += fi.fileName(); retval += ".cpp"_L1; } } else { @@ -161,17 +161,17 @@ static QString moc(const QString &name) QFileInfo source{sourceName}; retval += "moc_"_L1; - retval += source.baseName(); + retval += source.completeBaseName(); retval += ".cpp"_L1; fprintf(stderr, "warning: no header name is provided, assuming it to be \"%s\"\n", - qPrintable(source.baseName() + ".h"_L1)); + qPrintable(source.completeBaseName() + ".h"_L1)); } else { // Both source and header generated: include "moc_headername.cpp" QFileInfo header{headerName}; retval += "moc_"_L1; - retval += header.baseName(); + retval += header.completeBaseName(); retval += ".cpp"_L1; } } diff --git a/tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp b/tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp index 0d30d4856e0..10bb410bd2f 100644 --- a/tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp +++ b/tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp @@ -384,6 +384,10 @@ void tst_qdbusxml2cpp::includeMoc_data() QTest::newRow("cpp-only") << ":foo.cpp" << QByteArray("#include \"moc_foo.cpp\"") << QByteArray("warning: no header name is provided, assuming it to be \"foo.h\""); QTest::newRow("header-and-cpp") << "foo_h.h:foo.cpp" << QByteArray("#include \"moc_foo_h.cpp\"") << QByteArray(""); + + QTest::newRow("combined-cpp with dots") << "foo.bar.cpp" << QByteArray("#include \"foo.bar.moc\"") << QByteArray(""); + QTest::newRow("without extension with dots") << "foo.bar" << QByteArray("#include \"moc_foo.bar.cpp\"") << QByteArray(""); + QTest::newRow("header-and-cpp with dots") << "foo.bar_h.h:foo.bar.cpp" << QByteArray("#include \"moc_foo.bar_h.cpp\"") << QByteArray(""); } void tst_qdbusxml2cpp::includeMoc() @@ -402,9 +406,11 @@ void tst_qdbusxml2cpp::includeMoc() QStringList parts = filenames.split(u':'); QFileInfo first{parts.first()}; - if ((parts.size() == 1) && (!first.suffix().isEmpty())) { + const bool firstHasSuffix = QStringList({"h", "cpp", "cc"}).contains(first.suffix()); + + if ((parts.size() == 1) && firstHasSuffix) { checkOneFile(parts.first(), expected); - } else if ((parts.size() == 1) && (first.suffix().isEmpty())) { + } else if ((parts.size() == 1) && (!firstHasSuffix)) { QString headerName{parts.first()}; headerName += ".h"; QString sourceName{parts.first()};