Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 2 additions & 0 deletions generator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ add_library(
internal/metadata_decorator_generator.h
internal/metadata_decorator_rest_generator.cc
internal/metadata_decorator_rest_generator.h
internal/mixin_utils.cc
internal/mixin_utils.h
internal/mock_connection_generator.cc
internal/mock_connection_generator.h
internal/option_defaults_generator.cc
Expand Down
2 changes: 2 additions & 0 deletions generator/google_cloud_cpp_generator.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ google_cloud_cpp_generator_hdrs = [
"internal/make_generators.h",
"internal/metadata_decorator_generator.h",
"internal/metadata_decorator_rest_generator.h",
"internal/mixin_utils.h",
"internal/mock_connection_generator.h",
"internal/option_defaults_generator.h",
"internal/options_generator.h",
Expand Down Expand Up @@ -108,6 +109,7 @@ google_cloud_cpp_generator_srcs = [
"internal/make_generators.cc",
"internal/metadata_decorator_generator.cc",
"internal/metadata_decorator_rest_generator.cc",
"internal/mixin_utils.cc",
"internal/mock_connection_generator.cc",
"internal/option_defaults_generator.cc",
"internal/options_generator.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class DefaultGoldenKitchenSinkStub : public GoldenKitchenSinkStub {
public:
explicit DefaultGoldenKitchenSinkStub(
std::unique_ptr<google::test::admin::database::v1::GoldenKitchenSink::StubInterface> grpc_stub)
: grpc_stub_(std::move(grpc_stub)) {}
: grpc_stub_(std::move(grpc_stub)){}

StatusOr<google::test::admin::database::v1::GenerateAccessTokenResponse> GenerateAccessToken(
grpc::ClientContext& context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ class GoldenThingAdminStub {
class DefaultGoldenThingAdminStub : public GoldenThingAdminStub {
public:
DefaultGoldenThingAdminStub(
std::unique_ptr<google::test::admin::database::v1::GoldenThingAdmin::StubInterface> grpc_stub,
std::unique_ptr<google::longrunning::Operations::StubInterface> operations)
: grpc_stub_(std::move(grpc_stub)),
operations_(std::move(operations)) {}
std::unique_ptr<google::test::admin::database::v1::GoldenThingAdmin::StubInterface> grpc_stub
,std::unique_ptr<google::longrunning::Operations::StubInterface> operations)
: grpc_stub_(std::move(grpc_stub))
, operations_(std::move(operations)) {}

StatusOr<google::test::admin::database::v1::ListDatabasesResponse> ListDatabases(
grpc::ClientContext& context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ class RequestIdServiceStub {
class DefaultRequestIdServiceStub : public RequestIdServiceStub {
public:
DefaultRequestIdServiceStub(
std::unique_ptr<google::test::requestid::v1::RequestIdService::StubInterface> grpc_stub,
std::unique_ptr<google::longrunning::Operations::StubInterface> operations)
: grpc_stub_(std::move(grpc_stub)),
operations_(std::move(operations)) {}
std::unique_ptr<google::test::requestid::v1::RequestIdService::StubInterface> grpc_stub
,std::unique_ptr<google::longrunning::Operations::StubInterface> operations)
: grpc_stub_(std::move(grpc_stub))
, operations_(std::move(operations)) {}

StatusOr<google::test::requestid::v1::Foo> CreateFoo(
grpc::ClientContext& context,
Expand Down
5 changes: 3 additions & 2 deletions generator/internal/auth_decorator_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ AuthDecoratorGenerator::AuthDecoratorGenerator(
google::protobuf::ServiceDescriptor const* service_descriptor,
VarsDictionary service_vars,
std::map<std::string, VarsDictionary> service_method_vars,
google::protobuf::compiler::GeneratorContext* context)
google::protobuf::compiler::GeneratorContext* context,
std::vector<MixinMethod> const& mixin_methods)
: StubGeneratorBase("auth_header_path", "auth_cc_path", service_descriptor,
std::move(service_vars), std::move(service_method_vars),
context) {}
context, mixin_methods) {}

Status AuthDecoratorGenerator::GenerateHeader() {
HeaderPrint(CopyrightLicenseFileHeader());
Expand Down
3 changes: 2 additions & 1 deletion generator/internal/auth_decorator_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class AuthDecoratorGenerator : public StubGeneratorBase {
google::protobuf::ServiceDescriptor const* service_descriptor,
VarsDictionary service_vars,
std::map<std::string, VarsDictionary> service_method_vars,
google::protobuf::compiler::GeneratorContext* context);
google::protobuf::compiler::GeneratorContext* context,
std::vector<MixinMethod> const& mixin_methods);

~AuthDecoratorGenerator() override = default;

Expand Down
6 changes: 4 additions & 2 deletions generator/internal/client_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ ClientGenerator::ClientGenerator(
google::protobuf::ServiceDescriptor const* service_descriptor,
VarsDictionary service_vars,
std::map<std::string, VarsDictionary> service_method_vars,
google::protobuf::compiler::GeneratorContext* context)
google::protobuf::compiler::GeneratorContext* context,
std::vector<MixinMethod> const& mixin_methods)
: ServiceCodeGenerator("client_header_path", "client_cc_path",
service_descriptor, std::move(service_vars),
std::move(service_method_vars), context) {
std::move(service_method_vars), context,
mixin_methods) {
// Remember if there are methods from google.iam.v1.GetIamPolicyRequest and
// google.iam.v1.SetIamPolicyRequest to google.iam.v1.Policy with signature
// extensions. If so, we'll generate a "set" wrapper method to help prevent
Expand Down
3 changes: 2 additions & 1 deletion generator/internal/client_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class ClientGenerator : public ServiceCodeGenerator {
ClientGenerator(google::protobuf::ServiceDescriptor const* service_descriptor,
VarsDictionary service_vars,
std::map<std::string, VarsDictionary> service_method_vars,
google::protobuf::compiler::GeneratorContext* context);
google::protobuf::compiler::GeneratorContext* context,
std::vector<MixinMethod> const& mixin_methods);

~ClientGenerator() override = default;

Expand Down
20 changes: 13 additions & 7 deletions generator/internal/connection_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "generator/internal/pagination.h"
#include "generator/internal/predicate_utils.h"
#include "generator/internal/printer.h"
#include "absl/strings/str_split.h"
#include <google/protobuf/descriptor.h>

namespace google {
Expand All @@ -29,10 +30,12 @@ ConnectionGenerator::ConnectionGenerator(
google::protobuf::ServiceDescriptor const* service_descriptor,
VarsDictionary service_vars,
std::map<std::string, VarsDictionary> service_method_vars,
google::protobuf::compiler::GeneratorContext* context)
google::protobuf::compiler::GeneratorContext* context,
std::vector<MixinMethod> const& mixin_methods)
: ServiceCodeGenerator("connection_header_path", "connection_cc_path",
service_descriptor, std::move(service_vars),
std::move(service_method_vars), context) {}
std::move(service_method_vars), context,
mixin_methods) {}

Status ConnectionGenerator::GenerateHeader() {
HeaderPrint(CopyrightLicenseFileHeader());
Expand Down Expand Up @@ -68,11 +71,14 @@ Status ConnectionGenerator::GenerateHeader() {
: "",
IsExperimental() ? "google/cloud/experimental_tag.h" : "",
"google/cloud/version.h"});
HeaderSystemIncludes(
{vars("proto_header_path"), vars("additional_pb_header_paths"),
HasGRPCLongrunningOperation() ? "google/longrunning/operations.grpc.pb.h"
: "",
"memory"});
std::vector<std::string> const additional_pb_header_paths =
absl::StrSplit(vars("additional_pb_header_paths"), absl::ByChar(','));
HeaderSystemIncludes(additional_pb_header_paths);
HeaderSystemIncludes({vars("proto_header_path"),
HasGRPCLongrunningOperation()
? "google/longrunning/operations.grpc.pb.h"
: "",
"memory"});
switch (endpoint_location_style) {
case ServiceConfiguration::LOCATION_DEPENDENT:
case ServiceConfiguration::LOCATION_DEPENDENT_COMPAT:
Expand Down
3 changes: 2 additions & 1 deletion generator/internal/connection_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class ConnectionGenerator : public ServiceCodeGenerator {
google::protobuf::ServiceDescriptor const* service_descriptor,
VarsDictionary service_vars,
std::map<std::string, VarsDictionary> service_method_vars,
google::protobuf::compiler::GeneratorContext* context);
google::protobuf::compiler::GeneratorContext* context,
std::vector<MixinMethod> const& mixin_methods);

~ConnectionGenerator() override = default;

Expand Down
11 changes: 6 additions & 5 deletions generator/internal/connection_impl_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ ConnectionImplGenerator::ConnectionImplGenerator(
google::protobuf::ServiceDescriptor const* service_descriptor,
VarsDictionary service_vars,
std::map<std::string, VarsDictionary> service_method_vars,
google::protobuf::compiler::GeneratorContext* context)
: ServiceCodeGenerator("connection_impl_header_path",
"connection_impl_cc_path", service_descriptor,
std::move(service_vars),
std::move(service_method_vars), context) {}
google::protobuf::compiler::GeneratorContext* context,
std::vector<MixinMethod> const& mixin_methods)
: ServiceCodeGenerator(
"connection_impl_header_path", "connection_impl_cc_path",
service_descriptor, std::move(service_vars),
std::move(service_method_vars), context, mixin_methods) {}

Status ConnectionImplGenerator::GenerateHeader() {
HeaderPrint(CopyrightLicenseFileHeader());
Expand Down
3 changes: 2 additions & 1 deletion generator/internal/connection_impl_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class ConnectionImplGenerator : public ServiceCodeGenerator {
google::protobuf::ServiceDescriptor const* service_descriptor,
VarsDictionary service_vars,
std::map<std::string, VarsDictionary> service_method_vars,
google::protobuf::compiler::GeneratorContext* context);
google::protobuf::compiler::GeneratorContext* context,
std::vector<MixinMethod> const& mixin_methods);

~ConnectionImplGenerator() override = default;

Expand Down
11 changes: 6 additions & 5 deletions generator/internal/connection_impl_rest_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ ConnectionImplRestGenerator::ConnectionImplRestGenerator(
google::protobuf::ServiceDescriptor const* service_descriptor,
VarsDictionary service_vars,
std::map<std::string, VarsDictionary> service_method_vars,
google::protobuf::compiler::GeneratorContext* context)
: ServiceCodeGenerator("connection_impl_rest_header_path",
"connection_impl_rest_cc_path", service_descriptor,
std::move(service_vars),
std::move(service_method_vars), context) {}
google::protobuf::compiler::GeneratorContext* context,
std::vector<MixinMethod> const& mixin_methods)
: ServiceCodeGenerator(
"connection_impl_rest_header_path", "connection_impl_rest_cc_path",
service_descriptor, std::move(service_vars),
std::move(service_method_vars), context, mixin_methods) {}

Status ConnectionImplRestGenerator::GenerateHeader() {
HeaderPrint(CopyrightLicenseFileHeader());
Expand Down
3 changes: 2 additions & 1 deletion generator/internal/connection_impl_rest_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class ConnectionImplRestGenerator : public ServiceCodeGenerator {
google::protobuf::ServiceDescriptor const* service_descriptor,
VarsDictionary service_vars,
std::map<std::string, VarsDictionary> service_method_vars,
google::protobuf::compiler::GeneratorContext* context);
google::protobuf::compiler::GeneratorContext* context,
std::vector<MixinMethod> const& mixin_methods);

~ConnectionImplRestGenerator() override = default;

Expand Down
11 changes: 6 additions & 5 deletions generator/internal/connection_rest_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ ConnectionRestGenerator::ConnectionRestGenerator(
google::protobuf::ServiceDescriptor const* service_descriptor,
VarsDictionary service_vars,
std::map<std::string, VarsDictionary> service_method_vars,
google::protobuf::compiler::GeneratorContext* context)
: ServiceCodeGenerator("connection_rest_header_path",
"connection_rest_cc_path", service_descriptor,
std::move(service_vars),
std::move(service_method_vars), context) {}
google::protobuf::compiler::GeneratorContext* context,
std::vector<MixinMethod> const& mixin_methods)
: ServiceCodeGenerator(
"connection_rest_header_path", "connection_rest_cc_path",
service_descriptor, std::move(service_vars),
std::move(service_method_vars), context, mixin_methods) {}

Status ConnectionRestGenerator::GenerateHeader() {
HeaderPrint(CopyrightLicenseFileHeader());
Expand Down
3 changes: 2 additions & 1 deletion generator/internal/connection_rest_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class ConnectionRestGenerator : public ServiceCodeGenerator {
google::protobuf::ServiceDescriptor const* service_descriptor,
VarsDictionary service_vars,
std::map<std::string, VarsDictionary> service_method_vars,
google::protobuf::compiler::GeneratorContext* context);
google::protobuf::compiler::GeneratorContext* context,
std::vector<MixinMethod> const& mixin_methods);

~ConnectionRestGenerator() override = default;

Expand Down
63 changes: 60 additions & 3 deletions generator/internal/descriptor_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,18 @@ std::string FormatAdditionalPbHeaderPaths(VarsDictionary& vars) {
return absl::StrJoin(additional_pb_header_paths, ",");
}

std::string FormatMixinPbHeaderPaths(
std::vector<MixinMethod> const& mixin_methods, std::string suffix) {
std::vector<std::string> mixin_header_paths;
for (auto const& mixin_method : mixin_methods) {
std::string mixin_header_path = absl::StrCat(
absl::StripSuffix(mixin_method.method.get().file()->name(), ".proto"),
suffix);
mixin_header_paths.push_back(mixin_header_path);
}
return absl::StrJoin(mixin_header_paths, ",");
}

// If a service name mapping exists, return the new name.
// Parses a command line argument in the form:
// {"service_name_mappings": "service_a=new_service_a,service=new_service"}.
Expand Down Expand Up @@ -559,7 +571,8 @@ bool CheckParameterCommentSubstitutions() {

VarsDictionary CreateServiceVars(
google::protobuf::ServiceDescriptor const& descriptor,
std::vector<std::pair<std::string, std::string>> const& initial_values) {
std::vector<std::pair<std::string, std::string>> const& initial_values,
std::vector<MixinMethod> const& mixin_methods) {
VarsDictionary vars(initial_values.begin(), initial_values.end());
auto const& service_name = GetEffectiveServiceName(vars, descriptor.name());
vars["product_options_page"] = OptionsGroup(vars["product_path"]);
Expand Down Expand Up @@ -692,6 +705,10 @@ VarsDictionary CreateServiceVars(
absl::StripSuffix(descriptor.file()->name(), ".proto"), ".grpc.pb.h");
vars["proto_header_path"] = absl::StrCat(
absl::StripSuffix(descriptor.file()->name(), ".proto"), ".pb.h");
vars["mixin_proto_grpc_header_paths"] =
FormatMixinPbHeaderPaths(mixin_methods, ".grpc.pb.h");
vars["mixin_proto_header_paths"] =
FormatMixinPbHeaderPaths(mixin_methods, ".pb.h");
vars["retry_policy_name"] = absl::StrCat(service_name, "RetryPolicy");
vars["retry_traits_name"] = absl::StrCat(service_name, "RetryTraits");
vars["retry_traits_header_path"] =
Expand Down Expand Up @@ -802,7 +819,8 @@ std::map<std::string, std::string> ParseIdempotencyOverrides(

std::map<std::string, VarsDictionary> CreateMethodVars(
google::protobuf::ServiceDescriptor const& service,
YAML::Node const& service_config, VarsDictionary const& vars) {
YAML::Node const& service_config, VarsDictionary const& vars,
std::vector<MixinMethod> const& mixin_methods) {
auto split_arg = [&vars](std::string const& arg) -> std::set<std::string> {
auto l = vars.find(arg);
if (l == vars.end()) return {};
Expand Down Expand Up @@ -842,7 +860,46 @@ std::map<std::string, VarsDictionary> CreateMethodVars(
SetLongrunningOperationMethodVars(method, method_vars);
AssignPaginationMethodVars(method, method_vars);
SetMethodSignatureMethodVars(service, method, omitted_rpcs, method_vars);
auto parsed_http_info = ParseHttpExtension(method);
auto parsed_http_info = ParseHttpExtension(method, service);
method_vars["request_resource"] =
FormatRequestResource(*method.input_type(), parsed_http_info);
SetHttpDerivedMethodVars(parsed_http_info, method, method_vars);
SetHttpQueryParameters(parsed_http_info, method, method_vars);
service_methods_vars[method.full_name()] = method_vars;
}
for (auto const& mixin_method : mixin_methods) {
auto const& method = mixin_method.method.get();
VarsDictionary method_vars;
method_vars["method_return_doxygen_link"] =
FormatDoxygenLink(*method.output_type());
method_vars["idempotency"] = DefaultIdempotencyFromHttpOperation(method);
if (!idempotency_overrides.empty()) {
auto iter = idempotency_overrides.find(
absl::StrCat(service.name(), ".", method.name()));
if (iter != idempotency_overrides.end()) {
method_vars["idempotency"] = iter->second;
}
}
method_vars["method_name"] = method.name();
method_vars["method_name_snake"] = CamelCaseToSnakeCase(method.name());
method_vars["request_type"] =
ProtoNameToCppName(method.input_type()->full_name());
method_vars["response_message_type"] = method.output_type()->full_name();
method_vars["response_type"] =
ProtoNameToCppName(method.output_type()->full_name());
method_vars["return_type"] =
IsResponseTypeEmpty(method)
? "Status"
: absl::StrFormat("StatusOr<%s>", method_vars.at("response_type"));
auto request_id_field_name = RequestIdFieldName(service_config, method);
if (!request_id_field_name.empty()) {
method_vars["request_id_field_name"] = std::move(request_id_field_name);
}
SetLongrunningOperationMethodVars(method, method_vars);
AssignPaginationMethodVars(method, method_vars);
SetMethodSignatureMethodVars(service, method, omitted_rpcs, method_vars);
auto parsed_http_info =
ParseHttpExtension(method, service, mixin_method.method_override);
method_vars["request_resource"] =
FormatRequestResource(*method.input_type(), parsed_http_info);
SetHttpDerivedMethodVars(parsed_http_info, method, method_vars);
Expand Down
7 changes: 5 additions & 2 deletions generator/internal/descriptor_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define GOOGLE_CLOUD_CPP_GENERATOR_INTERNAL_DESCRIPTOR_UTILS_H

#include "generator/internal/generator_interface.h"
#include "generator/internal/mixin_utils.h"
#include "generator/internal/predicate_utils.h"
#include "generator/internal/printer.h"
#include "absl/types/variant.h"
Expand All @@ -38,14 +39,16 @@ namespace generator_internal {
*/
VarsDictionary CreateServiceVars(
google::protobuf::ServiceDescriptor const& descriptor,
std::vector<std::pair<std::string, std::string>> const& initial_values);
std::vector<std::pair<std::string, std::string>> const& initial_values,
std::vector<MixinMethod> const& mixin_methods = std::vector<MixinMethod>());

/**
* Extracts method specific substitution data for each method in the service.
*/
std::map<std::string, VarsDictionary> CreateMethodVars(
google::protobuf::ServiceDescriptor const& service,
YAML::Node const& service_config, VarsDictionary const& service_vars);
YAML::Node const& service_config, VarsDictionary const& service_vars,
std::vector<MixinMethod> const& mixin_methods = std::vector<MixinMethod>());

/**
* Determines which `MethodPattern` to use from patterns for the given method
Expand Down
Loading