Browse Source

Allow services with lite runtime when using rpc generator plugin.

kenton@google.com 15 years ago
parent
commit
d09ab8538d
2 changed files with 17 additions and 3 deletions
  1. 6 2
      src/google/protobuf/descriptor.cc
  2. 11 1
      src/google/protobuf/descriptor_unittest.cc

+ 6 - 2
src/google/protobuf/descriptor.cc

@@ -3720,10 +3720,14 @@ void DescriptorBuilder::ValidateEnumValueOptions(
 }
 }
 void DescriptorBuilder::ValidateServiceOptions(ServiceDescriptor* service,
 void DescriptorBuilder::ValidateServiceOptions(ServiceDescriptor* service,
     const ServiceDescriptorProto& proto) {
     const ServiceDescriptorProto& proto) {
-  if (IsLite(service->file())) {
+  if (IsLite(service->file()) &&
+      (service->file()->options().cc_generic_services() ||
+       service->file()->options().java_generic_services())) {
     AddError(service->full_name(), proto,
     AddError(service->full_name(), proto,
              DescriptorPool::ErrorCollector::NAME,
              DescriptorPool::ErrorCollector::NAME,
-             "Files with optimize_for = LITE_RUNTIME cannot define services.");
+             "Files with optimize_for = LITE_RUNTIME cannot define services "
+             "unless you set both options cc_generic_services and "
+             "java_generic_sevices to false.");
   }
   }
 
 
   VALIDATE_OPTIONS_FROM_ARRAY(service, method, Method);
   VALIDATE_OPTIONS_FROM_ARRAY(service, method, Method);

+ 11 - 1
src/google/protobuf/descriptor_unittest.cc

@@ -3487,7 +3487,17 @@ TEST_F(ValidationErrorTest, NoLiteServices) {
     "service { name: \"Foo\" }",
     "service { name: \"Foo\" }",
 
 
     "foo.proto: Foo: NAME: Files with optimize_for = LITE_RUNTIME cannot "
     "foo.proto: Foo: NAME: Files with optimize_for = LITE_RUNTIME cannot "
-    "define services.\n");
+    "define services unless you set both options cc_generic_services and "
+    "java_generic_sevices to false.\n");
+
+  BuildFile(
+    "name: \"bar.proto\" "
+    "options {"
+    "  optimize_for: LITE_RUNTIME"
+    "  cc_generic_services: false"
+    "  java_generic_services: false"
+    "} "
+    "service { name: \"Foo\" }");
 }
 }
 
 
 TEST_F(ValidationErrorTest, RollbackAfterError) {
 TEST_F(ValidationErrorTest, RollbackAfterError) {