Skip to content

Commit 182164e

Browse files
committed
compiler: Add option to disable version output
If the option becomes popular, we can just remove the version.
1 parent ab65c79 commit 182164e

File tree

19 files changed

+31
-22
lines changed

19 files changed

+31
-22
lines changed

benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/BenchmarkServiceGrpc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
*/
2020
@javax.annotation.Generated(
21-
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)",
21+
value = "by gRPC proto compiler",
2222
comments = "Source: services.proto")
2323
public final class BenchmarkServiceGrpc {
2424

benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/ReportQpsScenarioServiceGrpc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
*/
2020
@javax.annotation.Generated(
21-
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)",
21+
value = "by gRPC proto compiler",
2222
comments = "Source: services.proto")
2323
public final class ReportQpsScenarioServiceGrpc {
2424

benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/WorkerServiceGrpc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
*/
2020
@javax.annotation.Generated(
21-
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)",
21+
value = "by gRPC proto compiler",
2222
comments = "Source: services.proto")
2323
public final class WorkerServiceGrpc {
2424

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ subprojects {
130130
// To generate deprecated interfaces and static bindService method,
131131
// turn the enable_deprecated option to true below:
132132
option 'enable_deprecated=false'
133+
option 'noversion'
133134
}
134135
}
135136
}

compiler/src/java_plugin/cpp/java_generator.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,14 +1023,16 @@ static void PrintService(const ServiceDescriptor* service,
10231023
std::map<string, string>* vars,
10241024
Printer* p,
10251025
ProtoFlavor flavor,
1026-
bool enable_deprecated) {
1026+
bool enable_deprecated,
1027+
bool disable_version) {
10271028
(*vars)["service_name"] = service->name();
10281029
(*vars)["file_name"] = service->file()->name();
10291030
(*vars)["service_class_name"] = ServiceClassName(service);
1031+
(*vars)["grpc_version"] = "";
10301032
#ifdef GRPC_VERSION
1033+
if (!disable_version) {
10311034
(*vars)["grpc_version"] = " (version " XSTR(GRPC_VERSION) ")";
1032-
#else
1033-
(*vars)["grpc_version"] = "";
1035+
}
10341036
#endif
10351037
// TODO(nmittler): Replace with WriteServiceDocComment once included by protobuf distro.
10361038
GrpcWriteServiceDocComment(p, service);
@@ -1168,7 +1170,8 @@ void PrintImports(Printer* p, bool generate_nano) {
11681170
void GenerateService(const ServiceDescriptor* service,
11691171
google::protobuf::io::ZeroCopyOutputStream* out,
11701172
ProtoFlavor flavor,
1171-
bool enable_deprecated) {
1173+
bool enable_deprecated,
1174+
bool disable_version) {
11721175
// All non-generated classes must be referred by fully qualified names to
11731176
// avoid collision with generated classes.
11741177
std::map<string, string> vars;
@@ -1212,7 +1215,7 @@ void GenerateService(const ServiceDescriptor* service,
12121215
if (!vars["Package"].empty()) {
12131216
vars["Package"].append(".");
12141217
}
1215-
PrintService(service, &vars, &printer, flavor, enable_deprecated);
1218+
PrintService(service, &vars, &printer, flavor, enable_deprecated, disable_version);
12161219
}
12171220

12181221
string ServiceJavaPackage(const FileDescriptor* file, bool nano) {

compiler/src/java_plugin/cpp/java_generator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ string ServiceClassName(const google::protobuf::ServiceDescriptor* service);
5050
void GenerateService(const google::protobuf::ServiceDescriptor* service,
5151
google::protobuf::io::ZeroCopyOutputStream* out,
5252
ProtoFlavor flavor,
53-
bool enable_deprecated);
53+
bool enable_deprecated,
54+
bool disable_version);
5455

5556
} // namespace java_grpc_generator
5657

compiler/src/java_plugin/cpp/java_plugin.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@ class JavaGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
3838
java_grpc_generator::ProtoFlavor::NORMAL;
3939

4040
bool enable_deprecated = false;
41+
bool disable_version = false;
4142
for (size_t i = 0; i < options.size(); i++) {
4243
if (options[i].first == "nano") {
4344
flavor = java_grpc_generator::ProtoFlavor::NANO;
4445
} else if (options[i].first == "lite") {
4546
flavor = java_grpc_generator::ProtoFlavor::LITE;
4647
} else if (options[i].first == "enable_deprecated") {
4748
enable_deprecated = options[i].second == "true";
49+
} else if (options[i].first == "noversion") {
50+
disable_version = true;
4851
}
4952
}
5053

@@ -57,7 +60,8 @@ class JavaGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
5760
+ java_grpc_generator::ServiceClassName(service) + ".java";
5861
std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output(
5962
context->Open(filename));
60-
java_grpc_generator::GenerateService(service, output.get(), flavor, enable_deprecated);
63+
java_grpc_generator::GenerateService(
64+
service, output.get(), flavor, enable_deprecated, disable_version);
6165
}
6266
return true;
6367
}

grpclb/src/generated/main/grpc/io/grpc/grpclb/LoadBalancerGrpc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
*/
2020
@javax.annotation.Generated(
21-
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)",
21+
value = "by gRPC proto compiler",
2222
comments = "Source: load_balancer.proto")
2323
public final class LoadBalancerGrpc {
2424

interop-testing/src/generated/main/grpc/io/grpc/testing/integration/MetricsServiceGrpc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
*/
2020
@javax.annotation.Generated(
21-
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)",
21+
value = "by gRPC proto compiler",
2222
comments = "Source: io/grpc/testing/integration/metrics.proto")
2323
public final class MetricsServiceGrpc {
2424

interop-testing/src/generated/main/grpc/io/grpc/testing/integration/ReconnectServiceGrpc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* </pre>
2222
*/
2323
@javax.annotation.Generated(
24-
value = "by gRPC proto compiler (version 1.7.0-SNAPSHOT)",
24+
value = "by gRPC proto compiler",
2525
comments = "Source: io/grpc/testing/integration/test.proto")
2626
public final class ReconnectServiceGrpc {
2727

0 commit comments

Comments
 (0)