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

JVM lockfile invalidation headers and verification #14185

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e5142c3
Adds `JVMLockfileMetadata` and related things
Jan 12, 2022
a274adf
Moves `CoursierResolvedLockfile.from_json_dict` to `.from_serialized`…
Jan 12, 2022
60b3f43
Serializes coursier lockfiles to toml, and adds initial support for r…
Jan 13, 2022
8595016
Generated lockfiles now include invalidation headers
Jan 13, 2022
1536ac9
WIP
Jan 13, 2022
df0c578
Pulls `Coordinate` and `ArtifactRequirements` out into a separate fil…
Jan 13, 2022
3ceac13
Pulls `Coordinate` and `ArtifactRequirements` out into a separate fil…
Jan 13, 2022
31cc4b7
Validate lockfiles in `jvm_tool.py`
Jan 14, 2022
53ffa56
Regenerates tool lockfiles into new toml format
Jan 14, 2022
89b6f18
Validates lockfile headers for google java format
Jan 14, 2022
37c464c
All JVM tools validate their lockfile on setup
Jan 14, 2022
4129ee0
Merge remote-tracking branch 'origin/main' into chrisjrn/13373-jvm-lo…
Jan 14, 2022
0e83cf1
Updates JVM user lockfiles
Jan 14, 2022
b574265
Merge branch 'main' into chrisjrn/13373-jvm-lockfile-invalidation
Jan 18, 2022
49e23b3
Fix the tool lockfile generating code to actually execute
Jan 18, 2022
3c50573
fmt
Jan 18, 2022
3434461
Fix tests
Jan 18, 2022
410c115
Add validation of user lockfiles
Jan 18, 2022
2a43202
Fix tests
Jan 18, 2022
9a6d8fb
Fixmore tests
Jan 18, 2022
622332f
fmt
Jan 18, 2022
65af690
Renames `TCoursierResolvedLockfile` to `CoursierLockfileWrapper`
Jan 19, 2022
647c9f5
Update error message to be less terse/useless
Jan 19, 2022
e987f2e
Updates `is_valid_for` docstring
Jan 19, 2022
fc53b02
simplifies junit_test slightly
Jan 19, 2022
b55f229
fix parenthesisation
Jan 19, 2022
0dc2130
Merge remote-tracking branch 'origin/main' into chrisjrn/13373-jvm-lo…
Jan 19, 2022
858f83e
Address code review floop
Jan 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions 3rdparty/jvm/global_scalac_plugins.lock
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
# This lockfile was autogenerated by Pants. To regenerate, run:
#
# ./pants jvm-generate-lockfiles
#
# --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE ---
# {
# "version": 1,
# "generated_with_requirements": []
# }
# --- END PANTS LOCKFILE METADATA ---
Eric-Arellano marked this conversation as resolved.
Show resolved Hide resolved

entries = []
11 changes: 11 additions & 0 deletions 3rdparty/jvm/testprojects.lockfile
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
# This lockfile was autogenerated by Pants. To regenerate, run:
#
# ./pants generate-lockfiles
#
# --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE ---
# {
# "version": 1,
# "generated_with_requirements": []
# }
# --- END PANTS LOCKFILE METADATA ---

entries = []
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# This lockfile was autogenerated by Pants. To regenerate, run:
#
# ./pants jvm-generate-lockfiles
#
# --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE ---
# {
# "version": 1,
# "generated_with_requirements": [
# "org.apache.avro:avro-tools:1.11.0,url=not_provided,jar=not_provided"
# ]
# }
# --- END PANTS LOCKFILE METADATA ---

[[entries]]
directDependencies = []
dependencies = []
Expand Down
11 changes: 9 additions & 2 deletions src/python/pants/backend/codegen/avro/java/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@
from pants.jvm.goals import lockfile
from pants.jvm.goals.lockfile import JvmLockfileRequest
from pants.jvm.jdk_rules import JdkSetup
from pants.jvm.resolve.coursier_fetch import MaterializedClasspath, MaterializedClasspathRequest
from pants.jvm.resolve.coursier_fetch import (
CoursierResolvedLockfile,
MaterializedClasspath,
MaterializedClasspathRequest,
)
from pants.jvm.resolve.jvm_tool import ValidatedJvmToolLockfileRequest
from pants.source.source_root import SourceRoot, SourceRootRequest
from pants.util.logging import LogLevel

Expand Down Expand Up @@ -98,11 +103,13 @@ async def compile_avro_source(
output_dir = "_generated_files"
toolcp_relpath = "__toolcp"

lockfile = await Get(CoursierResolvedLockfile, ValidatedJvmToolLockfileRequest(avro_tools))

tool_classpath, subsetted_input_digest, empty_output_dir = await MultiGet(
Get(
MaterializedClasspath,
MaterializedClasspathRequest(
lockfiles=(avro_tools.resolved_lockfile(),),
lockfiles=(lockfile,),
),
),
Get(
Expand Down
16 changes: 12 additions & 4 deletions src/python/pants/backend/codegen/protobuf/scala/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@
from pants.jvm.goals.lockfile import JvmLockfileRequest
from pants.jvm.jdk_rules import JdkSetup
from pants.jvm.resolve.common import ArtifactRequirements, Coordinate
from pants.jvm.resolve.coursier_fetch import MaterializedClasspath, MaterializedClasspathRequest
from pants.jvm.resolve.jvm_tool import GatherJvmCoordinatesRequest
from pants.jvm.resolve.coursier_fetch import (
CoursierResolvedLockfile,
MaterializedClasspath,
MaterializedClasspathRequest,
)
from pants.jvm.resolve.jvm_tool import GatherJvmCoordinatesRequest, ValidatedJvmToolLockfileRequest
from pants.source.source_root import SourceRoot, SourceRootRequest
from pants.util.logging import LogLevel
from pants.util.ordered_set import FrozenOrderedSet
Expand Down Expand Up @@ -112,6 +116,8 @@ async def generate_scala_from_protobuf(
plugins_relpath = "__plugins"
protoc_relpath = "__protoc"

lockfile = await Get(CoursierResolvedLockfile, ValidatedJvmToolLockfileRequest(scalapb))

(
downloaded_protoc_binary,
tool_classpath,
Expand All @@ -123,7 +129,7 @@ async def generate_scala_from_protobuf(
Get(
MaterializedClasspath,
MaterializedClasspathRequest(
lockfiles=(scalapb.resolved_lockfile(),),
lockfiles=(lockfile,),
),
),
Get(Digest, CreateDigest([Directory(output_dir)])),
Expand Down Expand Up @@ -279,6 +285,8 @@ async def setup_scalapb_shim_classfiles(

scalapb_shim_source = FileContent("ScalaPBShim.scala", scalapb_shim_content)

lockfile = await Get(CoursierResolvedLockfile, ValidatedJvmToolLockfileRequest(scalapb))

tool_classpath, shim_classpath, source_digest = await MultiGet(
Get(
MaterializedClasspath,
Expand Down Expand Up @@ -311,7 +319,7 @@ async def setup_scalapb_shim_classfiles(
MaterializedClasspath,
MaterializedClasspathRequest(
prefix="__shimcp",
lockfiles=(scalapb.resolved_lockfile(),),
lockfiles=(lockfile,),
),
),
Get(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# This lockfile was autogenerated by Pants. To regenerate, run:
#
# ./pants jvm-generate-lockfiles
#
# --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE ---
# {
# "version": 1,
# "generated_with_requirements": [
# "com.thesamet.scalapb:scalapbc_2.13:0.11.6,url=not_provided,jar=not_provided"
# ]
# }
# --- END PANTS LOCKFILE METADATA ---

[[entries]]
file_name = "com.chuusai_shapeless_2.13_2.3.3.jar"
[[entries.directDependencies]]
Expand Down
11 changes: 9 additions & 2 deletions src/python/pants/backend/codegen/thrift/scrooge/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
from pants.jvm.goals import lockfile
from pants.jvm.goals.lockfile import JvmLockfileRequest
from pants.jvm.jdk_rules import JdkSetup
from pants.jvm.resolve.coursier_fetch import MaterializedClasspath, MaterializedClasspathRequest
from pants.jvm.resolve.coursier_fetch import (
CoursierResolvedLockfile,
MaterializedClasspath,
MaterializedClasspathRequest,
)
from pants.jvm.resolve.jvm_tool import ValidatedJvmToolLockfileRequest
from pants.source.source_root import SourceRootsRequest, SourceRootsResult
from pants.util.logging import LogLevel

Expand Down Expand Up @@ -49,11 +54,13 @@ async def generate_scrooge_thrift_sources(
output_dir = "_generated_files"
toolcp_relpath = "__toolcp"

lockfile = await Get(CoursierResolvedLockfile, ValidatedJvmToolLockfileRequest(scrooge))

tool_classpath, transitive_targets, empty_output_dir_digest, wrapped_target = await MultiGet(
Get(
MaterializedClasspath,
MaterializedClasspathRequest(
lockfiles=(scrooge.resolved_lockfile(),),
lockfiles=(lockfile,),
),
),
Get(TransitiveTargets, TransitiveTargetsRequest([request.thrift_source_field.address])),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# This lockfile was autogenerated by Pants. To regenerate, run:
#
# ./pants jvm-generate-lockfiles
#
# --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE ---
# {
# "version": 1,
# "generated_with_requirements": [
# "com.twitter:scrooge-generator_2.13:21.12.0,url=not_provided,jar=not_provided"
# ]
# }
# --- END PANTS LOCKFILE METADATA ---

[[entries]]
file_name = "com.github.scopt_scopt_2.13_4.0.0-RC2.jar"
[[entries.directDependencies]]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# This lockfile was autogenerated by Pants. To regenerate, run:
#
# ./pants generate-lockfiles
#
# --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE ---
# {
# "version": 1,
# "generated_with_requirements": [
# "com.fasterxml.jackson.core:jackson-databind:2.12.4,url=not_provided,jar=not_provided",
# "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.12.4,url=not_provided,jar=not_provided",
# "com.github.javaparser:javaparser-symbol-solver-core:3.23.0,url=not_provided,jar=not_provided"
# ]
# }
# --- END PANTS LOCKFILE METADATA ---

[[entries]]
directDependencies = []
dependencies = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# This lockfile was autogenerated by Pants. To regenerate, run:
#
# ./pants jvm-generate-lockfiles
#
# --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE ---
# {
# "version": 1,
# "generated_with_requirements": [
# "com.google.googlejavaformat:google-java-format:1.13.0,url=not_provided,jar=not_provided"
# ]
# }
# --- END PANTS LOCKFILE METADATA ---

[[entries]]
directDependencies = []
dependencies = []
Expand Down
15 changes: 13 additions & 2 deletions src/python/pants/backend/java/lint/google_java_format/rules.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
import dataclasses
import logging
from dataclasses import dataclass

from pants.backend.java.lint.google_java_format.skip_field import SkipGoogleJavaFormatField
Expand All @@ -19,10 +20,17 @@
from pants.jvm.goals import lockfile
from pants.jvm.goals.lockfile import JvmLockfileRequest
from pants.jvm.jdk_rules import JdkSetup
from pants.jvm.resolve.coursier_fetch import MaterializedClasspath, MaterializedClasspathRequest
from pants.jvm.resolve.coursier_fetch import (
CoursierResolvedLockfile,
MaterializedClasspath,
MaterializedClasspathRequest,
)
from pants.jvm.resolve.jvm_tool import ValidatedJvmToolLockfileRequest
from pants.util.logging import LogLevel
from pants.util.strutil import pluralize

logger = logging.getLogger(__name__)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: not necessary



@dataclass(frozen=True)
class GoogleJavaFormatFieldSet(FieldSet):
Expand Down Expand Up @@ -62,6 +70,9 @@ async def setup_google_java_format(
jdk_setup: JdkSetup,
bash: BashBinary,
) -> Setup:

lockfile = await Get(CoursierResolvedLockfile, ValidatedJvmToolLockfileRequest(tool))

source_files, tool_classpath = await MultiGet(
Get(
SourceFiles,
Expand All @@ -70,7 +81,7 @@ async def setup_google_java_format(
Get(
MaterializedClasspath,
MaterializedClasspathRequest(
lockfiles=(tool.resolved_lockfile(),),
lockfiles=(lockfile,),
Comment on lines -73 to +84
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh huh, this was violating the engine by using open() inside lockfile_content

),
),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# This lockfile was autogenerated by Pants. To regenerate, run:
#
# ./pants generate-lockfiles
#
# --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE ---
# {
# "version": 1,
# "generated_with_requirements": [
# "io.circe:circe-generic_2.13:0.14.1,url=not_provided,jar=not_provided",
# "org.scalameta:scalameta_2.13:4.4.30,url=not_provided,jar=not_provided"
# ]
# }
# --- END PANTS LOCKFILE METADATA ---

[[entries]]
file_name = "com.chuusai_shapeless_2.13_2.3.7.jar"
[[entries.directDependencies]]
Expand Down
12 changes: 10 additions & 2 deletions src/python/pants/backend/scala/lint/scalafmt/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
from pants.jvm.goals import lockfile
from pants.jvm.goals.lockfile import JvmLockfileRequest
from pants.jvm.jdk_rules import JdkSetup
from pants.jvm.resolve.coursier_fetch import MaterializedClasspath, MaterializedClasspathRequest
from pants.jvm.resolve.coursier_fetch import (
CoursierResolvedLockfile,
MaterializedClasspath,
MaterializedClasspathRequest,
)
from pants.jvm.resolve.jvm_tool import ValidatedJvmToolLockfileRequest
from pants.util.frozendict import FrozenDict
from pants.util.logging import LogLevel
from pants.util.strutil import pluralize
Expand Down Expand Up @@ -197,6 +202,9 @@ async def setup_scalafmt(
bash: BashBinary,
) -> Setup:
toolcp_relpath = "__toolcp"

lockfile = await Get(CoursierResolvedLockfile, ValidatedJvmToolLockfileRequest(tool))

source_files, tool_classpath = await MultiGet(
Get(
SourceFiles,
Expand All @@ -205,7 +213,7 @@ async def setup_scalafmt(
Get(
MaterializedClasspath,
MaterializedClasspathRequest(
lockfiles=(tool.resolved_lockfile(),),
lockfiles=(lockfile,),
),
),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# This lockfile was autogenerated by Pants. To regenerate, run:
#
# ./pants jvm-generate-lockfiles
#
# --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE ---
# {
# "version": 1,
# "generated_with_requirements": [
# "org.scalameta:scalafmt-cli_2.13:3.2.1,url=not_provided,jar=not_provided"
# ]
# }
# --- END PANTS LOCKFILE METADATA ---

[[entries]]
file_name = "com.geirsson_metaconfig-core_2.13_0.9.15.jar"
[[entries.directDependencies]]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# This lockfile was autogenerated by Pants. To regenerate, run:
#
# ./pants jvm-generate-lockfiles
#
# --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE ---
# {
# "version": 1,
# "generated_with_requirements": [
# "org.scalatest:scalatest_2.13:3.2.10,url=not_provided,jar=not_provided"
# ]
# }
# --- END PANTS LOCKFILE METADATA ---

[[entries]]
file_name = "org.scala-lang.modules_scala-xml_2.13_1.3.0.jar"
[[entries.directDependencies]]
Expand Down
12 changes: 10 additions & 2 deletions src/python/pants/backend/scala/test/scalatest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
from pants.jvm.goals import lockfile
from pants.jvm.goals.lockfile import JvmLockfileRequest
from pants.jvm.jdk_rules import JdkSetup
from pants.jvm.resolve.coursier_fetch import MaterializedClasspath, MaterializedClasspathRequest
from pants.jvm.resolve.coursier_fetch import (
CoursierResolvedLockfile,
MaterializedClasspath,
MaterializedClasspathRequest,
)
from pants.jvm.resolve.jvm_tool import ValidatedJvmToolLockfileRequest
from pants.jvm.subsystems import JvmSubsystem
from pants.util.logging import LogLevel

Expand Down Expand Up @@ -63,11 +68,14 @@ async def setup_scalatest_for_target(
scalatest: Scalatest,
test_subsystem: TestSubsystem,
) -> TestSetup:

lockfile = await Get(CoursierResolvedLockfile, ValidatedJvmToolLockfileRequest(scalatest))

classpath, scalatest_classpath = await MultiGet(
Get(Classpath, Addresses([request.field_set.address])),
Get(
MaterializedClasspath,
MaterializedClasspathRequest(lockfiles=(scalatest.resolved_lockfile(),)),
MaterializedClasspathRequest(lockfiles=(lockfile,)),
),
)

Expand Down
1 change: 1 addition & 0 deletions src/python/pants/core/util_rules/lockfile_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@


class LockfileScope(Enum):
JVM = "jvm"
PYTHON = "python"
Comment on lines 18 to 20
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

@Eric-Arellano : Not a blocker for this change, but this seems like something that should be computed from one of the @unions involved here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe which metadata class to create when generating a lockfile, but nothing else.



Expand Down
Loading