compiler: Add option to disable version output

If the option becomes popular, we can just remove the version.
This commit is contained in:
Eric Anderson 2016-06-16 13:54:12 -07:00
parent ab65c797bf
commit 182164eafc
19 changed files with 31 additions and 22 deletions

View File

@ -18,7 +18,7 @@ import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
/** /**
*/ */
@javax.annotation.Generated( @javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)", value = "by gRPC proto compiler",
comments = "Source: services.proto") comments = "Source: services.proto")
public final class BenchmarkServiceGrpc { public final class BenchmarkServiceGrpc {

View File

@ -18,7 +18,7 @@ import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
/** /**
*/ */
@javax.annotation.Generated( @javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)", value = "by gRPC proto compiler",
comments = "Source: services.proto") comments = "Source: services.proto")
public final class ReportQpsScenarioServiceGrpc { public final class ReportQpsScenarioServiceGrpc {

View File

@ -18,7 +18,7 @@ import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
/** /**
*/ */
@javax.annotation.Generated( @javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)", value = "by gRPC proto compiler",
comments = "Source: services.proto") comments = "Source: services.proto")
public final class WorkerServiceGrpc { public final class WorkerServiceGrpc {

View File

@ -130,6 +130,7 @@ subprojects {
// To generate deprecated interfaces and static bindService method, // To generate deprecated interfaces and static bindService method,
// turn the enable_deprecated option to true below: // turn the enable_deprecated option to true below:
option 'enable_deprecated=false' option 'enable_deprecated=false'
option 'noversion'
} }
} }
} }

View File

@ -1023,14 +1023,16 @@ static void PrintService(const ServiceDescriptor* service,
std::map<string, string>* vars, std::map<string, string>* vars,
Printer* p, Printer* p,
ProtoFlavor flavor, ProtoFlavor flavor,
bool enable_deprecated) { bool enable_deprecated,
bool disable_version) {
(*vars)["service_name"] = service->name(); (*vars)["service_name"] = service->name();
(*vars)["file_name"] = service->file()->name(); (*vars)["file_name"] = service->file()->name();
(*vars)["service_class_name"] = ServiceClassName(service); (*vars)["service_class_name"] = ServiceClassName(service);
(*vars)["grpc_version"] = "";
#ifdef GRPC_VERSION #ifdef GRPC_VERSION
if (!disable_version) {
(*vars)["grpc_version"] = " (version " XSTR(GRPC_VERSION) ")"; (*vars)["grpc_version"] = " (version " XSTR(GRPC_VERSION) ")";
#else }
(*vars)["grpc_version"] = "";
#endif #endif
// TODO(nmittler): Replace with WriteServiceDocComment once included by protobuf distro. // TODO(nmittler): Replace with WriteServiceDocComment once included by protobuf distro.
GrpcWriteServiceDocComment(p, service); GrpcWriteServiceDocComment(p, service);
@ -1168,7 +1170,8 @@ void PrintImports(Printer* p, bool generate_nano) {
void GenerateService(const ServiceDescriptor* service, void GenerateService(const ServiceDescriptor* service,
google::protobuf::io::ZeroCopyOutputStream* out, google::protobuf::io::ZeroCopyOutputStream* out,
ProtoFlavor flavor, ProtoFlavor flavor,
bool enable_deprecated) { bool enable_deprecated,
bool disable_version) {
// All non-generated classes must be referred by fully qualified names to // All non-generated classes must be referred by fully qualified names to
// avoid collision with generated classes. // avoid collision with generated classes.
std::map<string, string> vars; std::map<string, string> vars;
@ -1212,7 +1215,7 @@ void GenerateService(const ServiceDescriptor* service,
if (!vars["Package"].empty()) { if (!vars["Package"].empty()) {
vars["Package"].append("."); vars["Package"].append(".");
} }
PrintService(service, &vars, &printer, flavor, enable_deprecated); PrintService(service, &vars, &printer, flavor, enable_deprecated, disable_version);
} }
string ServiceJavaPackage(const FileDescriptor* file, bool nano) { string ServiceJavaPackage(const FileDescriptor* file, bool nano) {

View File

@ -50,7 +50,8 @@ string ServiceClassName(const google::protobuf::ServiceDescriptor* service);
void GenerateService(const google::protobuf::ServiceDescriptor* service, void GenerateService(const google::protobuf::ServiceDescriptor* service,
google::protobuf::io::ZeroCopyOutputStream* out, google::protobuf::io::ZeroCopyOutputStream* out,
ProtoFlavor flavor, ProtoFlavor flavor,
bool enable_deprecated); bool enable_deprecated,
bool disable_version);
} // namespace java_grpc_generator } // namespace java_grpc_generator

View File

@ -38,6 +38,7 @@ class JavaGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
java_grpc_generator::ProtoFlavor::NORMAL; java_grpc_generator::ProtoFlavor::NORMAL;
bool enable_deprecated = false; bool enable_deprecated = false;
bool disable_version = false;
for (size_t i = 0; i < options.size(); i++) { for (size_t i = 0; i < options.size(); i++) {
if (options[i].first == "nano") { if (options[i].first == "nano") {
flavor = java_grpc_generator::ProtoFlavor::NANO; flavor = java_grpc_generator::ProtoFlavor::NANO;
@ -45,6 +46,8 @@ class JavaGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
flavor = java_grpc_generator::ProtoFlavor::LITE; flavor = java_grpc_generator::ProtoFlavor::LITE;
} else if (options[i].first == "enable_deprecated") { } else if (options[i].first == "enable_deprecated") {
enable_deprecated = options[i].second == "true"; enable_deprecated = options[i].second == "true";
} else if (options[i].first == "noversion") {
disable_version = true;
} }
} }
@ -57,7 +60,8 @@ class JavaGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
+ java_grpc_generator::ServiceClassName(service) + ".java"; + java_grpc_generator::ServiceClassName(service) + ".java";
std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output( std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output(
context->Open(filename)); context->Open(filename));
java_grpc_generator::GenerateService(service, output.get(), flavor, enable_deprecated); java_grpc_generator::GenerateService(
service, output.get(), flavor, enable_deprecated, disable_version);
} }
return true; return true;
} }

View File

@ -18,7 +18,7 @@ import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
/** /**
*/ */
@javax.annotation.Generated( @javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)", value = "by gRPC proto compiler",
comments = "Source: load_balancer.proto") comments = "Source: load_balancer.proto")
public final class LoadBalancerGrpc { public final class LoadBalancerGrpc {

View File

@ -18,7 +18,7 @@ import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
/** /**
*/ */
@javax.annotation.Generated( @javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)", value = "by gRPC proto compiler",
comments = "Source: io/grpc/testing/integration/metrics.proto") comments = "Source: io/grpc/testing/integration/metrics.proto")
public final class MetricsServiceGrpc { public final class MetricsServiceGrpc {

View File

@ -21,7 +21,7 @@ import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
* </pre> * </pre>
*/ */
@javax.annotation.Generated( @javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)", value = "by gRPC proto compiler",
comments = "Source: io/grpc/testing/integration/test.proto") comments = "Source: io/grpc/testing/integration/test.proto")
public final class ReconnectServiceGrpc { public final class ReconnectServiceGrpc {

View File

@ -22,7 +22,7 @@ import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
* </pre> * </pre>
*/ */
@javax.annotation.Generated( @javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)", value = "by gRPC proto compiler",
comments = "Source: io/grpc/testing/integration/test.proto") comments = "Source: io/grpc/testing/integration/test.proto")
public final class TestServiceGrpc { public final class TestServiceGrpc {

View File

@ -22,7 +22,7 @@ import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
* </pre> * </pre>
*/ */
@javax.annotation.Generated( @javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)", value = "by gRPC proto compiler",
comments = "Source: io/grpc/testing/integration/test.proto") comments = "Source: io/grpc/testing/integration/test.proto")
public final class UnimplementedServiceGrpc { public final class UnimplementedServiceGrpc {

View File

@ -18,7 +18,7 @@ import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
/** /**
*/ */
@javax.annotation.Generated( @javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)", value = "by gRPC proto compiler",
comments = "Source: health.proto") comments = "Source: health.proto")
public final class HealthGrpc { public final class HealthGrpc {

View File

@ -18,7 +18,7 @@ import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
/** /**
*/ */
@javax.annotation.Generated( @javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)", value = "by gRPC proto compiler",
comments = "Source: grpc/instrumentation/v1alpha/monitoring.proto") comments = "Source: grpc/instrumentation/v1alpha/monitoring.proto")
public final class MonitoringGrpc { public final class MonitoringGrpc {

View File

@ -18,7 +18,7 @@ import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
/** /**
*/ */
@javax.annotation.Generated( @javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)", value = "by gRPC proto compiler",
comments = "Source: io/grpc/reflection/v1alpha/reflection.proto") comments = "Source: io/grpc/reflection/v1alpha/reflection.proto")
public final class ServerReflectionGrpc { public final class ServerReflectionGrpc {

View File

@ -21,7 +21,7 @@ import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
* </pre> * </pre>
*/ */
@javax.annotation.Generated( @javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)", value = "by gRPC proto compiler",
comments = "Source: io/grpc/reflection/testing/dynamic_reflection_test.proto") comments = "Source: io/grpc/reflection/testing/dynamic_reflection_test.proto")
public final class AnotherDynamicServiceGrpc { public final class AnotherDynamicServiceGrpc {

View File

@ -21,7 +21,7 @@ import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
* </pre> * </pre>
*/ */
@javax.annotation.Generated( @javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)", value = "by gRPC proto compiler",
comments = "Source: io/grpc/reflection/testing/dynamic_reflection_test.proto") comments = "Source: io/grpc/reflection/testing/dynamic_reflection_test.proto")
public final class DynamicServiceGrpc { public final class DynamicServiceGrpc {

View File

@ -18,7 +18,7 @@ import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
/** /**
*/ */
@javax.annotation.Generated( @javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)", value = "by gRPC proto compiler",
comments = "Source: io/grpc/reflection/testing/reflection_test.proto") comments = "Source: io/grpc/reflection/testing/reflection_test.proto")
public final class ReflectableServiceGrpc { public final class ReflectableServiceGrpc {

View File

@ -21,7 +21,7 @@ import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
* </pre> * </pre>
*/ */
@javax.annotation.Generated( @javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)", value = "by gRPC proto compiler",
comments = "Source: io/grpc/testing/protobuf/simpleservice.proto") comments = "Source: io/grpc/testing/protobuf/simpleservice.proto")
public final class SimpleServiceGrpc { public final class SimpleServiceGrpc {