Skip to content
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

Add support for multiple compile/testing JDKs #14421

Merged
merged 34 commits into from Feb 11, 2022

Conversation

chrisjrn
Copy link
Contributor

@chrisjrn chrisjrn commented Feb 9, 2022

This adds support for a jdk_version on all JVM source targets as well as deploy_jar. Supply --jvm-default-source-jdk to set a default for the jdk_version field -- currently we also fall back to --jvm-jdk, but this is deprecated and will be removed presently.

Needs: tests

There's a bit more work than I'd like to support validating that a deploy_jar is run with an acceptable JDK version, so deferring that for a follow-up.

Christopher Neugebauer added 12 commits February 7, 2022 08:51
…mits

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
[ci skip-rust]

[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]
… sources

[ci skip-rust] [ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@chrisjrn chrisjrn requested a review from stuhood February 9, 2022 23:52
@chrisjrn chrisjrn marked this pull request as draft February 9, 2022 23:57
@chrisjrn chrisjrn changed the title Chrisjrn/13995 multiple jdks take 2 WIP Support multiple JDKs Feb 9, 2022
src/python/pants/backend/codegen/protobuf/scala/rules.py Outdated Show resolved Hide resolved
src/python/pants/backend/java/target_types.py Outdated Show resolved Hide resolved
src/python/pants/jvm/jdk_rules.py Outdated Show resolved Hide resolved
src/python/pants/jvm/jdk_rules.py Outdated Show resolved Hide resolved
Comment on lines 340 to 341
# TODO: verify that we're requesting the same JDK version for all `ct` members?
t = ct.representative
Copy link
Sponsor Member

@stuhood stuhood Feb 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea. This validation could maybe move into ClasspathEntryRequest, and then become a field of ClasspathEntryRequest? Not a blocker though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I think I'd decided on CoarsenedTarget before I knew where JDK selection would be necessary. I'll see if I can refactor that appropriately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stuhood I think the validation side of things will require ClasspathEntryRequest.for_targets to be re-written as a rule (or further complicated by accepting more singleton arguments) to resolve the JDK at construction time. If you're OK with that, I can do that in a separate PR before landing this?

src/python/pants/jvm/subsystems.py Outdated Show resolved Hide resolved
Christopher Neugebauer added 6 commits February 10, 2022 08:24
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
…get`

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@chrisjrn
Copy link
Contributor Author

Requesting a full review now (working on tests in the meantime). Supporting validation/erroring out in the right place is going to take a bit more work than I'd like, and I'd rather land the overall support.

@chrisjrn chrisjrn marked this pull request as ready for review February 10, 2022 19:53
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]

@dataclass(frozen=True)
class Nailgun:
classpath_entry: ClasspathEntry


@dataclass(frozen=True)
class JdkForClasspathRequest:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could -- theoretically -- get folded into JdkRequest, but I feel like that's going to overcomplicate things further

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(commented on the topic elsewhere before seeing this)

@chrisjrn chrisjrn changed the title WIP Support multiple JDKs Add support for multiple compile/testing JDKs Feb 10, 2022
Copy link
Sponsor Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! One blocking issue here for the repl goal. I also think that we should swap up the option names.

Comment on lines 338 to 349
@rule
async def jdk_request_for_classpath(request: JdkForClasspathRequest) -> JdkRequest:

# TODO: verify that we're requesting the same JDK version for all `ct` members?
t = request.cper.component.representative

if not t.has_field(JvmJdkField):
raise ValueError(f"Cannot construct a JDK request for a non-JVM target {t}")

field = t[JvmJdkField]

return JdkRequest(field)
Copy link
Sponsor Member

@stuhood stuhood Feb 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule is overly coarse I think (and possibly worth fixing before landing): the request will be different for every CoarsenedTarget, even though all the rule is going to consume is a single field.

I'd suggest moving the body of this @rule into a static method of JdkRequest that constructs a JdkRequest from a CoarsenedTarget. Alternatively, keep the JdkForClasspathRequest type and move the body to static method there. Either way, that should reduce the number of times this rule runs to "once per distinct field value".

src/python/pants/backend/scala/goals/repl.py Outdated Show resolved Hide resolved

@dataclass(frozen=True)
class Nailgun:
classpath_entry: ClasspathEntry


@dataclass(frozen=True)
class JdkForClasspathRequest:
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(commented on the topic elsewhere before seeing this)

src/python/pants/jvm/jdk_rules.py Outdated Show resolved Hide resolved
src/python/pants/jvm/jdk_rules.py Outdated Show resolved Hide resolved
src/python/pants/jvm/subsystems.py Outdated Show resolved Hide resolved
chrisjrn and others added 4 commits February 10, 2022 15:50
Co-authored-by: Stu Hood <stuhood@gmail.com>
Co-authored-by: Stu Hood <stuhood@gmail.com>
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
[ci skip-rust]

[ci skip-build-wheels]
Copy link
Contributor Author

@chrisjrn chrisjrn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This addresses the two most egregious issues; I'll work on efficiency as a fast-follow for this.

Copy link
Sponsor Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

src/python/pants/backend/java/compile/javac_test.py Outdated Show resolved Hide resolved
src/python/pants/jvm/subsystems.py Outdated Show resolved Hide resolved
src/python/pants/jvm/subsystems.py Outdated Show resolved Hide resolved
chrisjrn and others added 5 commits February 10, 2022 17:25
Co-authored-by: Stu Hood <stuhood@gmail.com>
Co-authored-by: Stu Hood <stuhood@gmail.com>
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
…le-jdks-take-2

[ci skip-rust]

[ci skip-build-wheels]
@stuhood stuhood enabled auto-merge (squash) February 11, 2022 05:41
stuhood added a commit to stuhood/example-jvm that referenced this pull request Feb 11, 2022
@stuhood
Copy link
Sponsor Member

stuhood commented Feb 11, 2022

@chrisjrn : It looks like your test failures are likely a collision with the second commit in #14441... sorry about that. In short: "target generator" types like java_sources no longer keep their resolve field: it's moved to the targets that they generate. To account for that, that commit adjusted things to ignore targets which don't have a resolve field, rather than failing.

stuhood added a commit to stuhood/example-jvm that referenced this pull request Feb 11, 2022
# Conflicts:
#	src/python/pants/backend/java/target_types.py
#	src/python/pants/backend/scala/target_types.py

# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@chrisjrn
Copy link
Contributor Author

@stuhood Looks like the tests pass again once we treat jdk as a copied_field rather than a moved_field. AIUI, copied_field behaviour is what we previously had before the adjustment in #14441, so that's probably fine.

Let's address whether it should be made a moved_field once I start work on validation.

Christopher Neugebauer added 4 commits February 11, 2022 08:23
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
…ake-2' into chrisjrn/13995-take-3

[ci skip-rust]

[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@stuhood stuhood merged commit aae56a6 into pantsbuild:main Feb 11, 2022
@chrisjrn chrisjrn deleted the chrisjrn/13995-multiple-jdks-take-2 branch February 11, 2022 20:23
chrisjrn pushed a commit that referenced this pull request Feb 11, 2022
Previously we were constructing a `JdkEnvironment` for every instance of `JvmJdkField` rather than caching by version. This refactors `JdkRequest` to no longer store a field, and instead, always store a version string or magic constant.

This should reduce the number of times we download a JDK.

(Fast-follow for #14421, addresses #13995)
@stuhood
Copy link
Sponsor Member

stuhood commented Feb 16, 2022

Let's address whether it should be made a moved_field once I start work on validation.

It should be a moved field, as that's necessary for parametrize (which is also why the changes were made in #14441). This is probably why @tdyas wasn't able to get pantsbuild/example-jvm#10 to work.

stuhood added a commit to stuhood/example-jvm that referenced this pull request Mar 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants