Have grpc include file with correct filename-suffix given to flatc (#6954)

When generating code with --grpc,  --cpp and using filename-suffix, the generated grpc files where not including the correct header that had the filename-suffix. As a suffix, they used the default "_generated".
Free functions for these were used to get the suffix. FlatBufFile had such methods, but also needed to be into its base File and use these.
- grpc generated files include the correct message header.
- grpc generated files also have the suffix
- grpc generated cc file does not include initial message header
This commit is contained in:
Panagiotis Gourgaris
2021-12-02 19:49:12 +02:00
committed by GitHub
parent e47dc0e465
commit fadd40e402
3 changed files with 18 additions and 10 deletions

View File

@@ -114,7 +114,7 @@ grpc::string GetHeaderPrologue(grpc_generator::File *file,
vars["filename"] = file->filename();
vars["filename_identifier"] = FilenameIdentifier(file->filename());
vars["filename_base"] = file->filename_without_ext();
vars["message_header_ext"] = message_header_ext();
vars["message_header_ext"] = file->message_header_ext();
printer->Print(vars, "// Generated by the gRPC C++ plugin.\n");
printer->Print(vars,
@@ -1155,15 +1155,13 @@ grpc::string GetSourcePrologue(grpc_generator::File *file,
vars["filename"] = file->filename();
vars["filename_base"] = file->filename_without_ext();
vars["message_header_ext"] = message_header_ext();
vars["service_header_ext"] = service_header_ext();
vars["service_header_ext"] = file->service_header_ext();
printer->Print(vars, "// Generated by the gRPC C++ plugin.\n");
printer->Print(vars,
"// If you make any local change, they will be lost.\n");
printer->Print(vars, "// source: $filename$\n\n");
printer->Print(vars, "#include \"$filename_base$$message_header_ext$\"\n");
printer->Print(vars, "#include \"$filename_base$$service_header_ext$\"\n");
printer->Print(vars, "\n");
}

View File

@@ -108,6 +108,8 @@ struct File : public CommentHolder {
virtual grpc::string package() const = 0;
virtual std::vector<grpc::string> package_parts() const = 0;
virtual grpc::string additional_headers() const = 0;
virtual std::string message_header_ext() const = 0;
virtual std::string service_header_ext() const = 0;
virtual int service_count() const = 0;
virtual std::unique_ptr<const Service> service(int i) const = 0;

View File

@@ -242,9 +242,13 @@ class FlatBufFile : public grpc_generator::File {
return StripExtension(file_name_);
}
std::string message_header_ext() const { return "_generated.h"; }
std::string message_header_ext() const {
return parser_.opts.filename_suffix + ".h";
}
std::string service_header_ext() const { return ".grpc.fb.h"; }
std::string service_header_ext() const {
return parser_.opts.filename_suffix + ".grpc.fb.h";
}
std::string package() const {
return parser_.current_namespace_->GetFullyQualifiedName("");
@@ -370,10 +374,14 @@ bool GenerateCppGRPC(const Parser &parser, const std::string &path,
grpc_cpp_generator::GetSourceServices(&fbfile, generator_parameters) +
grpc_cpp_generator::GetSourceEpilogue(&fbfile, generator_parameters);
return flatbuffers::SaveFile((path + file_name + ".grpc.fb.h").c_str(),
header_code, false) &&
flatbuffers::SaveFile((path + file_name + ".grpc.fb.cc").c_str(),
source_code, false);
return flatbuffers::SaveFile(
(path + file_name + parser.opts.filename_suffix + ".grpc.fb.h")
.c_str(),
header_code, false) &&
flatbuffers::SaveFile(
(path + file_name + parser.opts.filename_suffix + ".grpc.fb.cc")
.c_str(),
source_code, false);
}
class JavaGRPCGenerator : public flatbuffers::BaseGenerator {