From 65a6b3bc218250d0fc90ba1e1b025c426f8a9314 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Wed, 17 Jan 2024 16:46:15 -0800 Subject: [PATCH] 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 --- java_grpc_library.bzl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/java_grpc_library.bzl b/java_grpc_library.bzl index 9cc37f443e6..22487954aef 100644 --- a/java_grpc_library.bzl +++ b/java_grpc_library.bzl @@ -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 @@ -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,