diff options
author | Mate Barany <mate.barany@qt.io> | 2022-06-27 17:47:52 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-07-07 07:44:16 +0000 |
commit | cc707579644bfbfae2b868a7a1ba0b933f2bcda5 (patch) | |
tree | 174c8bfa02221a36c7a848b6761db3d505301bd2 | |
parent | 9e7c5670509ac81efdf78b691e70e5ce3d408a09 (diff) |
qdbusxml2cpp: allow choosing <> over ""
qdbusxml2cpp's -i option uses "" for the includes.
However, an option to include with <> would be also
desirable, since some compilers may use a different
search strategy for <> than for "".
Add a new command line option -I/--global-include
to include the given argument using <>.
The new option will be used in qtconnectivity.
[ChangeLog][qdbusxml2cpp] Added command line option
-I/--global-include to include header files with <> in
the generated files.
Fixes: QTBUG-103362
Change-Id: If8e7f8b86440bdec53f2517db1ad460912664b20
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
-rw-r--r-- | src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp | 20 | ||||
-rw-r--r-- | tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp | 49 |
2 files changed, 68 insertions, 1 deletions
diff --git a/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp b/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp index 672242d665..0c35632e7b 100644 --- a/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp +++ b/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp @@ -37,6 +37,7 @@ static bool verbose; static bool includeMocs; static QString commandLine; static QStringList includes; +static QStringList globalIncludes; static QStringList wantedInterfaces; static const char includeList[] = @@ -459,6 +460,12 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf cs << "#include \"" << include << "\"" << Qt::endl; } + for (const QString &include : qAsConst(globalIncludes)) { + hs << "#include <" << include << ">" << Qt::endl; + if (headerName.isEmpty()) + cs << "#include <" << include << ">" << Qt::endl; + } + hs << Qt::endl; if (cppName != headerName) { @@ -772,6 +779,12 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte cs << "#include \"" << include << "\"" << Qt::endl; } + for (const QString &include : qAsConst(globalIncludes)) { + hs << "#include <" << include << ">" << Qt::endl; + if (headerName.isEmpty()) + cs << "#include <" << include << ">" << Qt::endl; + } + if (cppName != headerName) { if (!headerName.isEmpty() && headerName != "-"_L1) cs << "#include \"" << headerName << "\"" << Qt::endl; @@ -1058,9 +1071,13 @@ int main(int argc, char **argv) parser.addOption(classNameOption); QCommandLineOption addIncludeOption(QStringList() << QStringLiteral("i") << QStringLiteral("include"), - QStringLiteral("Add #include to the output"), QStringLiteral("filename")); + QStringLiteral("Add #include \"filename\" to the output"), QStringLiteral("filename")); parser.addOption(addIncludeOption); + QCommandLineOption addGlobalIncludeOption(QStringList() << QStringLiteral("I") << QStringLiteral("global-include"), + QStringLiteral("Add #include <filename> to the output"), QStringLiteral("filename")); + parser.addOption(addGlobalIncludeOption); + QCommandLineOption adapterParentOption(QStringLiteral("l"), QStringLiteral("When generating an adaptor, use <classname> as the parent class"), QStringLiteral("classname")); parser.addOption(adapterParentOption); @@ -1086,6 +1103,7 @@ int main(int argc, char **argv) adaptorFile = parser.value(adapterCodeOption); globalClassName = parser.value(classNameOption); includes = parser.values(addIncludeOption); + globalIncludes = parser.values(addGlobalIncludeOption); parentClassName = parser.value(adapterParentOption); includeMocs = parser.isSet(mocIncludeOption); skipNamespaces = parser.isSet(noNamespaceOption); diff --git a/tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp b/tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp index 6cbea1b328..db0c8af0fd 100644 --- a/tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp +++ b/tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp @@ -19,6 +19,8 @@ private slots: void initTestCase_data(); void process_data(); void process(); + void includeStyle_data(); + void includeStyle(); }; struct BasicTypeList { @@ -235,6 +237,53 @@ void tst_qdbusxml2cpp::process() QVERIFY2(output.count(adaptorSearch) == 1, qPrintable(adaptorSearch.pattern() + "\nin\n" + output)); } +void tst_qdbusxml2cpp::includeStyle_data() +{ + QTest::addColumn<bool>("isGlobal"); + QTest::addColumn<QByteArray>("expected"); + + QTest::newRow("localInclude") << false << QByteArray("#include \"test.hpp\""); + QTest::newRow("globalInclude") << true << QByteArray("#include <test.hpp>"); +} + +void tst_qdbusxml2cpp::includeStyle() +{ + QFETCH(bool, isGlobal); + QFETCH(QByteArray, expected); + QFETCH_GLOBAL(QString, commandLineArg); + + // feed it our XML data + static const char xml[] = + "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE // \n is included + "<node>\n" + " <interface name=\"local.name.is.not.important\">\n" + " </interface>\n" + "</node>\n"; + + // Run the tool + const QString binpath = QLibraryInfo::path(QLibraryInfo::BinariesPath); + const QString command = binpath + QLatin1String("/qdbusxml2cpp"); + QProcess process; + process.start(command, QStringList() << commandLineArg << "-" << "-N" << (isGlobal ? "-I" : "-i") << "test.hpp"); + QVERIFY2(process.waitForStarted(), qPrintable(process.errorString())); + + process.write(xml, int(sizeof xml) - 1); + while (process.bytesToWrite()) + QVERIFY2(process.waitForBytesWritten(), qPrintable(process.errorString())); + + process.closeWriteChannel(); + QVERIFY2(process.waitForFinished(), qPrintable(process.errorString())); + + QByteArray errOutput = process.readAllStandardError(); + QVERIFY2(errOutput.isEmpty(), errOutput); + QCOMPARE(process.exitCode(), 0); + + QByteArray fullOutput = process.readAll(); + QVERIFY(!fullOutput.isEmpty()); + QVERIFY(fullOutput.contains(expected)); +} + QTEST_MAIN(tst_qdbusxml2cpp) #include "tst_qdbusxml2cpp.moc" |