diff options
author | David Edmundson <davidedmundson@kde.org> | 2022-12-14 14:50:07 +0000 |
---|---|---|
committer | David Edmundson <davidedmundson@kde.org> | 2022-12-16 17:21:57 +0000 |
commit | c7425aa2950bfd47fdf390478616d1a383528886 (patch) | |
tree | 2a7a56a185b307888b828ded52f5c296e5a04289 | |
parent | 7d0f08094a2318b753ea7d69b71c0abe0a46b3d3 (diff) |
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.
Pick-to: 6.5
Change-Id: I3bf4ae8b2b9121184c2786009e8b5abcc5e3e410
Reviewed-by: Mate Barany <mate.barany@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r-- | src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp | 10 | ||||
-rw-r--r-- | 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 4f23b8604d..0bfaf6eb1e 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 0d30d4856e..10bb410bd2 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()}; |