From 72b872d4ffdb591f351cbadadcac14d41b385994 Mon Sep 17 00:00:00 2001 From: siddharthshukla Date: Thu, 8 Sep 2016 09:09:27 +0200 Subject: Add docstrings to generated beta elements Add docstrings mentioning that the Beta API is deprecated post 0.14.x in - PrintBetaServicer - PrintBetaStub - PrintBetaServerFactory - PrintBetaStubFactory --- src/compiler/python_generator.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/compiler') diff --git a/src/compiler/python_generator.cc b/src/compiler/python_generator.cc index c5f1ed8061..0e7b9fbf4d 100644 --- a/src/compiler/python_generator.cc +++ b/src/compiler/python_generator.cc @@ -236,6 +236,10 @@ bool PrintBetaServicer(const ServiceDescriptor* service, service->name()); { IndentScope raii_class_indent(out); + out->Print("\"\"\"The Beta API is deprecated for 0.15.0 and later.\n" + "\nIt is recommended to use the GA API (classes and functions in this\n" + "file not marked beta) for all further purposes. This class was generated\n" + "only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0.\"\"\"\n"); PrintAllComments(service, out); for (int i = 0; i < service->method_count(); ++i) { auto meth = service->method(i); @@ -259,6 +263,10 @@ bool PrintBetaStub(const ServiceDescriptor* service, out->Print("class Beta$Service$Stub(object):\n", "Service", service->name()); { IndentScope raii_class_indent(out); + out->Print("\"\"\"The Beta API is deprecated for 0.15.0 and later.\n" + "\nIt is recommended to use the GA API (classes and functions in this\n" + "file not marked beta) for all further purposes. This class was generated\n" + "only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0.\"\"\"\n"); PrintAllComments(service, out); for (int i = 0; i < service->method_count(); ++i) { const MethodDescriptor* meth = service->method(i); @@ -287,6 +295,11 @@ bool PrintBetaServerFactory(const grpc::string& package_qualified_service_name, "Service", service->name()); { IndentScope raii_create_server_indent(out); + out->Print("\"\"\"The Beta API is deprecated for 0.15.0 and later.\n" + "\nIt is recommended to use the GA API (classes and functions in this\n" + "file not marked beta) for all further purposes. This function was\n" + "generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0" + "\"\"\"\n"); map method_implementation_constructors; map input_message_modules_and_classes; map output_message_modules_and_classes; @@ -381,6 +394,11 @@ bool PrintBetaStubFactory(const grpc::string& package_qualified_service_name, " metadata_transformer=None, pool=None, pool_size=None):\n"); { IndentScope raii_create_server_indent(out); + out->Print("\"\"\"The Beta API is deprecated for 0.15.0 and later.\n" + "\nIt is recommended to use the GA API (classes and functions in this\n" + "file not marked beta) for all further purposes. This function was\n" + "generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0" + "\"\"\"\n"); map method_cardinalities; map input_message_modules_and_classes; map output_message_modules_and_classes; -- cgit v1.2.3 From beeeddd571b667278075799f566a79735eaa8137 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Thu, 29 Sep 2016 20:27:23 +0200 Subject: Format. --- src/compiler/python_generator.cc | 44 ++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 18 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/python_generator.cc b/src/compiler/python_generator.cc index 916a37c05e..6830f49931 100644 --- a/src/compiler/python_generator.cc +++ b/src/compiler/python_generator.cc @@ -234,10 +234,13 @@ bool PrintBetaServicer(const ServiceDescriptor* service, Printer* out) { service->name()); { IndentScope raii_class_indent(out); - out->Print("\"\"\"The Beta API is deprecated for 0.15.0 and later.\n" - "\nIt is recommended to use the GA API (classes and functions in this\n" - "file not marked beta) for all further purposes. This class was generated\n" - "only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0.\"\"\"\n"); + out->Print( + "\"\"\"The Beta API is deprecated for 0.15.0 and later.\n" + "\nIt is recommended to use the GA API (classes and functions in this\n" + "file not marked beta) for all further purposes. This class was " + "generated\n" + "only to ease transition from grpcio<0.15.0 to " + "grpcio>=0.15.0.\"\"\"\n"); PrintAllComments(service, out); for (int i = 0; i < service->method_count(); ++i) { auto meth = service->method(i); @@ -260,10 +263,13 @@ bool PrintBetaStub(const ServiceDescriptor* service, Printer* out) { out->Print("class Beta$Service$Stub(object):\n", "Service", service->name()); { IndentScope raii_class_indent(out); - out->Print("\"\"\"The Beta API is deprecated for 0.15.0 and later.\n" - "\nIt is recommended to use the GA API (classes and functions in this\n" - "file not marked beta) for all further purposes. This class was generated\n" - "only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0.\"\"\"\n"); + out->Print( + "\"\"\"The Beta API is deprecated for 0.15.0 and later.\n" + "\nIt is recommended to use the GA API (classes and functions in this\n" + "file not marked beta) for all further purposes. This class was " + "generated\n" + "only to ease transition from grpcio<0.15.0 to " + "grpcio>=0.15.0.\"\"\"\n"); PrintAllComments(service, out); for (int i = 0; i < service->method_count(); ++i) { const MethodDescriptor* meth = service->method(i); @@ -295,11 +301,12 @@ bool PrintBetaServerFactory(const grpc::string& package_qualified_service_name, "Service", service->name()); { IndentScope raii_create_server_indent(out); - out->Print("\"\"\"The Beta API is deprecated for 0.15.0 and later.\n" - "\nIt is recommended to use the GA API (classes and functions in this\n" - "file not marked beta) for all further purposes. This function was\n" - "generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0" - "\"\"\"\n"); + out->Print( + "\"\"\"The Beta API is deprecated for 0.15.0 and later.\n" + "\nIt is recommended to use the GA API (classes and functions in this\n" + "file not marked beta) for all further purposes. This function was\n" + "generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0" + "\"\"\"\n"); map method_implementation_constructors; map input_message_modules_and_classes; map output_message_modules_and_classes; @@ -399,11 +406,12 @@ bool PrintBetaStubFactory(const grpc::string& package_qualified_service_name, " metadata_transformer=None, pool=None, pool_size=None):\n"); { IndentScope raii_create_server_indent(out); - out->Print("\"\"\"The Beta API is deprecated for 0.15.0 and later.\n" - "\nIt is recommended to use the GA API (classes and functions in this\n" - "file not marked beta) for all further purposes. This function was\n" - "generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0" - "\"\"\"\n"); + out->Print( + "\"\"\"The Beta API is deprecated for 0.15.0 and later.\n" + "\nIt is recommended to use the GA API (classes and functions in this\n" + "file not marked beta) for all further purposes. This function was\n" + "generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0" + "\"\"\"\n"); map method_cardinalities; map input_message_modules_and_classes; map output_message_modules_and_classes; -- cgit v1.2.3 From 53d219c962fee8f0a755c4c7996ba4bd61f7c6bf Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Tue, 27 Sep 2016 15:45:55 -0700 Subject: PHP Proto3: gRPC PHP Plugin code generator --- src/compiler/php_generator.cc | 174 +++++++++++++++++++++++++++++++++++ src/compiler/php_generator.h | 45 +++++++++ src/compiler/php_generator_helpers.h | 58 ++++++++++++ src/compiler/php_plugin.cc | 73 +++++++++++++++ 4 files changed, 350 insertions(+) create mode 100644 src/compiler/php_generator.cc create mode 100644 src/compiler/php_generator.h create mode 100644 src/compiler/php_generator_helpers.h create mode 100644 src/compiler/php_plugin.cc (limited to 'src/compiler') diff --git a/src/compiler/php_generator.cc b/src/compiler/php_generator.cc new file mode 100644 index 0000000000..5dac02cec4 --- /dev/null +++ b/src/compiler/php_generator.cc @@ -0,0 +1,174 @@ +/* + * + * Copyright 2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include + +#include "src/compiler/config.h" +#include "src/compiler/generator_helpers.h" +#include "src/compiler/php_generator_helpers.h" + +using grpc::protobuf::FileDescriptor; +using grpc::protobuf::ServiceDescriptor; +using grpc::protobuf::MethodDescriptor; +using grpc::protobuf::Descriptor; +using grpc::protobuf::io::Printer; +using grpc::protobuf::io::StringOutputStream; +using std::map; + +namespace grpc_php_generator { +namespace { + +grpc::string MessageIdentifierName(const grpc::string &name) { + std::vector tokens = grpc_generator::tokenize(name, "."); + std::ostringstream oss; + for (unsigned int i = 0; i < tokens.size(); i++) { + oss << (i == 0 ? "" : "\\") + << grpc_generator::CapitalizeFirstLetter(tokens[i]); + } + return oss.str(); +} + +void PrintMethod(const MethodDescriptor *method, Printer *out) { + const Descriptor *input_type = method->input_type(); + const Descriptor *output_type = method->output_type(); + map vars; + vars["service_name"] = method->service()->full_name(); + vars["name"] = method->name(); + vars["input_type_id"] = MessageIdentifierName(input_type->full_name()); + vars["output_type_id"] = MessageIdentifierName(output_type->full_name()); + + out->Print("/**\n"); + out->Print(GetPHPComments(method, " *").c_str()); + if (method->client_streaming()) { + out->Print(vars, + " * @param array $$metadata metadata\n" + " * @param array $$options call options\n */\n" + "public function $name$($$metadata = [], " + "$$options = []) {\n"); + out->Indent(); + if (method->server_streaming()) { + out->Print("return $$this->_bidiRequest("); + } else { + out->Print("return $$this->_clientStreamRequest("); + } + out->Print(vars, + "'/$service_name$/$name$',\n" + "['\\$output_type_id$','decode'],\n" + "$$metadata, $$options);\n"); + } else { + out->Print(vars, + " * @param \\$input_type_id$ $$argument input argument\n" + " * @param array $$metadata metadata\n" + " * @param array $$options call options\n */\n" + "public function $name$(\\$input_type_id$ $$argument,\n" + " $$metadata = [], $$options = []) {\n"); + out->Indent(); + if (method->server_streaming()) { + out->Print("return $$this->_serverStreamRequest("); + } else { + out->Print("return $$this->_simpleRequest("); + } + out->Print(vars, + "'/$service_name$/$name$',\n" + "$$argument,\n" + "['\\$output_type_id$', 'decode'],\n" + "$$metadata, $$options);\n"); + } + out->Outdent(); + out->Print("}\n\n"); +} + +// Prints out the service descriptor object +void PrintService(const ServiceDescriptor *service, Printer *out) { + map vars; + out->Print(GetPHPComments(service, "//").c_str()); + vars["name"] = service->name(); + out->Print(vars, "class $name$Client extends \\Grpc\\BaseStub {\n\n"); + out->Indent(); + out->Print( + "/**\n * @param string $$hostname hostname\n" + " * @param array $$opts channel options\n" + " * @param Grpc\\Channel $$channel (optional) re-use channel " + "object\n */\n" + "public function __construct($$hostname, $$opts, " + "$$channel = null) {\n"); + out->Indent(); + out->Print("parent::__construct($$hostname, $$opts, $$channel);\n"); + out->Outdent(); + out->Print("}\n\n"); + for (int i = 0; i < service->method_count(); i++) { + grpc::string method_name = + grpc_generator::LowercaseFirstLetter(service->method(i)->name()); + PrintMethod(service->method(i), out); + } + out->Outdent(); + out->Print("}\n\n"); +} + +void PrintServices(const FileDescriptor *file, Printer *out) { + map vars; + vars["package"] = MessageIdentifierName(file->package()); + out->Print(vars, "namespace $package$ {\n\n"); + out->Indent(); + for (int i = 0; i < file->service_count(); i++) { + PrintService(file->service(i), out); + } + out->Outdent(); + out->Print("}\n"); +} +} + +grpc::string GenerateFile(const FileDescriptor *file) { + grpc::string output; + { + StringOutputStream output_stream(&output); + Printer out(&output_stream, '$'); + + if (file->service_count() == 0) { + return output; + } + out.Print(" + +#include "src/compiler/config.h" +#include "src/compiler/generator_helpers.h" + +namespace grpc_php_generator { + +inline grpc::string GetPHPServiceFilename(const grpc::string& filename) { + return grpc_generator::StripProto(filename) + "_grpc_pb.php"; +} + +// Get leading or trailing comments in a string. Comment lines start with "// ". +// Leading detached comments are put in in front of leading comments. +template +inline grpc::string GetPHPComments(const DescriptorType* desc, + grpc::string prefix) { + return grpc_generator::GetPrefixedComments(desc, true, prefix); +} + +} // namespace grpc_php_generator + +#endif // GRPC_INTERNAL_COMPILER_PHP_GENERATOR_HELPERS_H diff --git a/src/compiler/php_plugin.cc b/src/compiler/php_plugin.cc new file mode 100644 index 0000000000..88acad6524 --- /dev/null +++ b/src/compiler/php_plugin.cc @@ -0,0 +1,73 @@ +/* + * + * Copyright 2016, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +// Generates PHP gRPC service interface out of Protobuf IDL. + +#include + +#include "src/compiler/config.h" +#include "src/compiler/php_generator.h" +#include "src/compiler/php_generator_helpers.h" + +using grpc_php_generator::GenerateFile; +using grpc_php_generator::GetPHPServiceFilename; + +class PHPGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { + public: + PHPGrpcGenerator() {} + ~PHPGrpcGenerator() {} + + bool Generate(const grpc::protobuf::FileDescriptor *file, + const grpc::string ¶meter, + grpc::protobuf::compiler::GeneratorContext *context, + grpc::string *error) const { + grpc::string code = GenerateFile(file); + if (code.size() == 0) { + return true; + } + + // Get output file name + grpc::string file_name = GetPHPServiceFilename(file->name()); + + std::unique_ptr output( + context->Open(file_name)); + grpc::protobuf::io::CodedOutputStream coded_out(output.get()); + coded_out.WriteRaw(code.data(), code.size()); + return true; + } +}; + +int main(int argc, char *argv[]) { + PHPGrpcGenerator generator; + return grpc::protobuf::compiler::PluginMain(argc, argv, &generator); +} -- cgit v1.2.3 From 5b2e172e5785bcd73c425192ca3d670a96044d27 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 12 Oct 2016 18:00:39 +0200 Subject: Create README.md --- src/compiler/README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/compiler/README.md (limited to 'src/compiler') diff --git a/src/compiler/README.md b/src/compiler/README.md new file mode 100644 index 0000000000..a2f49b3cd5 --- /dev/null +++ b/src/compiler/README.md @@ -0,0 +1,4 @@ +#Overview + +This directory contains source code for gRPC protocol buffer compiler (*protoc*) plugins. Along with `protoc`, +these plugins are used to generate gRPC client and server stubs from `.proto` files. -- cgit v1.2.3