-
Notifications
You must be signed in to change notification settings - Fork 4k
Adopt proto_lang_toolchain for java_grpc_library() #12994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AgraVator
wants to merge
6
commits into
grpc:master
Choose a base branch
from
AgraVator:adopt-proto-lang-toolchain
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
18c1fb9
Adopt proto_lang_toolchain for java_grpc_library()
AgraVator fa8710e
Address PR feedback: remove dead toolchain code and format with build…
AgraVator c427419
Address PR feedback for proto_lang_toolchain migration
AgraVator 091d318
Load proto_common from @com_google_protobuf instead of @rules_proto
AgraVator cc9151d
Format BUILD files with buildifier
AgraVator 00f4e70
Deduplicate common compilation logic in _java_rpc_library_impl
AgraVator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 | ||
|
|
||
| common:skip_android --deleted_packages=android,binder | ||
| common:skip_android --deleted_packages=android,binder |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| """Build rule for java_grpc_library.""" | ||
|
|
||
| load("@com_google_protobuf//bazel/common:proto_common.bzl", "proto_common") | ||
| load("@com_google_protobuf//bazel/common:proto_info.bzl", "ProtoInfo") | ||
| load("@com_google_protobuf//bazel/common:proto_lang_toolchain_info.bzl", "ProtoLangToolchainInfo") | ||
| load("@rules_java//java:defs.bzl", "JavaInfo", "JavaPluginInfo", "java_common") | ||
|
|
||
| _JavaRpcToolchainInfo = provider( | ||
|
|
@@ -85,39 +87,56 @@ def _java_rpc_library_impl(ctx): | |
| print(("in srcs attribute of {0}: Proto source with label {1} should be in " + | ||
| "same package as consuming rule").format(ctx.label, ctx.attr.srcs[0].label)) | ||
|
|
||
| toolchain = ctx.attr._toolchain[_JavaRpcToolchainInfo] | ||
| srcs = ctx.attr.srcs[0][ProtoInfo].direct_sources | ||
| descriptor_set_in = ctx.attr.srcs[0][ProtoInfo].transitive_descriptor_sets | ||
|
|
||
| srcjar = ctx.actions.declare_file("%s-proto-gensrc.jar" % ctx.label.name) | ||
|
|
||
| args = ctx.actions.args() | ||
| args.add(toolchain.plugin[DefaultInfo].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(srcs, transitive = [descriptor_set_in, toolchain.plugin[DefaultInfo].files]), | ||
| outputs = [srcjar], | ||
| executable = toolchain.protoc[DefaultInfo].files_to_run, | ||
| arguments = [args], | ||
| use_default_shell_env = True, | ||
| toolchain = None, | ||
| ) | ||
| if ProtoLangToolchainInfo in ctx.attr._toolchain: | ||
| toolchain = ctx.attr._toolchain[ProtoLangToolchainInfo] | ||
| proto_common.compile( | ||
| actions = ctx.actions, | ||
| proto_info = ctx.attr.srcs[0][ProtoInfo], | ||
| proto_lang_toolchain_info = toolchain, | ||
| generated_files = [srcjar], | ||
| plugin_output = srcjar.path, | ||
| ) | ||
| java_toolchain = ctx.toolchains["@bazel_tools//tools/jdk:toolchain_type"].java | ||
| java_plugins = [] | ||
| runtime_deps = [toolchain.runtime[JavaInfo]] if toolchain.runtime else [] | ||
| else: | ||
| # Legacy support for java_rpc_toolchain | ||
| toolchain = ctx.attr._toolchain[_JavaRpcToolchainInfo] | ||
| srcs = ctx.attr.srcs[0][ProtoInfo].direct_sources | ||
| descriptor_set_in = ctx.attr.srcs[0][ProtoInfo].transitive_descriptor_sets | ||
|
|
||
| args = ctx.actions.args() | ||
| args.add(toolchain.plugin[DefaultInfo].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(srcs, transitive = [descriptor_set_in, toolchain.plugin[DefaultInfo].files]), | ||
| outputs = [srcjar], | ||
| executable = toolchain.protoc[DefaultInfo].files_to_run, | ||
| arguments = [args], | ||
| use_default_shell_env = True, | ||
| toolchain = None, | ||
| ) | ||
| java_toolchain = toolchain.java_toolchain[java_common.JavaToolchainInfo] | ||
| java_plugins = [plugin[JavaPluginInfo] for plugin in toolchain.java_plugins] | ||
| runtime_deps = [dep[JavaInfo] for dep in toolchain.runtime] | ||
|
|
||
| deps_java_info = java_common.merge([dep[JavaInfo] for dep in ctx.attr.deps]) | ||
|
|
||
| java_info = java_common.compile( | ||
| ctx, | ||
| java_toolchain = toolchain.java_toolchain[java_common.JavaToolchainInfo], | ||
| java_toolchain = java_toolchain, | ||
| source_jars = [srcjar], | ||
| output = ctx.outputs.jar, | ||
| output_source_jar = ctx.outputs.srcjar, | ||
| plugins = [plugin[JavaPluginInfo] for plugin in toolchain.java_plugins], | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like we need to still support this, as there are usages internally. I don't know if that means we need a second toolchain, or what. |
||
| plugins = java_plugins, | ||
| deps = [ | ||
| java_common.make_non_strict(deps_java_info), | ||
| ] + [dep[JavaInfo] for dep in toolchain.runtime], | ||
| ] + runtime_deps, | ||
| ) | ||
|
|
||
| return [java_info] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.