Skip to content

Commit

Permalink
java_grpc_library.bzl: Support runfiles for protoc and the plugin
Browse files Browse the repository at this point in the history
To support runfiles, the rule has to track more than just the
executable. `files_to_run` has both the runfile and executable
information (as separate fields), as does `files`, (combined as depset).
So using those when able is inherently "safe." `files_to_run.executable`
is only the executable, so does not propagate dependency information,
so we make sure to pass `files` to the rule in addition.
(`files_to_run.executable` is formatted into a string, so it wouldn't
carry depset information anyway.)

As originally noticed in cl/597962426
  • Loading branch information
ejona86 committed Jan 20, 2024
1 parent 75492c8 commit 65a6b3b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions java_grpc_library.bzl
Expand Up @@ -16,9 +16,9 @@ def _java_rpc_toolchain_impl(ctx):
_JavaRpcToolchainInfo(
java_toolchain = ctx.attr._java_toolchain,
java_plugins = ctx.attr.java_plugins,
plugin = ctx.executable.plugin,
plugin = ctx.attr.plugin,
plugin_arg = ctx.attr.plugin_arg,
protoc = ctx.executable._protoc,
protoc = ctx.attr._protoc,
runtime = ctx.attr.runtime,
),
platform_common.ToolchainInfo(), # Magic for b/78647825
Expand Down Expand Up @@ -89,15 +89,15 @@ def _java_rpc_library_impl(ctx):
srcjar = ctx.actions.declare_file("%s-proto-gensrc.jar" % ctx.label.name)

args = ctx.actions.args()
args.add(toolchain.plugin, format = "--plugin=protoc-gen-rpc-plugin=%s")
args.add(toolchain.plugin.files_to_run.executable, format = "--plugin=protoc-gen-rpc-plugin=%s")
args.add("--rpc-plugin_out={0}:{1}".format(toolchain.plugin_arg, srcjar.path))
args.add_joined("--descriptor_set_in", descriptor_set_in, join_with = ctx.configuration.host_path_separator)
args.add_all(srcs, map_each = _path_ignoring_repository)

ctx.actions.run(
inputs = depset([toolchain.plugin] + srcs, transitive = [descriptor_set_in]),
inputs = depset(srcs, transitive = [descriptor_set_in, toolchain.plugin.files]),
outputs = [srcjar],
executable = toolchain.protoc,
executable = toolchain.protoc.files_to_run,
arguments = [args],
use_default_shell_env = True,
toolchain = None,
Expand Down

0 comments on commit 65a6b3b

Please sign in to comment.