all: fix formatting on bzl file

This commit is contained in:
Carl Mastrangelo 2019-01-25 16:13:46 -08:00 committed by GitHub
parent f6689a1f86
commit 6c8020e584
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 95 additions and 86 deletions

View File

@ -1,15 +1,16 @@
def _path_ignoring_repository(f): def _path_ignoring_repository(f):
if (len(f.owner.workspace_root) == 0): if (len(f.owner.workspace_root) == 0):
return f.short_path return f.short_path
return f.path[f.path.find(f.owner.workspace_root)+len(f.owner.workspace_root)+1:] return f.path[f.path.find(f.owner.workspace_root) + len(f.owner.workspace_root) + 1:]
def _gensource_impl(ctx): def _gensource_impl(ctx):
if len(ctx.attr.srcs) > 1: if len(ctx.attr.srcs) > 1:
fail("Only one src value supported", "srcs") fail("Only one src value supported", "srcs")
for s in ctx.attr.srcs: for s in ctx.attr.srcs:
if s.label.package != ctx.label.package: if s.label.package != ctx.label.package:
print(("in srcs attribute of {0}: Proto source with label {1} should be in " print(("in srcs attribute of {0}: Proto source with label {1} should be in " +
+ "same package as consuming rule").format(ctx.label, s.label)) "same package as consuming rule").format(ctx.label, s.label))
# Use .jar since .srcjar makes protoc think output will be a directory # Use .jar since .srcjar makes protoc think output will be a directory
srcdotjar = ctx.new_file(ctx.label.name + "_src.jar") srcdotjar = ctx.new_file(ctx.label.name + "_src.jar")
@ -26,14 +27,17 @@ def _gensource_impl(ctx):
arguments = [ arguments = [
"--plugin=protoc-gen-grpc-java=" + ctx.executable._java_plugin.path, "--plugin=protoc-gen-grpc-java=" + ctx.executable._java_plugin.path,
"--grpc-java_out={0},enable_deprecated={1}:{2}" "--grpc-java_out={0},enable_deprecated={1}:{2}"
.format(flavor, str(ctx.attr.enable_deprecated).lower(), srcdotjar.path)] .format(flavor, str(ctx.attr.enable_deprecated).lower(), srcdotjar.path),
+ ["-I{0}={1}".format(_path_ignoring_repository(include), include.path) for include in includes] ] +
+ [_path_ignoring_repository(src) for src in srcs]) ["-I{0}={1}".format(_path_ignoring_repository(include), include.path) for include in includes] +
[_path_ignoring_repository(src) for src in srcs],
)
ctx.action( ctx.action(
command = "cp $1 $2", command = "cp $1 $2",
inputs = [srcdotjar], inputs = [srcdotjar],
outputs = [ctx.outputs.srcjar], outputs = [ctx.outputs.srcjar],
arguments = [srcdotjar.path, ctx.outputs.srcjar.path]) arguments = [srcdotjar.path, ctx.outputs.srcjar.path],
)
_gensource = rule( _gensource = rule(
attrs = { attrs = {
@ -69,8 +73,13 @@ _gensource = rule(
implementation = _gensource_impl, implementation = _gensource_impl,
) )
def java_grpc_library(name, srcs, deps, flavor=None, def java_grpc_library(
enable_deprecated=None, visibility=None, name,
srcs,
deps,
flavor = None,
enable_deprecated = None,
visibility = None,
**kwargs): **kwargs):
"""Generates and compiles gRPC Java sources for services defined in a proto """Generates and compiles gRPC Java sources for services defined in a proto
file. This rule is compatible with java_proto_library and java_lite_proto_library. file. This rule is compatible with java_proto_library and java_lite_proto_library.