mirror of https://github.com/qt/qtgrpc.git
Fix the invalid handling of header files suffixes
Avoid removing and appending header files suffixes where this is not intentional. Change the default internal header file template and always add the suffix explicitly, where required. Pick-to: 6.8 Change-Id: I1fff1d3813700d6387964d5411970b21ecb4a2e6 Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
This commit is contained in:
parent
c344407f8c
commit
4577291626
|
@ -78,6 +78,9 @@ bool QGrpcGenerator::Generate(const FileDescriptor *file,
|
|||
std::set<std::string> QGrpcGenerator::GetInternalIncludes(const FileDescriptor *file)
|
||||
{
|
||||
std::set<std::string> includes;
|
||||
std::string fullSuffix = CommonTemplates::ProtoFileSuffix();
|
||||
fullSuffix += CommonTemplates::HeaderSuffix();
|
||||
|
||||
assert(file != nullptr);
|
||||
for (int i = 0; i < file->service_count(); ++i) {
|
||||
const ServiceDescriptor *service = file->service(i);
|
||||
|
@ -85,19 +88,19 @@ std::set<std::string> QGrpcGenerator::GetInternalIncludes(const FileDescriptor *
|
|||
const MethodDescriptor *method = service->method(i);
|
||||
if (method->input_type()->file() != service->file()) {
|
||||
includes.insert(utils::removeFileSuffix(method->input_type()->file()->name())
|
||||
+ CommonTemplates::ProtoFileSuffix());
|
||||
+ fullSuffix);
|
||||
}
|
||||
|
||||
if (method->output_type()->file() != service->file()) {
|
||||
includes.insert(utils::removeFileSuffix(method->output_type()->file()->name())
|
||||
+ CommonTemplates::ProtoFileSuffix());
|
||||
+ fullSuffix);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (file->message_type_count() > 0) {
|
||||
includes.insert(common::generateRelativeFilePath(file,
|
||||
utils::extractFileBasename(file->name()))
|
||||
+ CommonTemplates::ProtoFileSuffix());
|
||||
+ fullSuffix);
|
||||
}
|
||||
return includes;
|
||||
}
|
||||
|
@ -130,11 +133,12 @@ void QGrpcGenerator::GenerateQmlClientServices(
|
|||
const std::string qmlBasename = qmlPrefix + basename;
|
||||
|
||||
const std::string realtivePath = common::generateRelativeFilePath(file, basename);
|
||||
const std::string qmlRealtivePath = qmlPrefix +realtivePath ;
|
||||
const std::string qmlRealtivePath = qmlPrefix + realtivePath;
|
||||
|
||||
// QML registered client class
|
||||
std::unique_ptr<ZeroCopyOutputStream> clientQmlHeaderStream(
|
||||
generatorContext->Open(qmlRealtivePath + ".h"));
|
||||
std::unique_ptr<ZeroCopyOutputStream>
|
||||
clientQmlHeaderStream(generatorContext->Open(qmlRealtivePath
|
||||
+ CommonTemplates::HeaderSuffix()));
|
||||
std::unique_ptr<ZeroCopyOutputStream> clientQmlSourceStream(
|
||||
generatorContext->Open(qmlRealtivePath + ".cpp"));
|
||||
|
||||
|
@ -144,13 +148,18 @@ void QGrpcGenerator::GenerateQmlClientServices(
|
|||
printDisclaimer(qmlHeaderPrinter.get());
|
||||
printDisclaimer(qmlSourcePrinter.get());
|
||||
|
||||
std::string headerGuard = common::headerGuardFromFilename(qmlBasename + ".h");
|
||||
std::string headerGuard = common::headerGuardFromFilename(qmlBasename
|
||||
+ CommonTemplates::HeaderSuffix());
|
||||
QGrpcGenerator::printHeaderGuardBegin(qmlHeaderPrinter.get(), headerGuard);
|
||||
|
||||
printIncludes(qmlHeaderPrinter.get(), { realtivePath }, externalQmlIncludes(), {});
|
||||
printIncludes(qmlHeaderPrinter.get(), { realtivePath + CommonTemplates::HeaderSuffix() },
|
||||
externalQmlIncludes(), {});
|
||||
|
||||
qmlSourcePrinter->Print({ { "include", qmlRealtivePath } },
|
||||
CommonTemplates::InternalIncludeTemplate());
|
||||
qmlSourcePrinter->Print(
|
||||
{
|
||||
{ "include", qmlRealtivePath + CommonTemplates::HeaderSuffix() }
|
||||
},
|
||||
CommonTemplates::InternalIncludeTemplate());
|
||||
|
||||
QGrpcGenerator::RunPrinter<QmlClientDeclarationPrinter>(file, qmlHeaderPrinter);
|
||||
QGrpcGenerator::RunPrinter<QmlClientDefinitionPrinter>(file, qmlSourcePrinter);
|
||||
|
@ -174,8 +183,8 @@ bool QGrpcGenerator::GenerateClientServices(const FileDescriptor *file,
|
|||
GenerateQmlClientServices(file, generatorContext);
|
||||
|
||||
// CPP client class
|
||||
std::unique_ptr<ZeroCopyOutputStream> clientHeaderStream(
|
||||
generatorContext->Open(realtivePath + ".h"));
|
||||
std::unique_ptr<ZeroCopyOutputStream>
|
||||
clientHeaderStream(generatorContext->Open(realtivePath + CommonTemplates::HeaderSuffix()));
|
||||
std::unique_ptr<ZeroCopyOutputStream> clientSourceStream(
|
||||
generatorContext->Open(realtivePath + ".cpp"));
|
||||
|
||||
|
@ -185,16 +194,20 @@ bool QGrpcGenerator::GenerateClientServices(const FileDescriptor *file,
|
|||
printDisclaimer(clientHeaderPrinter.get());
|
||||
printDisclaimer(clientSourcePrinter.get());
|
||||
|
||||
const std::string headerGuard = common::headerGuardFromFilename(basename + ".h");
|
||||
const std::string
|
||||
headerGuard = common::headerGuardFromFilename(basename + CommonTemplates::HeaderSuffix());
|
||||
QGrpcGenerator::printHeaderGuardBegin(clientHeaderPrinter.get(), headerGuard);
|
||||
|
||||
clientSourcePrinter->Print({ { "include", realtivePath } },
|
||||
CommonTemplates::InternalIncludeTemplate());
|
||||
clientSourcePrinter->Print(
|
||||
{
|
||||
{ "include", realtivePath + CommonTemplates::HeaderSuffix() }
|
||||
},
|
||||
CommonTemplates::InternalIncludeTemplate());
|
||||
|
||||
std::set<std::string> internalIncludes = QGrpcGenerator::GetInternalIncludes(file);
|
||||
if (!Options::instance().exportMacroFilename().empty()) {
|
||||
std::string exportMacroFilename = Options::instance().exportMacroFilename();
|
||||
internalIncludes.insert(utils::removeFileSuffix(exportMacroFilename));
|
||||
internalIncludes.insert(exportMacroFilename);
|
||||
}
|
||||
|
||||
printIncludes(clientHeaderPrinter.get(), internalIncludes, externalIncludes(),
|
||||
|
|
|
@ -60,7 +60,8 @@ void QProtobufGenerator::GenerateSources(const FileDescriptor *file,
|
|||
printDisclaimer(sourcePrinter.get());
|
||||
|
||||
utils::ExternalIncludesOrderedSet externalIncludes{ "QtProtobuf/qprotobufregistration.h" };
|
||||
std::set<std::string> internalIncludes{ relativePath + CommonTemplates::ProtoFileSuffix() };
|
||||
std::set<std::string> internalIncludes{ relativePath + CommonTemplates::ProtoFileSuffix()
|
||||
+ CommonTemplates::HeaderSuffix() };
|
||||
|
||||
printIncludes(registrationPrinter.get(), internalIncludes, externalIncludes, {});
|
||||
|
||||
|
@ -114,8 +115,8 @@ void QProtobufGenerator::GenerateHeader(const FileDescriptor *file,
|
|||
CommonTemplates::ProtoFileSuffix();
|
||||
std::string relativePath = common::generateRelativeFilePath(file, basename);
|
||||
|
||||
std::unique_ptr<io::ZeroCopyOutputStream> headerStream(generatorContext->Open(relativePath
|
||||
+ ".h"));
|
||||
std::unique_ptr<io::ZeroCopyOutputStream>
|
||||
headerStream(generatorContext->Open(relativePath + CommonTemplates::HeaderSuffix()));
|
||||
std::shared_ptr<Printer> headerPrinter(new Printer(headerStream.get(), '$'));
|
||||
|
||||
printDisclaimer(headerPrinter.get());
|
||||
|
@ -124,11 +125,12 @@ void QProtobufGenerator::GenerateHeader(const FileDescriptor *file,
|
|||
utils::ExternalIncludesOrderedSet externalIncludes;
|
||||
std::set<std::string> systemIncludes;
|
||||
|
||||
const std::string headerGuard = common::headerGuardFromFilename(basename + ".h");
|
||||
const std::string
|
||||
headerGuard = common::headerGuardFromFilename(basename + CommonTemplates::HeaderSuffix());
|
||||
QProtobufGenerator::printHeaderGuardBegin(headerPrinter.get(), headerGuard);
|
||||
if (!Options::instance().exportMacroFilename().empty()) {
|
||||
std::string exportMacroFilename = Options::instance().exportMacroFilename();
|
||||
internalIncludes.insert(utils::removeFileSuffix(exportMacroFilename));
|
||||
internalIncludes.insert(exportMacroFilename);
|
||||
}
|
||||
|
||||
externalIncludes.insert("QtCore/qbytearray.h");
|
||||
|
@ -200,7 +202,8 @@ void QProtobufGenerator::GenerateHeader(const FileDescriptor *file,
|
|||
continue;
|
||||
}
|
||||
internalIncludes.insert(utils::removeFileSuffix(file->dependency(i)->name())
|
||||
+ CommonTemplates::ProtoFileSuffix());
|
||||
+ CommonTemplates::ProtoFileSuffix()
|
||||
+ CommonTemplates::HeaderSuffix());
|
||||
}
|
||||
|
||||
printIncludes(headerPrinter.get(), internalIncludes, externalIncludes, systemIncludes);
|
||||
|
|
|
@ -95,7 +95,7 @@ const char *CommonTemplates::HeaderGuardEndTemplate()
|
|||
|
||||
const char *CommonTemplates::InternalIncludeTemplate()
|
||||
{
|
||||
return "#include \"$include$.h\"\n";
|
||||
return "#include \"$include$\"\n";
|
||||
}
|
||||
const char *CommonTemplates::ExternalIncludeTemplate()
|
||||
{
|
||||
|
@ -981,6 +981,11 @@ const std::unordered_map<::google::protobuf::FieldDescriptor::Type, std::string>
|
|||
return map;
|
||||
}
|
||||
|
||||
const char *CommonTemplates::HeaderSuffix()
|
||||
{
|
||||
return ".h";
|
||||
}
|
||||
|
||||
const char *CommonTemplates::ProtoFileSuffix()
|
||||
{
|
||||
return ".qpb";
|
||||
|
|
|
@ -167,6 +167,7 @@ public:
|
|||
|
||||
static const char *RepeatedSuffix();
|
||||
static const char *ProtoFileSuffix();
|
||||
static const char *HeaderSuffix();
|
||||
static const char *EnumClassSuffix();
|
||||
|
||||
static const std::unordered_map<::google::protobuf::FieldDescriptor::Type, std::string> &
|
||||
|
|
Loading…
Reference in New Issue