Skip to content

Commit

Permalink
feat: Support extra plugin_args for php bazel rules rules (#3165)
Browse files Browse the repository at this point in the history
  • Loading branch information
vam-google committed Apr 9, 2020
1 parent f3e5a70 commit 1f91fbb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 5 additions & 3 deletions gapic.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,21 @@ def _proto_custom_library_impl(ctx):
calculated_args = []
tools = []
plugin = ctx.executable.plugin
plugin_file_args = []

if plugin:
tools.append(plugin)
plugin_file_args = []
for t, k in ctx.attr.plugin_file_args.items():
for f in t.files.to_list():
extra_inputs.append(f)
plugin_file_args.append("%s=%s" % (k, f.path) if k else f.path)
if ctx.attr.plugin_args or plugin_file_args:
output_paths.insert(0, ",".join(ctx.attr.plugin_args + plugin_file_args))
calculated_args = [
"--plugin=protoc-gen-%s=%s" % (output_type, plugin.path),
]

if ctx.attr.plugin_args or plugin_file_args:
output_paths.insert(0, ",".join(ctx.attr.plugin_args + plugin_file_args))

calculated_args.append("%s=%s" % (output_type_name, ":".join(output_paths)))
arguments = \
ctx.attr.extra_args + \
Expand Down
7 changes: 4 additions & 3 deletions php/php_gapic.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,29 @@

load("//rules_gapic:gapic.bzl", "gapic_srcjar", "proto_custom_library")

def php_proto_library(name, deps, **kwargs):
def php_proto_library(name, deps, plugin_args = [], **kwargs):
srcjar_target_name = name
proto_custom_library(
name = srcjar_target_name,
deps = deps,
output_type = "php",
output_suffix = ".srcjar",
plugin_args = plugin_args,
extra_args = [
"--include_source_info",
],
**kwargs
)

def php_grpc_library(name, srcs, deps, **kwargs):
def php_grpc_library(name, srcs, deps, plugin_args = [], **kwargs):
srcjar_target_name = name

# `deps` is not used now but may be used if php_grpc_library ever tries to "compile" its output
proto_custom_library(
name = srcjar_target_name,
deps = srcs,
plugin = Label("@com_github_grpc_grpc//src/compiler:grpc_php_plugin"),
plugin_args = ["class_suffix=GrpcClient"],
plugin_args = ["class_suffix=GrpcClient"] + plugin_args,
output_type = "grpc",
output_suffix = ".srcjar",
extra_args = [
Expand Down

0 comments on commit 1f91fbb

Please sign in to comment.