Repository navigation
fix: resolve a JDK only for JRuby toolchains #461
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
TrapsterDK
wants to merge
3
commits into
bazel-contrib:main
Choose a base branch
from
TrapsterDK:fix/optional-java-runtime
base: main
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
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
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
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
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
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 |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ load( | |
| _convert_env_to_script = "convert_env_to_script", | ||
| _is_windows = "is_windows", | ||
| _normalize_path = "normalize_path", | ||
| _require_java_runtime = "require_java_runtime", | ||
| _resolve_bundle_build_env = "resolve_bundle_build_env", | ||
| ) | ||
|
|
||
|
|
@@ -25,9 +26,9 @@ def _rb_gem_install_impl(ctx): | |
| tools.extend(toolchain.files) | ||
|
|
||
| if toolchain.version.startswith("jruby"): | ||
| java_toolchain = ctx.exec_groups["ruby"].toolchains["@bazel_tools//tools/jdk:runtime_toolchain_type"] | ||
| tools.extend(java_toolchain.java_runtime.files.to_list()) | ||
| env.update({"JAVA_HOME": java_toolchain.java_runtime.java_home}) | ||
| java_runtime = _require_java_runtime(toolchain) | ||
| tools.extend(java_runtime.files.to_list()) | ||
| env.update({"JAVA_HOME": java_runtime.java_home}) | ||
|
|
||
| if _is_windows(ctx): | ||
| gem_install = ctx.actions.declare_file("gem_install_{}.cmd".format(ctx.label.name)) | ||
|
|
@@ -95,10 +96,7 @@ rb_gem_install = rule( | |
| }, | ||
| # JRuby runs Ruby and Java tools in the same action, on the same platform. | ||
| exec_groups = { | ||
| "ruby": exec_group(toolchains = [ | ||
|
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. Ditto. |
||
| "@rules_ruby//ruby:toolchain_type", | ||
| "@bazel_tools//tools/jdk:runtime_toolchain_type", | ||
| ]), | ||
| "ruby": exec_group(toolchains = ["@rules_ruby//ruby:toolchain_type"]), | ||
| }, | ||
| doc = """ | ||
| Installs a built Ruby gem. | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -2,11 +2,14 @@ | |
|
|
||
| load("//ruby/private:binary.bzl", "generate_rb_binary_script", BINARY_ATTRS = "ATTRS") | ||
| load("//ruby/private:library.bzl", LIBRARY_ATTRS = "ATTRS") | ||
| load("//ruby/private:utils.bzl", _to_rlocation_path = "to_rlocation_path") | ||
| load( | ||
| "//ruby/private:utils.bzl", | ||
| _require_java_runtime = "require_java_runtime", | ||
| _to_rlocation_path = "to_rlocation_path", | ||
| ) | ||
|
|
||
| def _rb_gem_push_impl(ctx): | ||
| env = {} | ||
| java_toolchain = ctx.toolchains["@bazel_tools//tools/jdk:runtime_toolchain_type"] | ||
| ruby_toolchain = ctx.toolchains["@rules_ruby//ruby:toolchain_type"] | ||
| if ctx.attr.ruby != None: | ||
| ruby_toolchain = ctx.attr.ruby[platform_common.ToolchainInfo] | ||
|
|
@@ -16,8 +19,9 @@ def _rb_gem_push_impl(ctx): | |
| java_bin = "" | ||
|
|
||
| if ruby_toolchain.version.startswith("jruby"): | ||
| tools.extend(java_toolchain.java_runtime.files.to_list()) | ||
| java_bin = java_toolchain.java_runtime.java_executable_runfiles_path[3:] | ||
| java_runtime = _require_java_runtime(ruby_toolchain) | ||
| tools.extend(java_runtime.files.to_list()) | ||
| java_bin = java_runtime.java_executable_runfiles_path[3:] | ||
|
|
||
| env.update(ruby_toolchain.env) | ||
| env.update(ctx.attr.env) | ||
|
|
@@ -69,7 +73,6 @@ Gem file to push to RubyGems. You would usually use an output of `rb_gem_build() | |
| ), | ||
| toolchains = [ | ||
| "@rules_ruby//ruby:toolchain_type", | ||
| "@bazel_tools//tools/jdk:runtime_toolchain_type", | ||
|
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. Ditto. |
||
| ], | ||
| doc = """ | ||
| Pushes a built Ruby gem. | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -16,7 +16,6 @@ rb_test = rule( | |
| ), | ||
| toolchains = [ | ||
| "@rules_ruby//ruby:toolchain_type", | ||
| "@bazel_tools//tools/jdk:runtime_toolchain_type", | ||
|
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. Ditto. |
||
| ], | ||
| doc = """ | ||
| Runs a Ruby test. | ||
|
|
||
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
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 |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| """Analysis tests for the Java runtime of Ruby toolchains.""" | ||
|
|
||
| load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") | ||
| load("//ruby:toolchain.bzl", "rb_toolchain") | ||
| load("//ruby/private:utils.bzl", "require_java_runtime") | ||
|
|
||
| def _subject_impl(ctx): | ||
| require_java_runtime(ctx.attr.toolchain[platform_common.ToolchainInfo]) | ||
| return [] | ||
|
|
||
| _subject = rule( | ||
| implementation = _subject_impl, | ||
| attrs = {"toolchain": attr.label(providers = [platform_common.ToolchainInfo])}, | ||
| ) | ||
|
|
||
| def _missing_java_runtime_test_impl(ctx): | ||
| env = analysistest.begin(ctx) | ||
| asserts.expect_failure(env, "has no `java_runtime`; set `java_runtime` on its rb_toolchain()") | ||
| return analysistest.end(env) | ||
|
|
||
| _missing_java_runtime_test = analysistest.make(_missing_java_runtime_test_impl, expect_failure = True) | ||
|
|
||
| def java_runtime_test_suite(name): | ||
| rb_toolchain( | ||
| name = name + "_toolchain", | ||
| ruby = "java_runtime_tests.bzl", | ||
| version = "jruby-10.1.2.0", | ||
| tags = ["manual"], | ||
| ) | ||
| _subject( | ||
| name = name + "_subject", | ||
| toolchain = ":" + name + "_toolchain", | ||
| tags = ["manual"], | ||
| ) | ||
| _missing_java_runtime_test( | ||
| name = name + "_missing_test", | ||
| target_under_test = ":" + name + "_subject", | ||
| ) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might still need both toolchains, otherwise it could fail on RBE, see comment above.