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

classmap: a jvm console task that outputs mapping from class products to their targets #4081

Merged
merged 9 commits into from Dec 7, 2016

Conversation

Projects
None yet
7 participants
@peiyuwang
Contributor

peiyuwang commented Nov 19, 2016

The task is straightforward similar to filemap that prints out target-file mapings, this outputs
target-class mappings.

This is useful when fixing compilation errors. One use case we encounter recently is to enable
strict_deps for performance, there are transitive dependencies need to be added.

This can be achieved by first running classmap to get the transitive target-class mapping, then
if after enabling strict_deps, we get error class X not found, we'll add X's mapping target
to the dependencies.

Test done

https://travis-ci.org/pantsbuild/pants/builds/177179488

A sample run

tw-mbp-peiyu:pants peiyu$ ./pants classmap testprojects//tests/java/org/pantsbuild/testproject/cucumber:lib |head
org.pantsbuild.testproject.cucumber.BadnamesSteps testprojects/tests/java/org/pantsbuild/testproject/cucumber:lib
org.pantsbuild.testproject.cucumber.DemoSteps testprojects/tests/java/org/pantsbuild/testproject/cucumber:lib
org.junit.ClassRule 3rdparty:junit
org.junit.Assert 3rdparty:junit
org.junit.After 3rdparty:junit
org.junit.rules.Stopwatch$Clock 3rdparty:junit
org.junit.rules.DisableOnDebug 3rdparty:junit
org.junit.rules.ExternalResource 3rdparty:junit
org.junit.rules.TestWatcher$1 3rdparty:junit
org.junit.rules.TemporaryFolder 3rdparty:junit
...
Show outdated Hide outdated src/python/pants/backend/jvm/tasks/classmap.py
def console_output(self, _):
def should_ignore(target):
if target.address.spec.startswith('//:'):

This comment has been minimized.

@stuhood

stuhood Nov 19, 2016

Member

Is this necessary? Seems easy enough to filter out any particular target before calling the goal.

@stuhood

stuhood Nov 19, 2016

Member

Is this necessary? Seems easy enough to filter out any particular target before calling the goal.

This comment has been minimized.

@peiyuwang

peiyuwang Nov 19, 2016

Contributor

Removed the //: check, agree easy to filter, either before (if calling with --internal-only) or after on the output.

The extra benefit is to be honest allow us to inspect all dependencies including those from build tools.

@peiyuwang

peiyuwang Nov 19, 2016

Contributor

Removed the //: check, agree easy to filter, either before (if calling with --internal-only) or after on the output.

The extra benefit is to be honest allow us to inspect all dependencies including those from build tools.

def console_output(self, _):
def should_ignore(target):
return self.get_options().internal_only and isinstance(target, JarLibrary)

This comment has been minimized.

@benjyw

benjyw Nov 19, 2016

Contributor

What about JvmBinary targets that have a source=?

Might be better to check for the opposite (not internal_only and isinstance(target, JarLibrary).

@benjyw

benjyw Nov 19, 2016

Contributor

What about JvmBinary targets that have a source=?

Might be better to check for the opposite (not internal_only and isinstance(target, JarLibrary).

This comment has been minimized.

@peiyuwang

peiyuwang Nov 20, 2016

Contributor

not sure I get... see no difference how jvm_binary is treated:

An example jvm_binary (this example has source but if w/o source if would be one less entry in the output of its own class mapping.)

tw-mbp-peiyu:pants peiyu$ ./pants classmap examples/src/java/org/pantsbuild/example/annotation/main --classmap-internal-only
org.pantsbuild.example.annotation.main.Main examples/src/java/org/pantsbuild/example/annotation/main:main
org.pantsbuild.example.annotation.example.Example examples/src/java/org/pantsbuild/example/annotation/example:example
org.pantsbuild.example.annotation.processor.ExampleProcessor examples/src/java/org/pantsbuild/example/annotation/processor:processor

tw-mbp-peiyu:pants peiyu$ ./pants classmap examples/src/java/org/pantsbuild/example/annotation/main --classmap-internal-only --no-classmap-transitive
org.pantsbuild.example.annotation.main.Main examples/src/java/org/pantsbuild/example/annotation/main:main
@peiyuwang

peiyuwang Nov 20, 2016

Contributor

not sure I get... see no difference how jvm_binary is treated:

An example jvm_binary (this example has source but if w/o source if would be one less entry in the output of its own class mapping.)

tw-mbp-peiyu:pants peiyu$ ./pants classmap examples/src/java/org/pantsbuild/example/annotation/main --classmap-internal-only
org.pantsbuild.example.annotation.main.Main examples/src/java/org/pantsbuild/example/annotation/main:main
org.pantsbuild.example.annotation.example.Example examples/src/java/org/pantsbuild/example/annotation/example:example
org.pantsbuild.example.annotation.processor.ExampleProcessor examples/src/java/org/pantsbuild/example/annotation/processor:processor

tw-mbp-peiyu:pants peiyu$ ./pants classmap examples/src/java/org/pantsbuild/example/annotation/main --classmap-internal-only --no-classmap-transitive
org.pantsbuild.example.annotation.main.Main examples/src/java/org/pantsbuild/example/annotation/main:main

This comment has been minimized.

@benjyw

benjyw Dec 7, 2016

Contributor

Oh, I think I misread "JavaLibrary" for "JarLibrary". This is fine as-is.

@benjyw

benjyw Dec 7, 2016

Contributor

Oh, I think I misread "JavaLibrary" for "JarLibrary". This is fine as-is.

@@ -576,11 +576,6 @@ def compute_classes_by_source(self, compile_contexts):
classes_by_src[None] = list(unclaimed_classes)
return classes_by_src_by_context
def classname_for_classfile(self, compile_context, class_file_name):

This comment has been minimized.

@benjyw

benjyw Nov 19, 2016

Contributor

Is this not needed anywhere?

@benjyw

benjyw Nov 19, 2016

Contributor

Is this not needed anywhere?

This comment has been minimized.

@peiyuwang

peiyuwang Nov 20, 2016

Contributor

yea, this is not used anywhere

[tw-mbp-peiyu pants (master)]$ git grep classname_for_classfile
src/python/pants/backend/jvm/tasks/jvm_compile/jvm_compile.py: def classname_for_classfile(self, compile_context, class_file_name):

@peiyuwang

peiyuwang Nov 20, 2016

Contributor

yea, this is not used anywhere

[tw-mbp-peiyu pants (master)]$ git grep classname_for_classfile
src/python/pants/backend/jvm/tasks/jvm_compile/jvm_compile.py: def classname_for_classfile(self, compile_context, class_file_name):

@jsirois jsirois removed the reviewable label Nov 29, 2016

@benjyw

benjyw approved these changes Dec 7, 2016

@peiyuwang peiyuwang merged commit 896f63d into pantsbuild:master Dec 7, 2016

1 check was pending

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details

@peiyuwang peiyuwang deleted the peiyuwang:peiyu/classmap branch Dec 12, 2016

lenucksi added a commit to lenucksi/pants that referenced this pull request Apr 25, 2017

classmap: a jvm console task that outputs mapping from class products…
… to their targets (#4081)

The task is straightforward similar to `filemap` that prints out target-file mapings, this outputs
target-class mappings.

This is useful when fixing compilation errors. One use case we encounter recently is to enable
`strict_deps` for performance, there are transitive dependencies need to be added.

This can be achieved by first running `classmap` to get the transitive target-class mapping, then
if after enabling `strict_deps`, we get error class X not found, we'll add X's mapping target
to the dependencies.

Test done
========
https://travis-ci.org/pantsbuild/pants/builds/177179488

A sample run
```
tw-mbp-peiyu:pants peiyu$ ./pants classmap testprojects//tests/java/org/pantsbuild/testproject/cucumber:lib |head
org.pantsbuild.testproject.cucumber.BadnamesSteps testprojects/tests/java/org/pantsbuild/testproject/cucumber:lib
org.pantsbuild.testproject.cucumber.DemoSteps testprojects/tests/java/org/pantsbuild/testproject/cucumber:lib
org.junit.ClassRule 3rdparty:junit
org.junit.Assert 3rdparty:junit
org.junit.After 3rdparty:junit
org.junit.rules.Stopwatch$Clock 3rdparty:junit
org.junit.rules.DisableOnDebug 3rdparty:junit
org.junit.rules.ExternalResource 3rdparty:junit
org.junit.rules.TestWatcher$1 3rdparty:junit
org.junit.rules.TemporaryFolder 3rdparty:junit
...
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment