Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated grpc flag to is_grpc to make it more apparent it's a bool #518

Merged
merged 2 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions proto/proto.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _expand_provider(lst, provider):
"""
return [el[provider] for el in lst if provider in el]

def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, grpc, compile_deps):
def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, is_grpc, compile_deps):
"""Create and run a rustc compile action based on the current rule's attributes

Args:
Expand All @@ -174,7 +174,7 @@ def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, grpc,
imports (depset): A set of transitive protobuf Imports.
crate_name (str): The name of the Crate for the current target
ctx (ctx): The current rule's context object
grpc (bool): True if the current rule is a `gRPC` rule.
is_grpc (bool): True if the current rule is a `gRPC` rule.
compile_deps (list): A list of Rust dependencies (`List[Target]`)

Returns:
Expand All @@ -183,7 +183,7 @@ def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, grpc,

# Create all the source in a specific folder
proto_toolchain = ctx.toolchains["@io_bazel_rules_rust//proto:toolchain"]
output_dir = "%s.%s.rust" % (crate_name, "grpc" if grpc else "proto")
output_dir = "%s.%s.rust" % (crate_name, "grpc" if is_grpc else "proto")

# Generate the proto stubs
srcs = _generate_proto(
Expand All @@ -193,12 +193,12 @@ def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, grpc,
imports = imports,
output_dir = output_dir,
proto_toolchain = proto_toolchain,
grpc = grpc,
is_grpc = is_grpc,
)

# and lib.rs
lib_rs = ctx.actions.declare_file("%s/lib.rs" % output_dir)
_gen_lib(ctx, grpc, protos, lib_rs)
_gen_lib(ctx, is_grpc, protos, lib_rs)
srcs.append(lib_rs)

# And simulate rust_library behavior
Expand Down Expand Up @@ -228,12 +228,12 @@ def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, grpc,
output_hash = output_hash,
)

def _rust_protogrpc_library_impl(ctx, grpc):
def _rust_protogrpc_library_impl(ctx, is_grpc):
"""Implementation of the rust_(proto|grpc)_library.

Args:
ctx (ctx): The current rule's context object
grpc (bool): True if the current rule is a `gRPC` rule.
is_grpc (bool): True if the current rule is a `gRPC` rule.

Returns:
list: A list of providers, see `_rust_proto_compile`
Expand All @@ -251,7 +251,7 @@ def _rust_protogrpc_library_impl(ctx, grpc):
imports = depset(transitive = [p.transitive_imports for p in proto]),
crate_name = ctx.label.name,
ctx = ctx,
grpc = grpc,
is_grpc = is_grpc,
compile_deps = ctx.attr.rust_deps,
)

Expand Down
6 changes: 3 additions & 3 deletions proto/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def rust_generate_proto(
imports,
output_dir,
proto_toolchain,
grpc = False):
is_grpc = False):
"""Generate a proto compilation action.

Args:
Expand All @@ -36,7 +36,7 @@ def rust_generate_proto(
imports (depset): directory, relative to the package, to output the list of stubs.
output_dir (str): The basename of the output directory for for the output generated stubs
proto_toolchain (ToolchainInfo): The toolchain for rust-proto compilation. See `rust_proto_toolchain`
grpc (bool, optional): generate gRPC stubs. Defaults to False.
is_grpc (bool, optional): generate gRPC stubs. Defaults to False.

Returns:
list: the list of generate stubs (File)
Expand All @@ -55,7 +55,7 @@ def rust_generate_proto(
outs = [ctx.actions.declare_file(path + ".rs") for path in paths]
output_directory = outs[0].dirname

if grpc:
if is_grpc:
# Add grpc stubs to the list of outputs
grpc_files = [ctx.actions.declare_file(path + "_grpc.rs") for path in paths]
outs.extend(grpc_files)
Expand Down