-
Notifications
You must be signed in to change notification settings - Fork 275
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
Allow per-target java runtime selection for scala_junit_tests #1373
Conversation
…ain to be used to run tests
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). For more information, open the CLA check for this pull request. |
scala/private/rule_impls.bzl
Outdated
@@ -166,8 +166,20 @@ def compile_java(ctx, source_jars, source_files, output, extra_javac_opts, provi | |||
def runfiles_root(ctx): | |||
return "${TEST_SRCDIR}/%s" % ctx.workspace_name | |||
|
|||
def specified_java_runtime(ctx, default_runtime): |
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.
def specified_java_runtime(ctx, default_runtime): | |
def specified_java_runtime(ctx, default_runtime=None): |
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.
so caller don't need to call with None
also would be good make sure the return value isn't None.
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.
Thanks. Looks reasonable.
Is this already 4 & 5 compatible, or is it going to break one? At the moment we probably need a compatible solution.
scala/private/rule_impls.bzl
Outdated
@@ -166,8 +166,20 @@ def compile_java(ctx, source_jars, source_files, output, extra_javac_opts, provi | |||
def runfiles_root(ctx): | |||
return "${TEST_SRCDIR}/%s" % ctx.workspace_name | |||
|
|||
def specified_java_runtime(ctx, default_runtime): |
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.
so caller don't need to call with None
also would be good make sure the return value isn't None.
Also we should probably add this new field to https://github.com/bazelbuild/rules_scala/blob/master/docs/scala_test.md when this is functionality good. |
Our original version was Bazel 5 only, but we reworked it to be 4 and 5 compat. |
LGTM! @wiwa please fix linter errors by running Has this improvement been tested on any other codebase than rules scala itself? |
Yes, it works for our use case! |
We only add the |
Yes, it's easier to review smaller PRs |
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.
Thanks, @wiwa!
Hi @wiwa , probably I'm too late but gonna ask anyway. Have you considered adding |
Hi @simuons, this is still a good question. There's a few reasons. Here is a couple of major ones:
|
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.
@wiwa thanks for PR
@wisechengyi thanks for explanation.
Description
Add an
attr
(runtime_jdk
) toscala_junit_tests
to specify the version of Java to run with viaJavaRuntimeInfo
.Adapt
java_bin()
andphase_default_info
to pick up the runtime and add its runfiles.Motivation
This change allows users to test their code on different Java versions before having to adapt their code to compile with those versions.
Our specific use case is to test and run code on the JDK it will be deployed onto, supporting a smoother migration from older versions.