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

[internal] Refactor consumption of JVM tool lockfiles #14239

Merged
merged 5 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 3 additions & 8 deletions src/python/pants/backend/codegen/avro/java/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
from pants.jvm.resolve import jvm_tool
from pants.jvm.resolve.coursier_fetch import (
CoursierResolvedLockfile,
MaterializedClasspath,
MaterializedClasspathRequest,
ToolClasspath,
ToolClasspathRequest,
)
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool, ValidatedJvmToolLockfileRequest
from pants.source.source_root import SourceRoot, SourceRootRequest
Expand Down Expand Up @@ -105,12 +105,7 @@ async def compile_avro_source(
lockfile = await Get(CoursierResolvedLockfile, ValidatedJvmToolLockfileRequest(avro_tools))

tool_classpath, subsetted_input_digest, empty_output_dir = await MultiGet(
Get(
MaterializedClasspath,
MaterializedClasspathRequest(
lockfiles=(lockfile,),
),
),
Get(ToolClasspath, ToolClasspathRequest(lockfile=lockfile)),
Get(
Digest,
DigestSubset(
Expand Down
99 changes: 30 additions & 69 deletions src/python/pants/backend/codegen/protobuf/scala/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
from pants.jvm.resolve.common import ArtifactRequirements, Coordinate
from pants.jvm.resolve.coursier_fetch import (
CoursierResolvedLockfile,
MaterializedClasspath,
MaterializedClasspathRequest,
ToolClasspath,
ToolClasspathRequest,
)
from pants.jvm.resolve.jvm_tool import (
GatherJvmCoordinatesRequest,
Expand Down Expand Up @@ -83,7 +83,7 @@ class MaterializeJvmPluginRequest:
@dataclass(frozen=True)
class MaterializedJvmPlugin:
name: str
classpath: MaterializedClasspath
classpath: ToolClasspath

def setup_arg(self, plugin_relpath: str) -> str:
classpath_arg = ":".join(self.classpath.classpath_entries(plugin_relpath))
Expand Down Expand Up @@ -129,12 +129,7 @@ async def generate_scala_from_protobuf(
inherit_env,
) = await MultiGet(
Get(DownloadedExternalTool, ExternalToolRequest, protoc.get_request(Platform.current)),
Get(
MaterializedClasspath,
MaterializedClasspathRequest(
lockfiles=(lockfile,),
),
),
Get(ToolClasspath, ToolClasspathRequest(lockfile=lockfile)),
Get(Digest, CreateDigest([Directory(output_dir)])),
Get(TransitiveTargets, TransitiveTargetsRequest([request.protocol_target.address])),
# Need PATH so that ScalaPB can invoke `mkfifo`.
Expand Down Expand Up @@ -180,13 +175,7 @@ async def generate_scala_from_protobuf(
}

input_digest = await Get(
Digest,
MergeDigests(
[
all_sources_stripped.snapshot.digest,
empty_output_dir,
]
),
Digest, MergeDigests([all_sources_stripped.snapshot.digest, empty_output_dir])
)

result = await Get(
Expand Down Expand Up @@ -248,13 +237,8 @@ async def materialize_jvm_plugin(request: MaterializeJvmPluginRequest) -> Materi
option_name="[scalapb].jvm_plugins",
),
)
classpath = await Get(
MaterializedClasspath, MaterializedClasspathRequest(artifact_requirements=(requirements,))
)
return MaterializedJvmPlugin(
name=request.plugin.name,
classpath=classpath,
)
classpath = await Get(ToolClasspath, ToolClasspathRequest(artifact_requirements=requirements))
return MaterializedJvmPlugin(name=request.plugin.name, classpath=classpath)


@rule
Expand Down Expand Up @@ -292,59 +276,36 @@ async def setup_scalapb_shim_classfiles(

tool_classpath, shim_classpath, source_digest = await MultiGet(
Get(
MaterializedClasspath,
MaterializedClasspathRequest(
ToolClasspath,
ToolClasspathRequest(
prefix="__toolcp",
artifact_requirements=(
ArtifactRequirements.from_coordinates(
[
Coordinate(
group="org.scala-lang",
artifact="scala-compiler",
version=SHIM_SCALA_VERSION,
),
Coordinate(
group="org.scala-lang",
artifact="scala-library",
version=SHIM_SCALA_VERSION,
),
Coordinate(
group="org.scala-lang",
artifact="scala-reflect",
version=SHIM_SCALA_VERSION,
),
]
),
artifact_requirements=ArtifactRequirements.from_coordinates(
[
Coordinate(
group="org.scala-lang",
artifact="scala-compiler",
version=SHIM_SCALA_VERSION,
),
Coordinate(
group="org.scala-lang",
artifact="scala-library",
version=SHIM_SCALA_VERSION,
),
Coordinate(
group="org.scala-lang",
artifact="scala-reflect",
version=SHIM_SCALA_VERSION,
),
]
),
),
),
Get(
MaterializedClasspath,
MaterializedClasspathRequest(
prefix="__shimcp",
lockfiles=(lockfile,),
),
),
Get(
Digest,
CreateDigest(
[
scalapb_shim_source,
Directory(dest_dir),
]
),
),
Get(ToolClasspath, ToolClasspathRequest(prefix="__shimcp", lockfile=lockfile)),
Get(Digest, CreateDigest([scalapb_shim_source, Directory(dest_dir)])),
)

merged_digest = await Get(
Digest,
MergeDigests(
(
tool_classpath.digest,
shim_classpath.digest,
source_digest,
)
),
Digest, MergeDigests((tool_classpath.digest, shim_classpath.digest, source_digest))
)

# NB: We do not use nailgun for this process, since it is launched exactly once.
Expand Down
11 changes: 3 additions & 8 deletions src/python/pants/backend/codegen/thrift/scrooge/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from pants.jvm.jdk_rules import JdkSetup
from pants.jvm.resolve.coursier_fetch import (
CoursierResolvedLockfile,
MaterializedClasspath,
MaterializedClasspathRequest,
ToolClasspath,
ToolClasspathRequest,
)
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool, ValidatedJvmToolLockfileRequest
from pants.source.source_root import SourceRootsRequest, SourceRootsResult
Expand Down Expand Up @@ -56,12 +56,7 @@ async def generate_scrooge_thrift_sources(
lockfile = await Get(CoursierResolvedLockfile, ValidatedJvmToolLockfileRequest(scrooge))

tool_classpath, transitive_targets, empty_output_dir_digest, wrapped_target = await MultiGet(
Get(
MaterializedClasspath,
MaterializedClasspathRequest(
lockfiles=(lockfile,),
),
),
Get(ToolClasspath, ToolClasspathRequest(lockfile=lockfile)),
Get(TransitiveTargets, TransitiveTargetsRequest([request.thrift_source_field.address])),
Get(Digest, CreateDigest([Directory(output_dir)])),
Get(WrappedTarget, Address, request.thrift_source_field.address),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from pants.engine.process import BashBinary, FallibleProcessResult, Process, ProcessExecutionFailure
from pants.engine.rules import Get, MultiGet, collect_rules, rule
from pants.jvm.jdk_rules import JdkSetup
from pants.jvm.resolve.coursier_fetch import MaterializedClasspath, MaterializedClasspathRequest
from pants.jvm.resolve.coursier_fetch import ToolClasspath, ToolClasspathRequest
from pants.option.global_options import ProcessCleanupOption
from pants.util.logging import LogLevel

Expand Down Expand Up @@ -88,10 +88,8 @@ async def analyze_java_source_dependencies(

(tool_classpath, prefixed_source_files_digest,) = await MultiGet(
Get(
MaterializedClasspath,
MaterializedClasspathRequest(
artifact_requirements=(java_parser_artifact_requirements(),),
),
ToolClasspath,
ToolClasspathRequest(artifact_requirements=java_parser_artifact_requirements()),
),
Get(Digest, AddPrefix(source_files.snapshot.digest, source_prefix)),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from pants.engine.rules import Get, MultiGet, collect_rules, rule
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.coursier_fetch import ToolClasspath, ToolClasspathRequest
from pants.util.logging import LogLevel

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -59,10 +59,9 @@ async def build_processors(bash: BashBinary, jdk_setup: JdkSetup) -> JavaParserC

materialized_classpath, source_digest = await MultiGet(
Get(
MaterializedClasspath,
MaterializedClasspathRequest(
prefix="__toolcp",
artifact_requirements=(java_parser_artifact_requirements(),),
ToolClasspath,
ToolClasspathRequest(
prefix="__toolcp", artifact_requirements=java_parser_artifact_requirements()
),
),
Get(
Expand Down
11 changes: 3 additions & 8 deletions src/python/pants/backend/java/lint/google_java_format/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from pants.jvm.resolve import jvm_tool
from pants.jvm.resolve.coursier_fetch import (
CoursierResolvedLockfile,
MaterializedClasspath,
MaterializedClasspathRequest,
ToolClasspath,
ToolClasspathRequest,
)
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool, ValidatedJvmToolLockfileRequest
from pants.util.logging import LogLevel
Expand Down Expand Up @@ -77,12 +77,7 @@ async def setup_google_java_format(
SourceFiles,
SourceFilesRequest(field_set.source for field_set in setup_request.request.field_sets),
),
Get(
MaterializedClasspath,
MaterializedClasspathRequest(
lockfiles=(lockfile,),
),
),
Get(ToolClasspath, ToolClasspathRequest(lockfile=lockfile)),
)

source_files_snapshot = (
Expand Down
34 changes: 16 additions & 18 deletions src/python/pants/backend/scala/compile/scalac.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from pants.jvm.compile import rules as jvm_compile_rules
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.coursier_fetch import ToolClasspath, ToolClasspathRequest
from pants.jvm.resolve.coursier_setup import Coursier
from pants.util.logging import LogLevel

Expand Down Expand Up @@ -116,23 +116,21 @@ async def compile_scala_source(
user_classpath = Classpath(direct_dependency_classpath_entries)
tool_classpath, sources_digest = await MultiGet(
Get(
MaterializedClasspath,
MaterializedClasspathRequest(
artifact_requirements=(
ArtifactRequirements.from_coordinates(
[
Coordinate(
group="org.scala-lang",
artifact="scala-compiler",
version=scala.version,
),
Coordinate(
group="org.scala-lang",
artifact="scala-library",
version=scala.version,
),
]
),
ToolClasspath,
ToolClasspathRequest(
artifact_requirements=ArtifactRequirements.from_coordinates(
[
Coordinate(
group="org.scala-lang",
artifact="scala-compiler",
version=scala.version,
),
Coordinate(
group="org.scala-lang",
artifact="scala-library",
version=scala.version,
),
]
),
),
),
Expand Down
13 changes: 5 additions & 8 deletions src/python/pants/backend/scala/compile/scalac_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from pants.jvm.goals import lockfile
from pants.jvm.resolve.coursier_fetch import (
CoursierResolvedLockfile,
MaterializedClasspath,
MaterializedClasspathRequest,
ToolClasspath,
ToolClasspathRequest,
)
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool
from pants.jvm.resolve.jvm_tool import rules as jvm_tool_rules
Expand Down Expand Up @@ -86,7 +86,7 @@ def generate_global_scalac_plugins_lockfile_request(
@dataclass(frozen=True)
class GlobalScalacPlugins:
names: tuple[str, ...]
classpath: MaterializedClasspath
classpath: ToolClasspath

def args(self, prefix: str | None = None) -> Iterator[str]:
for scalac_plugin_path in self.classpath.classpath_entries(prefix):
Expand All @@ -101,11 +101,8 @@ async def global_scalac_plugins(
) -> GlobalScalacPlugins:
lockfile = await Get(CoursierResolvedLockfile, GlobalScalacPluginsToolLockfileSentinel())
classpath = await Get(
MaterializedClasspath,
MaterializedClasspathRequest(
prefix="__scalac_plugin_cp",
lockfiles=(lockfile,),
),
ToolClasspath,
ToolClasspathRequest(prefix="__scalac_plugin_cp", lockfile=lockfile),
)
return GlobalScalacPlugins(loaded_global_plugins.names, classpath)

Expand Down
Loading