Skip to content

Commit

Permalink
JVM lockfile invalidation headers and verification (#14185)
Browse files Browse the repository at this point in the history
This adds support for JVM lockfile invalidation headers. Most of the infrastructure is shared with the equivalent Python support code.

Closes #13373
  • Loading branch information
Christopher Neugebauer authored Jan 19, 2022
1 parent 9e763a5 commit e771911
Show file tree
Hide file tree
Showing 30 changed files with 623 additions and 174 deletions.
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 generate-lockfiles
#
# --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE ---
# {
# "version": 1,
# "generated_with_requirements": []
# }
# --- END PANTS LOCKFILE METADATA ---

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 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, JvmLockfileRequestFromTool
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, JvmLockfileRequestFromTool
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 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, JvmLockfileRequestFromTool
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 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
54 changes: 19 additions & 35 deletions src/python/pants/backend/java/compile/javac_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
from pants.jvm import jdk_rules, testutil
from pants.jvm.compile import ClasspathEntry, CompileResult, FallibleClasspathEntry
from pants.jvm.goals.coursier import rules as coursier_rules
from pants.jvm.resolve.common import Coordinate, Coordinates
from pants.jvm.resolve.coursier_fetch import CoursierLockfileEntry, CoursierResolvedLockfile
from pants.jvm.resolve.common import ArtifactRequirement, Coordinate, Coordinates
from pants.jvm.resolve.coursier_fetch import CoursierLockfileEntry
from pants.jvm.resolve.coursier_fetch import rules as coursier_fetch_rules
from pants.jvm.resolve.coursier_setup import rules as coursier_setup_rules
from pants.jvm.resolve.coursier_test_util import TestCoursierWrapper
from pants.jvm.target_types import JvmArtifactTarget
from pants.jvm.testutil import (
RenderedClasspath,
Expand Down Expand Up @@ -103,9 +104,7 @@ def test_compile_no_deps(rule_runner: RuleRunner) -> None:
rule_runner.write_files(
{
"BUILD": "java_sources(name='lib')",
"3rdparty/jvm/default.lock": CoursierResolvedLockfile(entries=())
.to_serialized()
.decode(),
"3rdparty/jvm/default.lock": TestCoursierWrapper.new(entries=()).serialize(),
"ExampleLib.java": JAVA_LIB_SOURCE,
}
)
Expand Down Expand Up @@ -145,9 +144,7 @@ def test_compile_jdk_versions(rule_runner: RuleRunner) -> None:
)
"""
),
"3rdparty/jvm/default.lock": CoursierResolvedLockfile(entries=())
.to_serialized()
.decode(),
"3rdparty/jvm/default.lock": TestCoursierWrapper.new(entries=()).serialize(),
"ExampleLib.java": JAVA_LIB_SOURCE,
}
)
Expand Down Expand Up @@ -182,9 +179,7 @@ def test_compile_multiple_source_files(rule_runner: RuleRunner) -> None:
)
"""
),
"3rdparty/jvm/default.lock": CoursierResolvedLockfile(entries=())
.to_serialized()
.decode(),
"3rdparty/jvm/default.lock": TestCoursierWrapper.new(entries=()).serialize(),
"ExampleLib.java": JAVA_LIB_SOURCE,
"OtherLib.java": dedent(
"""\
Expand Down Expand Up @@ -262,9 +257,7 @@ def test_compile_with_cycle(rule_runner: RuleRunner) -> None:
"""\
"""
),
"3rdparty/jvm/default.lock": CoursierResolvedLockfile(entries=())
.to_serialized()
.decode(),
"3rdparty/jvm/default.lock": TestCoursierWrapper.new(entries=()).serialize(),
"a/BUILD": dedent(
"""\
java_sources(
Expand Down Expand Up @@ -350,9 +343,7 @@ def test_compile_with_transitive_cycle(rule_runner: RuleRunner) -> None:
public class Main implements A {}
"""
),
"3rdparty/jvm/default.lock": CoursierResolvedLockfile(entries=())
.to_serialized()
.decode(),
"3rdparty/jvm/default.lock": TestCoursierWrapper.new(entries=()).serialize(),
"a/BUILD": dedent(
"""\
java_sources(
Expand Down Expand Up @@ -436,9 +427,7 @@ def test_compile_with_transitive_multiple_sources(rule_runner: RuleRunner) -> No
class Other implements B {}
"""
),
"3rdparty/jvm/default.lock": CoursierResolvedLockfile(entries=())
.to_serialized()
.decode(),
"3rdparty/jvm/default.lock": TestCoursierWrapper.new(entries=()).serialize(),
"lib/BUILD": dedent(
"""\
java_sources(
Expand Down Expand Up @@ -497,9 +486,7 @@ def test_compile_with_deps(rule_runner: RuleRunner) -> None:
)
"""
),
"3rdparty/jvm/default.lock": CoursierResolvedLockfile(entries=())
.to_serialized()
.decode(),
"3rdparty/jvm/default.lock": TestCoursierWrapper.new(entries=()).serialize(),
"Example.java": JAVA_LIB_MAIN_SOURCE,
"lib/BUILD": dedent(
"""\
Expand Down Expand Up @@ -540,9 +527,7 @@ def test_compile_of_package_info(rule_runner: RuleRunner) -> None:
)
"""
),
"3rdparty/jvm/default.lock": CoursierResolvedLockfile(entries=())
.to_serialized()
.decode(),
"3rdparty/jvm/default.lock": TestCoursierWrapper.new(entries=()).serialize(),
"package-info.java": dedent(
"""
package org.pantsbuild.example;
Expand Down Expand Up @@ -581,9 +566,7 @@ def test_compile_with_missing_dep_fails(rule_runner: RuleRunner) -> None:
"""
),
"Example.java": JAVA_LIB_MAIN_SOURCE,
"3rdparty/jvm/default.lock": CoursierResolvedLockfile(entries=())
.to_serialized()
.decode(),
"3rdparty/jvm/default.lock": TestCoursierWrapper.new(entries=()).serialize(),
}
)
request = CompileJavaSourceRequest(
Expand All @@ -599,10 +582,11 @@ def test_compile_with_missing_dep_fails(rule_runner: RuleRunner) -> None:

@maybe_skip_jdk_test
def test_compile_with_maven_deps(rule_runner: RuleRunner) -> None:
resolved_joda_lockfile = CoursierResolvedLockfile(
joda_coord = Coordinate(group="joda-time", artifact="joda-time", version="2.10.10")
resolved_joda_lockfile = TestCoursierWrapper.new(
entries=(
CoursierLockfileEntry(
coord=Coordinate(group="joda-time", artifact="joda-time", version="2.10.10"),
coord=joda_coord,
file_name="joda-time-2.10.10.jar",
direct_dependencies=Coordinates([]),
dependencies=Coordinates([]),
Expand Down Expand Up @@ -633,7 +617,9 @@ def test_compile_with_maven_deps(rule_runner: RuleRunner) -> None:
)
"""
),
"3rdparty/jvm/default.lock": resolved_joda_lockfile.to_serialized().decode(),
"3rdparty/jvm/default.lock": resolved_joda_lockfile.serialize(
[ArtifactRequirement(coordinate=joda_coord)]
),
"Example.java": dedent(
"""
package org.pantsbuild.example;
Expand Down Expand Up @@ -674,9 +660,7 @@ def test_compile_with_missing_maven_dep_fails(rule_runner: RuleRunner) -> None:
)
"""
),
"3rdparty/jvm/default.lock": CoursierResolvedLockfile(entries=())
.to_serialized()
.decode(),
"3rdparty/jvm/default.lock": TestCoursierWrapper.new(entries=()).serialize(),
"Example.java": dedent(
"""
package org.pantsbuild.example;
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 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
Loading

0 comments on commit e771911

Please sign in to comment.