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

Make jar_library target export all its dependencies #4395

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/python/pants/backend/jvm/targets/jar_library.py
Expand Up @@ -76,6 +76,16 @@ def excludes(self):
"""
return self.payload.excludes

@property
def exports(self):
"""
:API: public
"""

# It is currently aliased to dependencies. For future work see
# https://github.com/pantsbuild/pants/issues/4398
return self.dependencies

@staticmethod
def to_jar_dependencies(relative_to, jar_library_specs, build_graph):
"""Convenience method to resolve a list of specs to JarLibraries and return its jars attributes.
Expand Down
Expand Up @@ -28,9 +28,14 @@ def _resolve_strict_dependencies(target):

def _resolve_exports(target):
for export in getattr(target, 'exports', []):
for exp in _resolve_exports(export):
yield exp
yield export
if type(export) in (AliasTarget, Target):
# If exported target is an alias, expand its dependencies.
for dep in _resolve_strict_dependencies(export):
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a test case for this bit of mutual recursion? It does make sense that it would work this way, but I'd like to see some examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, sure. I will add some unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added.

yield dep
else:
for exp in _resolve_exports(export):
yield exp
yield export


def strict_dependencies(target, dep_context):
Expand Down
20 changes: 20 additions & 0 deletions testprojects/tests/scala/org/pantsbuild/testproject/exports/BUILD
Expand Up @@ -25,3 +25,23 @@ scala_library(
dependencies=[':C'],
strict_deps=True,
)

target(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a test case that exercises this target 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.

Yeah it's in tests/python/pants_test/backend/jvm/tasks/jvm_compile/test_dep_exports_integration.py.

The test method does "list ::" in this dir, thus the new targets are automatically covered.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah. I see.

name='TB',
dependencies=[':B'],
)

scala_library(
name='TC',
sources = ['C.scala'],
dependencies=[':TB'],
exports=[':TB'],
strict_deps=True,
)

scala_library(
name='TD',
sources = ['D.scala'],
dependencies=[':TC'],
strict_deps=True,
)