mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-04 04:33:23 +00:00
Rebased: grpc/compiler: Respect filename suffix and extension during code generation (#7414)
* grpc/compiler: Respect filename suffix and extension during code generation grpc compiler is not respecting filename suffix and extension passed to flatc CLI. This causes compiler to spit out incorrect code, which then cannot be compiled without modification. Following patch fixes the problem. Note, I ended up removing some code introduced #6954 ("Have grpc include file with correct filename-suffix given to flatc") in favour of keeping sanity of the generator code. Signed-off-by: Aman Priyadarshi <aman.eureka@gmail.com> * tests: Add filename-suffix and filename-ext test files * Test 1: Filename extension changed to "hpp". * Test 2: Filename suffix changed to "_suffix". * Test 3: Filename extension changed to "hpp" and suffix changed to "_suffix" Signed-off-by: Aman Priyadarshi <aman.eureka@gmail.com>
This commit is contained in:
@@ -242,12 +242,6 @@ class FlatBufFile : public grpc_generator::File {
|
||||
return StripExtension(file_name_);
|
||||
}
|
||||
|
||||
std::string message_header_ext() const {
|
||||
return parser_.opts.filename_suffix + ".h";
|
||||
}
|
||||
|
||||
std::string service_header_ext() const { return ".grpc.fb.h"; }
|
||||
|
||||
std::string package() const {
|
||||
return parser_.current_namespace_->GetFullyQualifiedName("");
|
||||
}
|
||||
@@ -347,6 +341,7 @@ bool GenerateGoGRPC(const Parser &parser, const std::string &path,
|
||||
|
||||
bool GenerateCppGRPC(const Parser &parser, const std::string &path,
|
||||
const std::string &file_name) {
|
||||
const auto &opts = parser.opts;
|
||||
int nservices = 0;
|
||||
for (auto it = parser.services_.vec.begin(); it != parser.services_.vec.end();
|
||||
++it) {
|
||||
@@ -354,9 +349,15 @@ bool GenerateCppGRPC(const Parser &parser, const std::string &path,
|
||||
}
|
||||
if (!nservices) return true;
|
||||
|
||||
std::string suffix = "";
|
||||
suffix += opts.filename_suffix.empty() ? "_generated" : opts.filename_suffix;
|
||||
suffix += ".";
|
||||
suffix += opts.filename_extension.empty() ? "h" : opts.filename_extension;
|
||||
|
||||
grpc_cpp_generator::Parameters generator_parameters;
|
||||
// TODO(wvo): make the other parameters in this struct configurable.
|
||||
generator_parameters.use_system_headers = true;
|
||||
generator_parameters.message_header_extension = suffix;
|
||||
|
||||
FlatBufFile fbfile(parser, file_name, FlatBufFile::kLanguageCpp);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user