Skip to content

Commit 363e0f6

Browse files
lukaszx0ejona86
authored andcommitted
Print compiler version number in generated files
1 parent 511bea0 commit 363e0f6

File tree

13 files changed

+28
-12
lines changed

13 files changed

+28
-12
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
@@ -16,7 +16,7 @@
1616
import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
1717

1818
@javax.annotation.Generated(
19-
value = "by gRPC proto compiler",
19+
value = "by gRPC proto compiler (version 0.14.0-SNAPSHOT)",
2020
comments = "Source: services.proto")
2121
public class BenchmarkServiceGrpc {
2222

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
@@ -16,7 +16,7 @@
1616
import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
1717

1818
@javax.annotation.Generated(
19-
value = "by gRPC proto compiler",
19+
value = "by gRPC proto compiler (version 0.14.0-SNAPSHOT)",
2020
comments = "Source: services.proto")
2121
public class WorkerServiceGrpc {
2222

compiler/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ model {
7575
binaries {
7676
all {
7777
if (toolChain in Gcc || toolChain in Clang) {
78+
cppCompiler.define("GRPC_VERSION", version)
7879
cppCompiler.args "--std=c++0x"
7980
addEnvArgs("CXXFLAGS", cppCompiler.args)
8081
addEnvArgs("CPPFLAGS", cppCompiler.args)
@@ -95,6 +96,7 @@ model {
9596
}
9697
addEnvArgs("LDFLAGS", linker.args)
9798
} else if (toolChain in VisualCpp) {
99+
cppCompiler.define("GRPC_VERSION", version)
98100
cppCompiler.args "/EHsc", "/MT"
99101
if (rootProject.hasProperty('vcProtobufInclude')) {
100102
cppCompiler.args "/I${rootProject.vcProtobufInclude}"

compiler/src/java_plugin/cpp/java_generator.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
#include <google/protobuf/io/printer.h>
1010
#include <google/protobuf/io/zero_copy_stream.h>
1111

12+
// Stringify helpers used solely to cast GRPC_VERSION
13+
#ifndef STR
14+
#define STR(s) #s
15+
#endif
16+
17+
#ifndef XSTR
18+
#define XSTR(s) STR(s)
19+
#endif
20+
1221
namespace java_grpc_generator {
1322

1423
using google::protobuf::FileDescriptor;
@@ -698,10 +707,15 @@ static void PrintService(const ServiceDescriptor* service,
698707
(*vars)["service_name"] = service->name();
699708
(*vars)["file_name"] = service->file()->name();
700709
(*vars)["service_class_name"] = ServiceClassName(service);
710+
#ifdef GRPC_VERSION
711+
(*vars)["grpc_version"] = " (version " XSTR(GRPC_VERSION) ")";
712+
#else
713+
(*vars)["grpc_version"] = "";
714+
#endif
701715
p->Print(
702716
*vars,
703717
"@$Generated$(\n"
704-
" value = \"by gRPC proto compiler\",\n"
718+
" value = \"by gRPC proto compiler$grpc_version$\",\n"
705719
" comments = \"Source: $file_name$\")\n"
706720
"public class $service_class_name$ {\n\n");
707721
p->Indent();

compiler/src/test/golden/TestService.java.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
1616
import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
1717

1818
@javax.annotation.Generated(
19-
value = "by gRPC proto compiler",
19+
value = "by gRPC proto compiler (version 0.14.0-SNAPSHOT)",
2020
comments = "Source: test.proto")
2121
public class TestServiceGrpc {
2222

compiler/src/testLite/golden/TestService.java.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
1616
import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
1717

1818
@javax.annotation.Generated(
19-
value = "by gRPC proto compiler",
19+
value = "by gRPC proto compiler (version 0.14.0-SNAPSHOT)",
2020
comments = "Source: test.proto")
2121
public class TestServiceGrpc {
2222

compiler/src/testNano/golden/TestService.java.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
1818
import java.io.IOException;
1919

2020
@javax.annotation.Generated(
21-
value = "by gRPC proto compiler",
21+
value = "by gRPC proto compiler (version 0.14.0-SNAPSHOT)",
2222
comments = "Source: test.proto")
2323
public class TestServiceGrpc {
2424

examples/src/generated/main/grpc/io/grpc/examples/helloworld/GreeterGrpc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
1717

1818
@javax.annotation.Generated(
19-
value = "by gRPC proto compiler",
19+
value = "by gRPC proto compiler (version 0.14.0-SNAPSHOT)",
2020
comments = "Source: helloworld.proto")
2121
public class GreeterGrpc {
2222

examples/src/generated/main/grpc/io/grpc/examples/routeguide/RouteGuideGrpc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
1717

1818
@javax.annotation.Generated(
19-
value = "by gRPC proto compiler",
19+
value = "by gRPC proto compiler (version 0.14.0-SNAPSHOT)",
2020
comments = "Source: route_guide.proto")
2121
public class RouteGuideGrpc {
2222

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
1717

1818
@javax.annotation.Generated(
19-
value = "by gRPC proto compiler",
19+
value = "by gRPC proto compiler (version 0.14.0-SNAPSHOT)",
2020
comments = "Source: load_balancer.proto")
2121
public class LoadBalancerGrpc {
2222

0 commit comments

Comments
 (0)