Merge pull request #14784 from yang-g/mockssssss

Rename generate_mock to generate_mocks
reviewable/pr14615/r13^2
Yang Gao 7 years ago committed by GitHub
commit 3163f5ba8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      bazel/cc_grpc_library.bzl
  2. 6
      bazel/generate_cc.bzl
  3. 4
      bazel/grpc_build_system.bzl
  4. 4
      doc/unit_testing.md
  5. 4
      src/proto/grpc/testing/BUILD

@ -2,7 +2,7 @@
load("//:bazel/generate_cc.bzl", "generate_cc") load("//:bazel/generate_cc.bzl", "generate_cc")
def cc_grpc_library(name, srcs, deps, proto_only, well_known_protos, generate_mock, use_external = False, **kwargs): def cc_grpc_library(name, srcs, deps, proto_only, well_known_protos, generate_mocks = False, use_external = False, **kwargs):
"""Generates C++ grpc classes from a .proto file. """Generates C++ grpc classes from a .proto file.
Assumes the generated classes will be used in cc_api_version = 2. Assumes the generated classes will be used in cc_api_version = 2.
@ -16,7 +16,7 @@ def cc_grpc_library(name, srcs, deps, proto_only, well_known_protos, generate_mo
protos protos
use_external: When True the grpc deps are prefixed with //external. This use_external: When True the grpc deps are prefixed with //external. This
allows grpc to be used as a dependency in other bazel projects. allows grpc to be used as a dependency in other bazel projects.
generate_mock: When true GMOCk code for client stub is generated. generate_mocks: When True, Google Mock code for client stub is generated.
**kwargs: rest of arguments, e.g., compatible_with and visibility. **kwargs: rest of arguments, e.g., compatible_with and visibility.
""" """
if len(srcs) > 1: if len(srcs) > 1:
@ -54,7 +54,7 @@ def cc_grpc_library(name, srcs, deps, proto_only, well_known_protos, generate_mo
srcs = [proto_target], srcs = [proto_target],
plugin = plugin, plugin = plugin,
well_known_protos = well_known_protos, well_known_protos = well_known_protos,
generate_mock = generate_mock, generate_mocks = generate_mocks,
**kwargs **kwargs
) )

@ -14,7 +14,7 @@ def generate_cc_impl(ctx):
if ctx.executable.plugin: if ctx.executable.plugin:
outs += [proto.path[label_len:-len(".proto")] + ".grpc.pb.h" for proto in protos] outs += [proto.path[label_len:-len(".proto")] + ".grpc.pb.h" for proto in protos]
outs += [proto.path[label_len:-len(".proto")] + ".grpc.pb.cc" for proto in protos] outs += [proto.path[label_len:-len(".proto")] + ".grpc.pb.cc" for proto in protos]
if ctx.attr.generate_mock: if ctx.attr.generate_mocks:
outs += [proto.path[label_len:-len(".proto")] + "_mock.grpc.pb.h" for proto in protos] outs += [proto.path[label_len:-len(".proto")] + "_mock.grpc.pb.h" for proto in protos]
else: else:
outs += [proto.path[label_len:-len(".proto")] + ".pb.h" for proto in protos] outs += [proto.path[label_len:-len(".proto")] + ".pb.h" for proto in protos]
@ -26,7 +26,7 @@ def generate_cc_impl(ctx):
if ctx.executable.plugin: if ctx.executable.plugin:
arguments += ["--plugin=protoc-gen-PLUGIN=" + ctx.executable.plugin.path] arguments += ["--plugin=protoc-gen-PLUGIN=" + ctx.executable.plugin.path]
flags = list(ctx.attr.flags) flags = list(ctx.attr.flags)
if ctx.attr.generate_mock: if ctx.attr.generate_mocks:
flags.append("generate_mock_code=true") flags.append("generate_mock_code=true")
arguments += ["--PLUGIN_out=" + ",".join(flags) + ":" + dir_out] arguments += ["--PLUGIN_out=" + ",".join(flags) + ":" + dir_out]
additional_input = [ctx.executable.plugin] additional_input = [ctx.executable.plugin]
@ -76,7 +76,7 @@ _generate_cc = rule(
"well_known_protos" : attr.label( "well_known_protos" : attr.label(
mandatory = False, mandatory = False,
), ),
"generate_mock" : attr.bool( "generate_mocks" : attr.bool(
default = False, default = False,
mandatory = False, mandatory = False,
), ),

@ -97,7 +97,7 @@ def grpc_proto_plugin(name, srcs = [], deps = []):
load("//:bazel/cc_grpc_library.bzl", "cc_grpc_library") load("//:bazel/cc_grpc_library.bzl", "cc_grpc_library")
def grpc_proto_library(name, srcs = [], deps = [], well_known_protos = False, def grpc_proto_library(name, srcs = [], deps = [], well_known_protos = False,
has_services = True, use_external = False, generate_mock = False): has_services = True, use_external = False, generate_mocks = False):
cc_grpc_library( cc_grpc_library(
name = name, name = name,
srcs = srcs, srcs = srcs,
@ -105,7 +105,7 @@ def grpc_proto_library(name, srcs = [], deps = [], well_known_protos = False,
well_known_protos = well_known_protos, well_known_protos = well_known_protos,
proto_only = not has_services, proto_only = not has_services,
use_external = use_external, use_external = use_external,
generate_mock = generate_mock, generate_mocks = generate_mocks,
) )
def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data = [], uses_polling = True, language = "C++"): def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data = [], uses_polling = True, language = "C++"):

@ -56,7 +56,7 @@ Such a mock can be auto-generated by:
1. Setting flag(generate_mock_code=true) on grpc plugin for protoc, or 1. Setting flag(generate_mock_code=true) on grpc plugin for protoc, or
1. Setting an attribute(generate_mock) in your bazel rule. 1. Setting an attribute(generate_mocks) in your bazel rule.
Protoc plugin flag: Protoc plugin flag:
@ -70,7 +70,7 @@ Bazel rule:
grpc_proto_library( grpc_proto_library(
name = "echo_proto", name = "echo_proto",
srcs = ["echo.proto"], srcs = ["echo.proto"],
generate_mock = True, generate_mocks = True,
) )
``` ```

@ -26,7 +26,7 @@ exports_files([
grpc_proto_library( grpc_proto_library(
name = "compiler_test_proto", name = "compiler_test_proto",
srcs = ["compiler_test.proto"], srcs = ["compiler_test.proto"],
generate_mock = True, generate_mocks = True,
) )
grpc_proto_library( grpc_proto_library(
@ -49,7 +49,7 @@ grpc_proto_library(
name = "echo_proto", name = "echo_proto",
srcs = ["echo.proto"], srcs = ["echo.proto"],
deps = ["echo_messages_proto"], deps = ["echo_messages_proto"],
generate_mock = True, generate_mocks = True,
) )
grpc_proto_library( grpc_proto_library(

Loading…
Cancel
Save