only generate full or lite client, never both

pull/18705/head
Jan Tattermusch 6 years ago
parent 25e3d26e8c
commit 1b8418b546
  1. 38
      src/compiler/csharp_generator.cc
  2. 4
      src/compiler/csharp_generator.h
  3. 12
      src/compiler/csharp_plugin.cc

@ -176,9 +176,8 @@ std::string GetServiceClassName(const ServiceDescriptor* service) {
return service->name();
}
std::string GetClientClassName(const ServiceDescriptor* service,
bool lite_client) {
return service->name() + (lite_client ? "LiteClient" : "Client");
std::string GetClientClassName(const ServiceDescriptor* service) {
return service->name() + "Client";
}
std::string GetServerClassName(const ServiceDescriptor* service) {
@ -421,12 +420,12 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor* service,
out->Print("/// <summary>Client for $servicename$</summary>\n",
"servicename", GetServiceClassName(service));
out->Print("public partial class $name$ : grpc::ClientBase<$name$>\n",
"name", GetClientClassName(service, lite_client));
"name", GetClientClassName(service));
} else {
out->Print("/// <summary>Lite client for $servicename$</summary>\n",
"servicename", GetServiceClassName(service));
out->Print("public partial class $name$ : grpc::LiteClientBase\n", "name",
GetClientClassName(service, lite_client));
GetClientClassName(service));
}
out->Print("{\n");
out->Indent();
@ -439,7 +438,7 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor* service,
"calls.</param>\n",
"servicename", GetServiceClassName(service));
out->Print("public $name$(grpc::Channel channel) : base(channel)\n", "name",
GetClientClassName(service, lite_client));
GetClientClassName(service));
out->Print("{\n");
out->Print("}\n");
}
@ -451,14 +450,14 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor* service,
"servicename", GetServiceClassName(service));
out->Print(
"public $name$(grpc::CallInvoker callInvoker) : base(callInvoker)\n",
"name", GetClientClassName(service, lite_client));
"name", GetClientClassName(service));
out->Print("{\n");
out->Print("}\n");
out->Print(
"/// <summary>Protected parameterless constructor to allow creation"
" of test doubles.</summary>\n");
out->Print("protected $name$() : base()\n", "name",
GetClientClassName(service, lite_client));
GetClientClassName(service));
out->Print("{\n");
out->Print("}\n");
if (!lite_client) {
@ -470,7 +469,7 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor* service,
out->Print(
"protected $name$(ClientBaseConfiguration configuration)"
" : base(configuration)\n",
"name", GetClientClassName(service, lite_client));
"name", GetClientClassName(service));
out->Print("{\n");
out->Print("}\n");
}
@ -599,11 +598,11 @@ void GenerateClientStub(Printer* out, const ServiceDescriptor* service,
out->Print(
"protected override $name$ NewInstance(ClientBaseConfiguration "
"configuration)\n",
"name", GetClientClassName(service, lite_client));
"name", GetClientClassName(service));
out->Print("{\n");
out->Indent();
out->Print("return new $name$(configuration);\n", "name",
GetClientClassName(service, lite_client));
GetClientClassName(service));
out->Outdent();
out->Print("}\n");
}
@ -687,8 +686,8 @@ void GenerateBindServiceWithBinderMethod(Printer* out,
}
void GenerateService(Printer* out, const ServiceDescriptor* service,
bool generate_client, bool generate_lite_client,
bool generate_server, bool internal_access) {
bool generate_client, bool generate_server,
bool internal_access, bool lite_client) {
GenerateDocCommentBody(out, service);
out->Print("$access_level$ static partial class $classname$\n",
"access_level", GetAccessLevel(internal_access), "classname",
@ -710,10 +709,7 @@ void GenerateService(Printer* out, const ServiceDescriptor* service,
GenerateServerClass(out, service);
}
if (generate_client) {
GenerateClientStub(out, service, false);
}
if (generate_lite_client) {
GenerateClientStub(out, service, true);
GenerateClientStub(out, service, lite_client);
}
if (generate_server) {
@ -728,8 +724,8 @@ void GenerateService(Printer* out, const ServiceDescriptor* service,
} // anonymous namespace
grpc::string GetServices(const FileDescriptor* file, bool generate_client,
bool generate_lite_client, bool generate_server,
bool internal_access) {
bool generate_server, bool internal_access,
bool lite_client) {
grpc::string output;
{
// Scope the output stream so it closes and finalizes output to the string.
@ -770,8 +766,8 @@ grpc::string GetServices(const FileDescriptor* file, bool generate_client,
out.Indent();
}
for (int i = 0; i < file->service_count(); i++) {
GenerateService(&out, file->service(i), generate_client,
generate_lite_client, generate_server, internal_access);
GenerateService(&out, file->service(i), generate_client, generate_server,
internal_access, lite_client);
}
if (file_namespace != "") {
out.Outdent();

@ -26,8 +26,8 @@
namespace grpc_csharp_generator {
grpc::string GetServices(const grpc::protobuf::FileDescriptor* file,
bool generate_client, bool generate_lite_client,
bool generate_server, bool internal_access);
bool generate_client, bool generate_server,
bool internal_access, bool lite_client);
} // namespace grpc_csharp_generator

@ -38,18 +38,19 @@ class CSharpGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
bool generate_client = true;
bool generate_server = true;
bool generate_lite_client = true;
bool internal_access = false;
bool lite_client = false;
for (size_t i = 0; i < options.size(); i++) {
if (options[i].first == "no_client") {
generate_client = false;
} else if (options[i].first == "no_lite_client") {
// TODO: better option
generate_lite_client = false;
} else if (options[i].first == "no_server") {
generate_server = false;
} else if (options[i].first == "internal_access") {
internal_access = true;
} else if (options[i].first == "lite_client") {
// will only be used if generate_client is true.
// NOTE: experimental option, can be removed in future release
lite_client = true;
} else {
*error = "Unknown generator option: " + options[i].first;
return false;
@ -57,8 +58,7 @@ class CSharpGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
}
grpc::string code = grpc_csharp_generator::GetServices(
file, generate_client, generate_lite_client, generate_server,
internal_access);
file, generate_client, generate_server, internal_access, lite_client);
if (code.size() == 0) {
return true; // don't generate a file if there are no services
}

Loading…
Cancel
Save