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 <mate.barany@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit c7425aa2950bfd47fdf390478616d1a383528886) Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
parent
2de82be7f1
commit
cb9ae6ace2
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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()};
|
||||
|
Loading…
x
Reference in New Issue
Block a user