Skip to content

Commit

Permalink
Update grpc protoc plugin to be compliant of proto3 field presence
Browse files Browse the repository at this point in the history
  • Loading branch information
stanley-cheung committed May 20, 2020
1 parent 655f478 commit 312e70c
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 14 deletions.
8 changes: 4 additions & 4 deletions bazel/grpc_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ def grpc_deps():
if "com_google_protobuf" not in native.existing_rules():
http_archive(
name = "com_google_protobuf",
sha256 = "2435b7fb83b8a608c24ca677907aa9a35e482a7f018e65ca69481b3c8c9f7caf",
strip_prefix = "protobuf-d0bfd5221182da1a7cc280f3337b5e41a89539cf",
sha256 = "e6f9f187c352bdee57fcb6fd629cb7b90e42b6739f54e634a5fe7ad9327db459",
strip_prefix = "protobuf-0dd036d675508a4ecf69e61626fd0c88235a661d",
urls = [
"https://storage.googleapis.com/grpc-bazel-mirror/github.com/google/protobuf/archive/d0bfd5221182da1a7cc280f3337b5e41a89539cf.tar.gz",
"https://github.com/google/protobuf/archive/d0bfd5221182da1a7cc280f3337b5e41a89539cf.tar.gz",
"https://storage.googleapis.com/grpc-bazel-mirror/github.com/google/protobuf/archive/0dd036d675508a4ecf69e61626fd0c88235a661d.tar.gz",
"https://github.com/google/protobuf/archive/0dd036d675508a4ecf69e61626fd0c88235a661d.tar.gz",
],
)

Expand Down
6 changes: 5 additions & 1 deletion src/compiler/cpp_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
CppGrpcGenerator() {}
virtual ~CppGrpcGenerator() {}

uint64_t GetSupportedFeatures() const override {
return FEATURE_PROTO3_OPTIONAL;
}

virtual bool Generate(const grpc::protobuf::FileDescriptor* file,
const grpc::string& parameter,
grpc::protobuf::compiler::GeneratorContext* context,
grpc::string* error) const {
grpc::string* error) const override {
if (file->options().cc_generic_services()) {
*error =
"cpp grpc proto compiler plugin does not work with generic "
Expand Down
6 changes: 5 additions & 1 deletion src/compiler/csharp_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ class CSharpGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
CSharpGrpcGenerator() {}
~CSharpGrpcGenerator() {}

uint64_t GetSupportedFeatures() const override {
return FEATURE_PROTO3_OPTIONAL;
}

bool Generate(const grpc::protobuf::FileDescriptor* file,
const grpc::string& parameter,
grpc::protobuf::compiler::GeneratorContext* context,
grpc::string* error) const {
grpc::string* error) const override {
std::vector<std::pair<grpc::string, grpc::string> > options;
grpc::protobuf::compiler::ParseGeneratorParameter(parameter, &options);

Expand Down
6 changes: 5 additions & 1 deletion src/compiler/node_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ class NodeGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
NodeGrpcGenerator() {}
~NodeGrpcGenerator() {}

uint64_t GetSupportedFeatures() const override {
return FEATURE_PROTO3_OPTIONAL;
}

bool Generate(const grpc::protobuf::FileDescriptor* file,
const grpc::string& parameter,
grpc::protobuf::compiler::GeneratorContext* context,
grpc::string* error) const {
grpc::string* error) const override {
grpc_node_generator::Parameters generator_parameters;
generator_parameters.minimum_node_version = 4;

Expand Down
6 changes: 5 additions & 1 deletion src/compiler/objective_c_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,14 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
virtual ~ObjectiveCGrpcGenerator() {}

public:
uint64_t GetSupportedFeatures() const override {
return FEATURE_PROTO3_OPTIONAL;
}

virtual bool Generate(const grpc::protobuf::FileDescriptor* file,
const ::grpc::string& parameter,
grpc::protobuf::compiler::GeneratorContext* context,
::grpc::string* error) const {
::grpc::string* error) const override {
if (file->service_count() == 0) {
// No services. Do nothing.
return true;
Expand Down
6 changes: 5 additions & 1 deletion src/compiler/php_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ class PHPGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
PHPGrpcGenerator() {}
~PHPGrpcGenerator() {}

uint64_t GetSupportedFeatures() const override {
return FEATURE_PROTO3_OPTIONAL;
}

bool Generate(const grpc::protobuf::FileDescriptor* file,
const grpc::string& parameter,
grpc::protobuf::compiler::GeneratorContext* context,
grpc::string* error) const {
grpc::string* error) const override {
if (file->service_count() == 0) {
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/python_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,10 @@ static bool ParseParameters(const grpc::string& parameter,
return true;
}

uint64_t PythonGrpcGenerator::GetSupportedFeatures() const {
return FEATURE_PROTO3_OPTIONAL;
}

bool PythonGrpcGenerator::Generate(const FileDescriptor* file,
const grpc::string& parameter,
GeneratorContext* context,
Expand Down
4 changes: 3 additions & 1 deletion src/compiler/python_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ class PythonGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
PythonGrpcGenerator(const GeneratorConfiguration& config);
~PythonGrpcGenerator();

uint64_t GetSupportedFeatures() const override;

bool Generate(const grpc::protobuf::FileDescriptor* file,
const grpc::string& parameter,
grpc::protobuf::compiler::GeneratorContext* context,
grpc::string* error) const;
grpc::string* error) const override;

private:
GeneratorConfiguration config_;
Expand Down
6 changes: 5 additions & 1 deletion src/compiler/ruby_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ class RubyGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
RubyGrpcGenerator() {}
~RubyGrpcGenerator() {}

uint64_t GetSupportedFeatures() const override {
return FEATURE_PROTO3_OPTIONAL;
}

bool Generate(const grpc::protobuf::FileDescriptor* file,
const grpc::string& /*parameter*/,
grpc::protobuf::compiler::GeneratorContext* context,
grpc::string* /*error*/) const {
grpc::string* /*error*/) const override {
grpc::string code = grpc_ruby_generator::GetServices(file);
if (code.size() == 0) {
return true; // don't generate a file if there are no services
Expand Down
2 changes: 1 addition & 1 deletion third_party/protobuf
2 changes: 1 addition & 1 deletion tools/distrib/python/grpcio_tools/protoc_lib_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
CC_INCLUDE='third_party/protobuf/src'
PROTO_INCLUDE='third_party/protobuf/src'

PROTOBUF_SUBMODULE_VERSION="d0bfd5221182da1a7cc280f3337b5e41a89539cf"
PROTOBUF_SUBMODULE_VERSION="0dd036d675508a4ecf69e61626fd0c88235a661d"
2 changes: 1 addition & 1 deletion tools/run_tests/sanity/check_submodules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ cat << EOF | awk '{ print $1 }' | sort > "$want_submodules"
80ed4d0bbf65d57cc267dfc63bd2584557f11f9b third_party/googleapis (common-protos-1_3_1-915-g80ed4d0bb)
c9ccac7cb7345901884aabf5d1a786cfa6e2f397 third_party/googletest (6e2f397)
15ae750151ac9341e5945eb38f8982d59fb99201 third_party/libuv (v1.34.0)
d0bfd5221182da1a7cc280f3337b5e41a89539cf third_party/protobuf (v3.7.0-rc.2-784-gd0bfd5221)
0dd036d675508a4ecf69e61626fd0c88235a661d third_party/protobuf (v3.12.0)
0f2bc6c0fdac9113e3863ea6e30e5b2bd33e3b40 third_party/protoc-gen-validate (v0.0.10)
e8cd3a4bb307e2c810cffff99f93e96e6d7fee85 third_party/udpa (heads/master)
cacf7f1d4e3d44d871b605da3b647f07d718623f third_party/zlib (v1.2.11)
Expand Down

0 comments on commit 312e70c

Please sign in to comment.