Skip to content

Commit

Permalink
Allow JVM source to depend on relocated_files target (pantsbuild#17005)
Browse files Browse the repository at this point in the history
  • Loading branch information
somdoron authored Dec 1, 2022
1 parent 30470ea commit e5dd67e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/python/pants/jvm/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
from enum import Enum, auto
from typing import ClassVar, Iterable, Iterator, Sequence

from pants.core.target_types import FilesGeneratingSourcesField, FileSourceField
from pants.core.target_types import (
FilesGeneratingSourcesField,
FileSourceField,
RelocatedFilesOriginalTargetsField,
)
from pants.engine.collection import Collection
from pants.engine.engine_aware import EngineAwareReturnType
from pants.engine.environment import EnvironmentName
Expand Down Expand Up @@ -425,7 +429,9 @@ def ignore_because_file(coarsened_dep: CoarsenedTarget) -> bool:
return sum(
1
for t in coarsened_dep.members
if t.has_field(FileSourceField) or t.has_field(FilesGeneratingSourcesField)
if t.has_field(FileSourceField)
or t.has_field(FilesGeneratingSourcesField)
or t.has_field(RelocatedFilesOriginalTargetsField)
) == len(coarsened_dep.members)

return ClasspathEntryRequests(
Expand Down
11 changes: 9 additions & 2 deletions src/python/pants/jvm/compile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from pants.backend.scala.target_types import ScalaSourcesGeneratorTarget
from pants.backend.scala.target_types import rules as scala_target_types_rules
from pants.build_graph.address import Address
from pants.core.target_types import FilesGeneratorTarget
from pants.core.target_types import FilesGeneratorTarget, RelocatedFiles
from pants.core.util_rules import config_files, source_files, stripped_source_files
from pants.core.util_rules.external_tool import rules as external_tool_rules
from pants.engine.addresses import Addresses
Expand Down Expand Up @@ -135,6 +135,7 @@ def rule_runner() -> RuleRunner:
ProtobufSourcesGeneratorTarget,
ScalaSourcesGeneratorTarget,
FilesGeneratorTarget,
RelocatedFiles,
],
)
rule_runner.set_options(
Expand Down Expand Up @@ -354,8 +355,14 @@ def test_allow_files_dependency(
{
"BUILD": dedent(
"""\
scala_sources(name='main', dependencies=[":files"])
scala_sources(name='main', dependencies=[":files", ":relocated"])
files(name="files", sources=["File.txt"])
relocated_files(
name="relocated",
files_targets=[":files"],
src="",
dest="files",
)
"""
),
"3rdparty/jvm/BUILD": scala_stdlib_jvm_lockfile.requirements_as_jvm_artifact_targets(),
Expand Down

0 comments on commit e5dd67e

Please sign in to comment.