From 98ccb7fd947bd26c53902b7b5d62b19a0303d1f9 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 12 May 2021 15:17:45 +0200 Subject: [PATCH] Add C# plugin "file_suffix" option defaulting to "Grpc.cs" (#26162) * add C# plugin "file_extension" option defaulting to "Grpc.cs" * rename to "file_suffix" to avoid confusion * address review feedback --- src/compiler/csharp_generator_helpers.h | 7 ++++--- src/compiler/csharp_plugin.cc | 9 ++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/compiler/csharp_generator_helpers.h b/src/compiler/csharp_generator_helpers.h index c269431544c..466c645859a 100644 --- a/src/compiler/csharp_generator_helpers.h +++ b/src/compiler/csharp_generator_helpers.h @@ -25,9 +25,10 @@ namespace grpc_csharp_generator { inline bool ServicesFilename(const grpc::protobuf::FileDescriptor* file, - std::string* file_name_or_error) { - *file_name_or_error = - grpc_generator::FileNameInUpperCamel(file, false) + "Grpc.cs"; + const std::string& file_suffix, + std::string& out_file_name_or_error) { + out_file_name_or_error = + grpc_generator::FileNameInUpperCamel(file, false) + file_suffix; return true; } diff --git a/src/compiler/csharp_plugin.cc b/src/compiler/csharp_plugin.cc index cac50d28dc5..dcf800acd41 100644 --- a/src/compiler/csharp_plugin.cc +++ b/src/compiler/csharp_plugin.cc @@ -43,6 +43,9 @@ class CSharpGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { bool generate_client = true; bool generate_server = true; bool internal_access = false; + // the suffix that will get appended to the name generated from the name + // of the original .proto file + std::string file_suffix = "Grpc.cs"; for (size_t i = 0; i < options.size(); i++) { if (options[i].first == "no_client") { generate_client = false; @@ -50,6 +53,9 @@ class CSharpGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { generate_server = false; } else if (options[i].first == "internal_access") { internal_access = true; + } + if (options[i].first == "file_suffix") { + file_suffix = options[i].second; } else { *error = "Unknown generator option: " + options[i].first; return false; @@ -64,7 +70,8 @@ class CSharpGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { // Get output file name. std::string file_name; - if (!grpc_csharp_generator::ServicesFilename(file, &file_name)) { + if (!grpc_csharp_generator::ServicesFilename(file, file_suffix, + file_name)) { return false; } std::unique_ptr output(