summaryrefslogtreecommitdiff
path: root/grpc
diff options
context:
space:
mode:
authorAman Priyadarshi <aman.eureka@gmail.com>2022-08-07 19:32:53 +0100
committerGitHub <noreply@github.com>2022-08-07 11:32:53 -0700
commit468c00a3fec1c535f535eb34513935da2ae7f56b (patch)
treebc76d2603b9423496113bf341d7b4c156bea71fd /grpc
parent47c757f71470e1e80f8d7a66e165ccec13bfaa52 (diff)
downloadflatbuffers-468c00a3fec1c535f535eb34513935da2ae7f56b.tar.gz
flatbuffers-468c00a3fec1c535f535eb34513935da2ae7f56b.tar.bz2
flatbuffers-468c00a3fec1c535f535eb34513935da2ae7f56b.zip
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>
Diffstat (limited to 'grpc')
-rw-r--r--grpc/src/compiler/cpp_generator.cc16
-rw-r--r--grpc/src/compiler/cpp_generator.h2
-rw-r--r--grpc/src/compiler/schema_interface.h2
3 files changed, 9 insertions, 11 deletions
diff --git a/grpc/src/compiler/cpp_generator.cc b/grpc/src/compiler/cpp_generator.cc
index 59dcc66d..16e3373b 100644
--- a/grpc/src/compiler/cpp_generator.cc
+++ b/grpc/src/compiler/cpp_generator.cc
@@ -8,7 +8,6 @@
namespace grpc_cpp_generator {
namespace {
-grpc::string message_header_ext() { return "_generated.h"; }
grpc::string service_header_ext() { return ".grpc.fb.h"; }
template<class T> grpc::string as_string(T x) {
@@ -65,7 +64,7 @@ void PrintIncludes(grpc_generator::Printer *printer,
}
grpc::string GetHeaderPrologue(grpc_generator::File *file,
- const Parameters & /*params*/) {
+ const Parameters &params) {
grpc::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
@@ -75,7 +74,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"] = file->message_header_ext();
+ vars["message_header_ext"] = params.message_header_extension;
printer->Print(vars, "// Generated by the gRPC C++ plugin.\n");
printer->Print(vars,
@@ -1118,7 +1117,7 @@ grpc::string GetHeaderEpilogue(grpc_generator::File *file,
}
grpc::string GetSourcePrologue(grpc_generator::File *file,
- const Parameters & /*params*/) {
+ const Parameters &params) {
grpc::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
@@ -1127,8 +1126,8 @@ grpc::string GetSourcePrologue(grpc_generator::File *file,
vars["filename"] = file->filename();
vars["filename_base"] = file->filename_without_ext();
- vars["message_header_ext"] = file->message_header_ext();
- vars["service_header_ext"] = file->service_header_ext();
+ vars["message_header_ext"] = params.message_header_extension;
+ vars["service_header_ext"] = service_header_ext();
printer->Print(vars, "// Generated by the gRPC C++ plugin.\n");
printer->Print(vars,
@@ -1532,9 +1531,8 @@ grpc::string GetSourceEpilogue(grpc_generator::File *file,
return temp;
}
-// TODO(mmukhi): Make sure we need parameters or not.
grpc::string GetMockPrologue(grpc_generator::File *file,
- const Parameters & /*params*/) {
+ const Parameters &params) {
grpc::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
@@ -1543,7 +1541,7 @@ grpc::string GetMockPrologue(grpc_generator::File *file,
vars["filename"] = file->filename();
vars["filename_base"] = file->filename_without_ext();
- vars["message_header_ext"] = message_header_ext();
+ vars["message_header_ext"] = params.message_header_extension;
vars["service_header_ext"] = service_header_ext();
printer->Print(vars, "// Generated by the gRPC C++ plugin.\n");
diff --git a/grpc/src/compiler/cpp_generator.h b/grpc/src/compiler/cpp_generator.h
index 16aa97ac..a9af1a67 100644
--- a/grpc/src/compiler/cpp_generator.h
+++ b/grpc/src/compiler/cpp_generator.h
@@ -33,6 +33,8 @@ struct Parameters {
grpc::string grpc_search_path;
// Generate GMOCK code to facilitate unit testing.
bool generate_mock_code;
+ // By default, use "_generated.h"
+ std::string message_header_extension;
};
// Return the prologue of the generated header file.
diff --git a/grpc/src/compiler/schema_interface.h b/grpc/src/compiler/schema_interface.h
index e42e3e34..f89288d7 100644
--- a/grpc/src/compiler/schema_interface.h
+++ b/grpc/src/compiler/schema_interface.h
@@ -107,8 +107,6 @@ 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;