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>bb10
parent
9e7c567050
commit
cc70757964
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue