From b22bcdfd18039c6b1bdfe6ae3e2541381acfb595 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Tue, 29 Mar 2016 14:13:28 -0700 Subject: [PATCH] Use lite argument in codegen instead of LITE_RUNTIME This allows using the same proto file for both client and server without forcing the server to use lite. --- compiler/build.gradle | 25 +-- compiler/src/java_plugin/cpp/java_plugin.cpp | 6 +- .../golden/TestService.java.txt} | 150 +++++++++--------- .../proto/test.proto} | 4 +- .../golden/TestService.java.txt} | 0 5 files changed, 95 insertions(+), 90 deletions(-) rename compiler/src/{test/golden/TestServiceLite.java.txt => testLite/golden/TestService.java.txt} (65%) rename compiler/src/{test/proto/test_lite.proto => testLite/proto/test.proto} (95%) rename compiler/src/{test/golden/TestServiceNano.java.txt => testNano/golden/TestService.java.txt} (100%) diff --git a/compiler/build.gradle b/compiler/build.gradle index 740bf4b1e4..b9e41732a2 100644 --- a/compiler/build.gradle +++ b/compiler/build.gradle @@ -109,17 +109,21 @@ model { } configurations { + testLiteCompile testNanoCompile } dependencies { testCompile project(':grpc-protobuf'), project(':grpc-stub') + testLiteCompile project(':grpc-protobuf-lite'), + project(':grpc-stub') testNanoCompile project(':grpc-protobuf-nano'), project(':grpc-stub') } sourceSets { + testLite {} testNano { proto { setSrcDirs(['src/test/proto']) @@ -127,7 +131,7 @@ sourceSets { } } -compileTestJava { +compileTestLiteJava { // Protobuf-generated Lite produces quite a few warnings. it.options.compilerArgs.removeAll(["-Xlint:unchecked", "-Xlint:rawtypes"]) } @@ -150,6 +154,11 @@ protobuf { ofSourceSet('test')*.plugins { grpc {} } + ofSourceSet('testLite')*.plugins { + grpc { + option 'lite' + } + } ofSourceSet('testNano').each { task -> task.builtins { remove java @@ -228,10 +237,8 @@ artifacts { } } -test.dependsOn('testGolden', 'testLiteGolden', 'testNanoGolden') - -def configureTestTask(Task task, String suffix, String dep, - String extraPackage) { +def configureTestTask(Task task, String dep, String extraPackage) { + test.dependsOn task task.dependsOn "generateTest${dep}Proto" if (osdetector.os != 'windows') { task.executable "diff" @@ -241,12 +248,12 @@ def configureTestTask(Task task, String suffix, String dep, // File isn't found on Windows if last slash is forward-slash def slash = System.getProperty("file.separator") task.args "$buildDir/generated/source/proto/test${dep}/grpc/io/grpc/testing/integration${extraPackage}${slash}TestServiceGrpc.java", - "$projectDir/src/test/golden/TestService${suffix}.java.txt" + "$projectDir/src/test${dep}/golden/TestService.java.txt" } task testGolden(type: Exec) task testLiteGolden(type: Exec) task testNanoGolden(type: Exec) -configureTestTask(testGolden, '', '', '') -configureTestTask(testLiteGolden, 'Lite', '', '/lite') -configureTestTask(testNanoGolden, 'Nano', 'Nano', '/nano') +configureTestTask(testGolden, '', '') +configureTestTask(testLiteGolden, 'Lite', '') +configureTestTask(testNanoGolden, 'Nano', '/nano') diff --git a/compiler/src/java_plugin/cpp/java_plugin.cpp b/compiler/src/java_plugin/cpp/java_plugin.cpp index 1c95497ba6..eb4a456dc4 100644 --- a/compiler/src/java_plugin/cpp/java_plugin.cpp +++ b/compiler/src/java_plugin/cpp/java_plugin.cpp @@ -37,13 +37,11 @@ class JavaGrpcGenerator : public google::protobuf::compiler::CodeGenerator { java_grpc_generator::ProtoFlavor flavor = java_grpc_generator::ProtoFlavor::NORMAL; - if (file->options().optimize_for() == - google::protobuf::FileOptions::LITE_RUNTIME) { - flavor = java_grpc_generator::ProtoFlavor::LITE; - } for (int i = 0; i < options.size(); i++) { if (options[i].first == "nano" && options[i].second == "true") { flavor = java_grpc_generator::ProtoFlavor::NANO; + } else if (options[i].first == "lite") { + flavor = java_grpc_generator::ProtoFlavor::LITE; } } diff --git a/compiler/src/test/golden/TestServiceLite.java.txt b/compiler/src/testLite/golden/TestService.java.txt similarity index 65% rename from compiler/src/test/golden/TestServiceLite.java.txt rename to compiler/src/testLite/golden/TestService.java.txt index 86da7e77e0..c46ee56fd1 100644 --- a/compiler/src/test/golden/TestServiceLite.java.txt +++ b/compiler/src/testLite/golden/TestService.java.txt @@ -1,4 +1,4 @@ -package io.grpc.testing.integration.lite; +package io.grpc.testing.integration; import static io.grpc.stub.ClientCalls.asyncUnaryCall; import static io.grpc.stub.ClientCalls.asyncServerStreamingCall; @@ -15,59 +15,59 @@ import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall; @javax.annotation.Generated( value = "by gRPC proto compiler", - comments = "Source: test_lite.proto") + comments = "Source: test.proto") public class TestServiceGrpc { private TestServiceGrpc() {} - public static final String SERVICE_NAME = "grpc.testing.lite.TestService"; + public static final String SERVICE_NAME = "grpc.testing.TestService"; // Static method descriptors that strictly reflect the proto. @io.grpc.ExperimentalApi - public static final io.grpc.MethodDescriptor METHOD_UNARY_CALL = + public static final io.grpc.MethodDescriptor METHOD_UNARY_CALL = io.grpc.MethodDescriptor.create( io.grpc.MethodDescriptor.MethodType.UNARY, generateFullMethodName( - "grpc.testing.lite.TestService", "UnaryCall"), - io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(io.grpc.testing.integration.lite.TestLite.SimpleRequest.getDefaultInstance()), - io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(io.grpc.testing.integration.lite.TestLite.SimpleResponse.getDefaultInstance())); + "grpc.testing.TestService", "UnaryCall"), + io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(io.grpc.testing.integration.Test.SimpleRequest.getDefaultInstance()), + io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(io.grpc.testing.integration.Test.SimpleResponse.getDefaultInstance())); @io.grpc.ExperimentalApi - public static final io.grpc.MethodDescriptor METHOD_STREAMING_OUTPUT_CALL = + public static final io.grpc.MethodDescriptor METHOD_STREAMING_OUTPUT_CALL = io.grpc.MethodDescriptor.create( io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING, generateFullMethodName( - "grpc.testing.lite.TestService", "StreamingOutputCall"), - io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(io.grpc.testing.integration.lite.TestLite.StreamingOutputCallRequest.getDefaultInstance()), - io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(io.grpc.testing.integration.lite.TestLite.StreamingOutputCallResponse.getDefaultInstance())); + "grpc.testing.TestService", "StreamingOutputCall"), + io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(io.grpc.testing.integration.Test.StreamingOutputCallRequest.getDefaultInstance()), + io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(io.grpc.testing.integration.Test.StreamingOutputCallResponse.getDefaultInstance())); @io.grpc.ExperimentalApi - public static final io.grpc.MethodDescriptor METHOD_STREAMING_INPUT_CALL = + public static final io.grpc.MethodDescriptor METHOD_STREAMING_INPUT_CALL = io.grpc.MethodDescriptor.create( io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING, generateFullMethodName( - "grpc.testing.lite.TestService", "StreamingInputCall"), - io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(io.grpc.testing.integration.lite.TestLite.StreamingInputCallRequest.getDefaultInstance()), - io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(io.grpc.testing.integration.lite.TestLite.StreamingInputCallResponse.getDefaultInstance())); + "grpc.testing.TestService", "StreamingInputCall"), + io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(io.grpc.testing.integration.Test.StreamingInputCallRequest.getDefaultInstance()), + io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(io.grpc.testing.integration.Test.StreamingInputCallResponse.getDefaultInstance())); @io.grpc.ExperimentalApi - public static final io.grpc.MethodDescriptor METHOD_FULL_BIDI_CALL = + public static final io.grpc.MethodDescriptor METHOD_FULL_BIDI_CALL = io.grpc.MethodDescriptor.create( io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING, generateFullMethodName( - "grpc.testing.lite.TestService", "FullBidiCall"), - io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(io.grpc.testing.integration.lite.TestLite.StreamingOutputCallRequest.getDefaultInstance()), - io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(io.grpc.testing.integration.lite.TestLite.StreamingOutputCallResponse.getDefaultInstance())); + "grpc.testing.TestService", "FullBidiCall"), + io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(io.grpc.testing.integration.Test.StreamingOutputCallRequest.getDefaultInstance()), + io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(io.grpc.testing.integration.Test.StreamingOutputCallResponse.getDefaultInstance())); @io.grpc.ExperimentalApi - public static final io.grpc.MethodDescriptor METHOD_HALF_BIDI_CALL = + public static final io.grpc.MethodDescriptor METHOD_HALF_BIDI_CALL = io.grpc.MethodDescriptor.create( io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING, generateFullMethodName( - "grpc.testing.lite.TestService", "HalfBidiCall"), - io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(io.grpc.testing.integration.lite.TestLite.StreamingOutputCallRequest.getDefaultInstance()), - io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(io.grpc.testing.integration.lite.TestLite.StreamingOutputCallResponse.getDefaultInstance())); + "grpc.testing.TestService", "HalfBidiCall"), + io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(io.grpc.testing.integration.Test.StreamingOutputCallRequest.getDefaultInstance()), + io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(io.grpc.testing.integration.Test.StreamingOutputCallResponse.getDefaultInstance())); public static TestServiceStub newStub(io.grpc.Channel channel) { return new TestServiceStub(channel); @@ -85,34 +85,34 @@ public class TestServiceGrpc { public static interface TestService { - public void unaryCall(io.grpc.testing.integration.lite.TestLite.SimpleRequest request, - io.grpc.stub.StreamObserver responseObserver); + public void unaryCall(io.grpc.testing.integration.Test.SimpleRequest request, + io.grpc.stub.StreamObserver responseObserver); - public void streamingOutputCall(io.grpc.testing.integration.lite.TestLite.StreamingOutputCallRequest request, - io.grpc.stub.StreamObserver responseObserver); + public void streamingOutputCall(io.grpc.testing.integration.Test.StreamingOutputCallRequest request, + io.grpc.stub.StreamObserver responseObserver); - public io.grpc.stub.StreamObserver streamingInputCall( - io.grpc.stub.StreamObserver responseObserver); + public io.grpc.stub.StreamObserver streamingInputCall( + io.grpc.stub.StreamObserver responseObserver); - public io.grpc.stub.StreamObserver fullBidiCall( - io.grpc.stub.StreamObserver responseObserver); + public io.grpc.stub.StreamObserver fullBidiCall( + io.grpc.stub.StreamObserver responseObserver); - public io.grpc.stub.StreamObserver halfBidiCall( - io.grpc.stub.StreamObserver responseObserver); + public io.grpc.stub.StreamObserver halfBidiCall( + io.grpc.stub.StreamObserver responseObserver); } public static interface TestServiceBlockingClient { - public io.grpc.testing.integration.lite.TestLite.SimpleResponse unaryCall(io.grpc.testing.integration.lite.TestLite.SimpleRequest request); + public io.grpc.testing.integration.Test.SimpleResponse unaryCall(io.grpc.testing.integration.Test.SimpleRequest request); - public java.util.Iterator streamingOutputCall( - io.grpc.testing.integration.lite.TestLite.StreamingOutputCallRequest request); + public java.util.Iterator streamingOutputCall( + io.grpc.testing.integration.Test.StreamingOutputCallRequest request); } public static interface TestServiceFutureClient { - public com.google.common.util.concurrent.ListenableFuture unaryCall( - io.grpc.testing.integration.lite.TestLite.SimpleRequest request); + public com.google.common.util.concurrent.ListenableFuture unaryCall( + io.grpc.testing.integration.Test.SimpleRequest request); } public static class TestServiceStub extends io.grpc.stub.AbstractStub @@ -133,36 +133,36 @@ public class TestServiceGrpc { } @java.lang.Override - public void unaryCall(io.grpc.testing.integration.lite.TestLite.SimpleRequest request, - io.grpc.stub.StreamObserver responseObserver) { + public void unaryCall(io.grpc.testing.integration.Test.SimpleRequest request, + io.grpc.stub.StreamObserver responseObserver) { asyncUnaryCall( getChannel().newCall(METHOD_UNARY_CALL, getCallOptions()), request, responseObserver); } @java.lang.Override - public void streamingOutputCall(io.grpc.testing.integration.lite.TestLite.StreamingOutputCallRequest request, - io.grpc.stub.StreamObserver responseObserver) { + public void streamingOutputCall(io.grpc.testing.integration.Test.StreamingOutputCallRequest request, + io.grpc.stub.StreamObserver responseObserver) { asyncServerStreamingCall( getChannel().newCall(METHOD_STREAMING_OUTPUT_CALL, getCallOptions()), request, responseObserver); } @java.lang.Override - public io.grpc.stub.StreamObserver streamingInputCall( - io.grpc.stub.StreamObserver responseObserver) { + public io.grpc.stub.StreamObserver streamingInputCall( + io.grpc.stub.StreamObserver responseObserver) { return asyncClientStreamingCall( getChannel().newCall(METHOD_STREAMING_INPUT_CALL, getCallOptions()), responseObserver); } @java.lang.Override - public io.grpc.stub.StreamObserver fullBidiCall( - io.grpc.stub.StreamObserver responseObserver) { + public io.grpc.stub.StreamObserver fullBidiCall( + io.grpc.stub.StreamObserver responseObserver) { return asyncBidiStreamingCall( getChannel().newCall(METHOD_FULL_BIDI_CALL, getCallOptions()), responseObserver); } @java.lang.Override - public io.grpc.stub.StreamObserver halfBidiCall( - io.grpc.stub.StreamObserver responseObserver) { + public io.grpc.stub.StreamObserver halfBidiCall( + io.grpc.stub.StreamObserver responseObserver) { return asyncBidiStreamingCall( getChannel().newCall(METHOD_HALF_BIDI_CALL, getCallOptions()), responseObserver); } @@ -186,14 +186,14 @@ public class TestServiceGrpc { } @java.lang.Override - public io.grpc.testing.integration.lite.TestLite.SimpleResponse unaryCall(io.grpc.testing.integration.lite.TestLite.SimpleRequest request) { + public io.grpc.testing.integration.Test.SimpleResponse unaryCall(io.grpc.testing.integration.Test.SimpleRequest request) { return blockingUnaryCall( getChannel(), METHOD_UNARY_CALL, getCallOptions(), request); } @java.lang.Override - public java.util.Iterator streamingOutputCall( - io.grpc.testing.integration.lite.TestLite.StreamingOutputCallRequest request) { + public java.util.Iterator streamingOutputCall( + io.grpc.testing.integration.Test.StreamingOutputCallRequest request) { return blockingServerStreamingCall( getChannel(), METHOD_STREAMING_OUTPUT_CALL, getCallOptions(), request); } @@ -217,8 +217,8 @@ public class TestServiceGrpc { } @java.lang.Override - public com.google.common.util.concurrent.ListenableFuture unaryCall( - io.grpc.testing.integration.lite.TestLite.SimpleRequest request) { + public com.google.common.util.concurrent.ListenableFuture unaryCall( + io.grpc.testing.integration.Test.SimpleRequest request) { return futureUnaryCall( getChannel().newCall(METHOD_UNARY_CALL, getCallOptions()), request); } @@ -248,12 +248,12 @@ public class TestServiceGrpc { public void invoke(Req request, io.grpc.stub.StreamObserver responseObserver) { switch (methodId) { case METHODID_UNARY_CALL: - serviceImpl.unaryCall((io.grpc.testing.integration.lite.TestLite.SimpleRequest) request, - (io.grpc.stub.StreamObserver) responseObserver); + serviceImpl.unaryCall((io.grpc.testing.integration.Test.SimpleRequest) request, + (io.grpc.stub.StreamObserver) responseObserver); break; case METHODID_STREAMING_OUTPUT_CALL: - serviceImpl.streamingOutputCall((io.grpc.testing.integration.lite.TestLite.StreamingOutputCallRequest) request, - (io.grpc.stub.StreamObserver) responseObserver); + serviceImpl.streamingOutputCall((io.grpc.testing.integration.Test.StreamingOutputCallRequest) request, + (io.grpc.stub.StreamObserver) responseObserver); break; default: throw new AssertionError(); @@ -267,13 +267,13 @@ public class TestServiceGrpc { switch (methodId) { case METHODID_STREAMING_INPUT_CALL: return (io.grpc.stub.StreamObserver) serviceImpl.streamingInputCall( - (io.grpc.stub.StreamObserver) responseObserver); + (io.grpc.stub.StreamObserver) responseObserver); case METHODID_FULL_BIDI_CALL: return (io.grpc.stub.StreamObserver) serviceImpl.fullBidiCall( - (io.grpc.stub.StreamObserver) responseObserver); + (io.grpc.stub.StreamObserver) responseObserver); case METHODID_HALF_BIDI_CALL: return (io.grpc.stub.StreamObserver) serviceImpl.halfBidiCall( - (io.grpc.stub.StreamObserver) responseObserver); + (io.grpc.stub.StreamObserver) responseObserver); default: throw new AssertionError(); } @@ -287,36 +287,36 @@ public class TestServiceGrpc { METHOD_UNARY_CALL, asyncUnaryCall( new MethodHandlers< - io.grpc.testing.integration.lite.TestLite.SimpleRequest, - io.grpc.testing.integration.lite.TestLite.SimpleResponse>( + io.grpc.testing.integration.Test.SimpleRequest, + io.grpc.testing.integration.Test.SimpleResponse>( serviceImpl, METHODID_UNARY_CALL))) .addMethod( METHOD_STREAMING_OUTPUT_CALL, asyncServerStreamingCall( new MethodHandlers< - io.grpc.testing.integration.lite.TestLite.StreamingOutputCallRequest, - io.grpc.testing.integration.lite.TestLite.StreamingOutputCallResponse>( + io.grpc.testing.integration.Test.StreamingOutputCallRequest, + io.grpc.testing.integration.Test.StreamingOutputCallResponse>( serviceImpl, METHODID_STREAMING_OUTPUT_CALL))) .addMethod( METHOD_STREAMING_INPUT_CALL, asyncClientStreamingCall( new MethodHandlers< - io.grpc.testing.integration.lite.TestLite.StreamingInputCallRequest, - io.grpc.testing.integration.lite.TestLite.StreamingInputCallResponse>( + io.grpc.testing.integration.Test.StreamingInputCallRequest, + io.grpc.testing.integration.Test.StreamingInputCallResponse>( serviceImpl, METHODID_STREAMING_INPUT_CALL))) .addMethod( METHOD_FULL_BIDI_CALL, asyncBidiStreamingCall( new MethodHandlers< - io.grpc.testing.integration.lite.TestLite.StreamingOutputCallRequest, - io.grpc.testing.integration.lite.TestLite.StreamingOutputCallResponse>( + io.grpc.testing.integration.Test.StreamingOutputCallRequest, + io.grpc.testing.integration.Test.StreamingOutputCallResponse>( serviceImpl, METHODID_FULL_BIDI_CALL))) .addMethod( METHOD_HALF_BIDI_CALL, asyncBidiStreamingCall( new MethodHandlers< - io.grpc.testing.integration.lite.TestLite.StreamingOutputCallRequest, - io.grpc.testing.integration.lite.TestLite.StreamingOutputCallResponse>( + io.grpc.testing.integration.Test.StreamingOutputCallRequest, + io.grpc.testing.integration.Test.StreamingOutputCallResponse>( serviceImpl, METHODID_HALF_BIDI_CALL))) .build(); } diff --git a/compiler/src/test/proto/test_lite.proto b/compiler/src/testLite/proto/test.proto similarity index 95% rename from compiler/src/test/proto/test_lite.proto rename to compiler/src/testLite/proto/test.proto index 0e422033ea..fb2e3e7722 100644 --- a/compiler/src/test/proto/test_lite.proto +++ b/compiler/src/testLite/proto/test.proto @@ -1,9 +1,9 @@ // A simple service definition for testing the protoc plugin. syntax = "proto2"; -package grpc.testing.lite; +package grpc.testing; -option java_package = "io.grpc.testing.integration.lite"; +option java_package = "io.grpc.testing.integration"; option optimize_for = LITE_RUNTIME; message SimpleRequest { diff --git a/compiler/src/test/golden/TestServiceNano.java.txt b/compiler/src/testNano/golden/TestService.java.txt similarity index 100% rename from compiler/src/test/golden/TestServiceNano.java.txt rename to compiler/src/testNano/golden/TestService.java.txt