java_grpc_library.bzl: Support runfiles for protoc and the plugin

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
This commit is contained in:
Eric Anderson 2024-01-17 16:46:15 -08:00
parent 75492c8b36
commit 65a6b3bc21
1 changed files with 5 additions and 5 deletions

View File

@ -16,9 +16,9 @@ def _java_rpc_toolchain_impl(ctx):
_JavaRpcToolchainInfo( _JavaRpcToolchainInfo(
java_toolchain = ctx.attr._java_toolchain, java_toolchain = ctx.attr._java_toolchain,
java_plugins = ctx.attr.java_plugins, java_plugins = ctx.attr.java_plugins,
plugin = ctx.executable.plugin, plugin = ctx.attr.plugin,
plugin_arg = ctx.attr.plugin_arg, plugin_arg = ctx.attr.plugin_arg,
protoc = ctx.executable._protoc, protoc = ctx.attr._protoc,
runtime = ctx.attr.runtime, runtime = ctx.attr.runtime,
), ),
platform_common.ToolchainInfo(), # Magic for b/78647825 platform_common.ToolchainInfo(), # Magic for b/78647825
@ -89,15 +89,15 @@ def _java_rpc_library_impl(ctx):
srcjar = ctx.actions.declare_file("%s-proto-gensrc.jar" % ctx.label.name) srcjar = ctx.actions.declare_file("%s-proto-gensrc.jar" % ctx.label.name)
args = ctx.actions.args() 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("--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_joined("--descriptor_set_in", descriptor_set_in, join_with = ctx.configuration.host_path_separator)
args.add_all(srcs, map_each = _path_ignoring_repository) args.add_all(srcs, map_each = _path_ignoring_repository)
ctx.actions.run( ctx.actions.run(
inputs = depset([toolchain.plugin] + srcs, transitive = [descriptor_set_in]), inputs = depset(srcs, transitive = [descriptor_set_in, toolchain.plugin.files]),
outputs = [srcjar], outputs = [srcjar],
executable = toolchain.protoc, executable = toolchain.protoc.files_to_run,
arguments = [args], arguments = [args],
use_default_shell_env = True, use_default_shell_env = True,
toolchain = None, toolchain = None,