Made shading rules accessible and configurable for jvm_binary.

Review Request #2754 - Created Sept. 2, 2015 and submitted

Information
Garrett Malmquist
pants
gmalmquist/shading-support-for-jvm-binary
2121
3695dcb...
Reviewers
pants-reviews
benjyw, jsirois, stuhood, zundel

Made shading rules accessible and configurable for jvm_binary.

jvm_binary() targets may now specify a shading_rules argument,
which accepts a list of shading rules, which can be any of:

shading_relocate()
shading_exclude()
shading_relocate_package()
shading_exclude_package()

The order of rules in the list matters, as typical of shading
logic in general.

These rules are powerful enough to take advantage of jarjar's more
advanced syntax, like using wildcards in the middle of package
names. E.g., this syntax will now work:

# Destination pattern will be inferred to be
# `__shaded_by_pants__.com.@1.foo.bar.@2`
shading_relocate('com.*.foo.bar.**')

Which can also be done by:

shading_relocate_package('com.*.foo.bar')

I also added the ability to change the default
__shaded_by_pants__ prefix.

# `__my_prefix__.group.name.rev.jar.com.foo.bar.@1`
shading_relocate_package('com.foo.bar', shade_prefix='__my_prefix__.')

The rules are implemented by Shading.Relocate, Shading.Exclude,
Shading.RelocatePackage, and Shading.ExcludePackage.

Relocate is the most generic, and acts as the base-class. It is
essentially a factory for the Rule nametuple that previously
existed in Shader.

Rather than build off of the pre-existing shade_class,
shade_package, exclude_class, and exclude_package, I made
Relocate and friends more powerful, extensible and (I hope)
intuitive concepts, and refactored the existing functions to use
the new classes instead.

They are wrapped in a Shading object rather than in the previous
Shader object to keep the objects that make it into BUILD file
aliases separate from those that do not. I also wistfully imagine
a day when we can register BUILD file aliases recursively,
which would let us use syntax like Shading.Relocate instead of
shading_relocate, which would both be more consistent with things
like Duplicate and Skip today, without polluting the global
namespace. Today this is not possible, because while you can
register Shading, and then access Shading.* in BUILD files,
they don't make it into the BUILD dictionary when we generate docs.

Added tests to tests/python/pants_test/java/jar:shader and tests/python/pants_test/java/jar:shader-integration
Test project under testprojects/src/java/org/pantsbuild/testproject/shading and testprojects/src/java/org/pantsbuild/testproject/shadingdep.

CI went green: https://travis-ci.org/gmalmquist/pants/builds/78593423
CI went green: https://travis-ci.org/gmalmquist/pants/builds/78809269
CI went green: https://travis-ci.org/gmalmquist/pants/builds/79349294
CI went green: https://travis-ci.org/gmalmquist/pants/builds/79354035
CI went green: https://travis-ci.org/gmalmquist/pants/builds/79369976

Issues

  • 1
  • 2
  • 0
  • 3
Description From Last Updated
Hm... this implementation doesn't handle this case though? In order to handle this case, you'd need shading rules defined for ... Stu Hood Stu Hood
John Sirois
Eric Ayers
Garrett Malmquist
John Sirois
Garrett Malmquist
John Sirois
Garrett Malmquist
John Sirois
Garrett Malmquist
Eric Ayers
Garrett Malmquist
Garrett Malmquist
Review request changed

Status: Closed (submitted)

Change Summary:

In commit c40fd43b33cbab0f5b3948ffbb8abcc1d9ce7ee6
Thanks John & Eric!

Stu Hood

   
examples/src/java/org/pantsbuild/example/readme.md (Diff revision 6)
 
 
 
 
 
 
 

Hm... this implementation doesn't handle this case though? In order to handle this case, you'd need shading rules defined for jar_library targets.

Shading a binary handles the case where you're deployed into an environment that adds things to your classpath.

  1. Yeah - it handled this in an ad-hoc way only for binaries in earlier diffs, so the docs drifted from reality and I missed that in later diffs.
    My understanding is Garrett may circle back on the idea of having a new shading task that produces and caches shaded jar products - that would require the jar_library rules you suggest.
Loading...