mirror of https://github.com/qt/qtgrpc.git
Extract wrapping namespace from package but not from messages/enums/services
Use the package defined in a .proto file when generating the wrapping namespace statements. This fixes the crash when .proto file contain no message definitions. Pick-to: 6.5 6.6 6.7 Fixes: QTBUG-122816 Change-Id: I0eb474217eb0126dee5919bbd7b12a20f8078124 Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
parent
250eb5c2e3
commit
56f7edbe26
|
|
@ -74,9 +74,9 @@ void GeneratorBase::OpenFileNamespaces(
|
|||
assert(printer != nullptr);
|
||||
assert(file != nullptr);
|
||||
const bool hasQtNamespace = (Options::instance().extraNamespace() == "QT_NAMESPACE");
|
||||
const std::string scopeNamespaces = file->message_type_count() > 0
|
||||
? common::getFullNamespace(file->message_type(0), "::")
|
||||
: common::getFullNamespace(file->enum_type(0), "::");
|
||||
|
||||
const std::string scopeNamespaces = common::getFullNamespace(file->package() + ".noop", "::");
|
||||
|
||||
printer->Print("\n");
|
||||
if (hasQtNamespace || file->package() == "QtCore" || file->package() == "QtGui")
|
||||
printer->PrintRaw("QT_BEGIN_NAMESPACE\n");
|
||||
|
|
@ -92,9 +92,8 @@ void GeneratorBase::CloseFileNamespaces(
|
|||
{
|
||||
assert(printer != nullptr);
|
||||
const bool hasQtNamespace = (Options::instance().extraNamespace() == "QT_NAMESPACE");
|
||||
const std::string scopeNamespaces = file->message_type_count() > 0
|
||||
? common::getFullNamespace(file->message_type(0), "::")
|
||||
: common::getFullNamespace(file->enum_type(0), "::");
|
||||
|
||||
const std::string scopeNamespaces = common::getFullNamespace(file->package() + ".noop", "::");
|
||||
if (!scopeNamespaces.empty()) {
|
||||
printer->Print({ { "scope_namespaces", scopeNamespaces } },
|
||||
CommonTemplates::NamespaceClosingTemplate());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
/* This file is autogenerated. DO NOT CHANGE. All changes will be lost */
|
||||
|
||||
#include "testserivcenomessages_client.grpc.qpb.h"
|
||||
|
||||
namespace qtgrpc::tests::nomessages {
|
||||
namespace TestService {
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
Client::Client(QObject *parent)
|
||||
: QAbstractGrpcClient("qtgrpc.tests.nomessages.TestService"_L1, parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<QGrpcCallReply> Client::testMethod(const qtprotobufnamespace::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options)
|
||||
{
|
||||
return call("testMethod"_L1, arg, options);
|
||||
}
|
||||
|
||||
void Client::testMethod(const qtprotobufnamespace::tests::SimpleStringMessage &arg, const QObject *context, const std::function<void(std::shared_ptr<QGrpcCallReply>)> &callback, const QGrpcCallOptions &options)
|
||||
{
|
||||
std::shared_ptr<QGrpcCallReply> reply = call("testMethod"_L1, arg, options);
|
||||
QObject::connect(reply.get(), &QGrpcCallReply::finished, context, [reply, callback]() {
|
||||
callback(reply);
|
||||
}, Qt::SingleShotConnection);
|
||||
}
|
||||
|
||||
} // namespace TestService
|
||||
} // namespace qtgrpc::tests::nomessages
|
||||
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/* This file is autogenerated. DO NOT CHANGE. All changes will be lost */
|
||||
|
||||
#ifndef QPROTOBUF_TESTSERIVCENOMESSAGES_CLIENT_H
|
||||
#define QPROTOBUF_TESTSERIVCENOMESSAGES_CLIENT_H
|
||||
|
||||
#include <QtProtobuf/qprotobufmessage.h>
|
||||
#include <QtProtobuf/qprotobufobject.h>
|
||||
#include <QtProtobuf/qprotobuflazymessagepointer.h>
|
||||
|
||||
#include <QtGrpc/qabstractgrpcclient.h>
|
||||
#include <QtGrpc/qgrpccallreply.h>
|
||||
#include <QtGrpc/qgrpcstream.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "basicmessages.qpb.h"
|
||||
|
||||
namespace qtgrpc::tests::nomessages {
|
||||
namespace TestService {
|
||||
|
||||
class Client : public QAbstractGrpcClient
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Client(QObject *parent = nullptr);
|
||||
std::shared_ptr<QGrpcCallReply> testMethod(const qtprotobufnamespace::tests::SimpleStringMessage &arg, const QGrpcCallOptions &options = {});
|
||||
Q_INVOKABLE void testMethod(const qtprotobufnamespace::tests::SimpleStringMessage &arg, const QObject *context, const std::function<void(std::shared_ptr<QGrpcCallReply>)> &callback, const QGrpcCallOptions &options = {});
|
||||
|
||||
|
||||
};
|
||||
} // namespace TestService
|
||||
} // namespace qtgrpc::tests::nomessages
|
||||
|
||||
#endif // QPROTOBUF_TESTSERIVCENOMESSAGES_CLIENT_H
|
||||
|
|
@ -282,6 +282,10 @@ void tst_qtgrpcgen::cmdLineGeneratedFile_data()
|
|||
<< "testservice"
|
||||
<< "/no-options/"
|
||||
<< QString(extension);
|
||||
QTest::addRow("testserivcenomessages%s", extension.data())
|
||||
<< "testserivcenomessages"
|
||||
<< "/no-options/"
|
||||
<< QString(extension);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
// Copyright (C) 2024 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
||||
syntax = "proto3";
|
||||
|
||||
import "basicmessages.proto";
|
||||
|
||||
package qtgrpc.tests.nomessages;
|
||||
|
||||
service TestService {
|
||||
rpc testMethod(qtprotobufnamespace.tests.SimpleStringMessage) returns (qtprotobufnamespace.tests.SimpleStringMessage) {}
|
||||
}
|
||||
Loading…
Reference in New Issue