Allow targets to have sensible defaults for sources=.

Review Request #4300 - Created Oct. 12, 2016 and submitted

Information
Benjy Weinberger
pants
Reviewers
pants-reviews
jsirois, nhoward_tw
95% of the time, a java_library() target will have
sources=globs('*.java'), and it seems unnecessary to require this
boilerplate to be repeated everywhere.

This change provides a way for target to say "if no explicit sources
are specified, use this glob".

The change is gated behind an option, because it can have unintended
consequences.  For example, in the Pants codebase itself we had a few
places where we were using a python_library() with no sources as a
dependency aggregator, when we should have been using a target().

This change fixes such quirks in our own codebase.

It also modifies a couple of our example targets to take advantage
of this functionality, as proof-of-concept.

This change required modifying quite a few tests that were creating
library targets with no sources: These tests didn't init the relevant
subsystem, and so couldn't consult the new option to see what to do
when no sources= were provided.  These tests were fixed in one of
two ways: either by initializing the subsystem, or by providing
explicit sources=[], whichever made more sense.

Note that instead of creating a new subsystem, I added this option
to the Target.UnknownArguments subsystem.  This implied an expanded
role for that subsystem, so its name was no longer applicable.
I renamed it to Target.Arguments, and deprecated its scope.

Finally, note that the defaults for library and test targets make
it easy to have tests live side-by-side with the code they test,
instead of in a separate source tree, which is a really useful
idiom IMO.

CI passes: https://travis-ci.org/pantsbuild/pants/builds/168486240

Issues

  • 0
  • 2
  • 0
  • 2
Description From Last Updated
Benjy Weinberger
John Sirois
Stu Hood
Stu Hood
Nick Howard (Twitter)
Benjy Weinberger
Stu Hood
Nick Howard (Twitter)
Benjy Weinberger
Benjy Weinberger
Benjy Weinberger
Review request changed

Status: Closed (submitted)

Change Summary:

127867b852cff0ceda14d0bd427b2ffe9cdbe5a0

Benjy Weinberger

Submitted as 127867b852cff0ceda14d0bd427b2ffe9cdbe5a0. Thanks!

Loading...