Introduce anonymous targets built by macros.

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

Information
John Sirois
pants
jsirois/issues/2019
2019, 2123
2726
42a100a...
Reviewers
pants-reviews
benjyw, patricklaw, stuhood, zundel
This change introduces a new `TargetMacro.Factory` type whose instances
are accepted in the `BuildFileAliases` "targets" slot that can restrict
targets to only being contructed via the context aware object factory
interface, aka: BUILD file target macros.  This allows a target author to
be more restrictive with a target's arguments.  Two cases are immediately
important:

1. Enforcing 1:1:1
   This requires taking away the ability of the BUILD file author to
   specify a target name to ensure each BUILD file can have only 1
   target.  Since name is integral to Target capture, only a macro can
   do this.
2. Enforcing no dependencies
   The need to do this at all should go away when BuildGraph handling of
   non-Target Addressables is supported; but, until then, dependencies
   is another low-level property of Targets that cannot otherwise be
   blocked from population by BUILD file authors.

In the course of adding support for anonymous targets, the limits of the
existing system of carrying around type alias metadata in
BuildFileAddress were reached, and so this attribute was re-plumbed
through the Addressable proxies and into Target directly, allowing
macros to specify the alias for anonymous targets they create.

Finally, the BuildFileTargetFactory was lifted up as a small interface to
abstract the role both macros and target proxies serve in SourceRoot
specification and an explicit Macro type was introduced to allow for
macros to back restricted source roots.

 contrib/buildgen/src/python/pants/contrib/buildgen/build_file_manipulator.py                                                  |   6 +-
 contrib/go/examples/3rdparty/go/github.com/bitly/go-simplejson/BUILD                                                          |   1 -
 contrib/go/examples/3rdparty/go/github.com/bmizerany/assert/BUILD                                                             |   4 +-
 contrib/go/examples/3rdparty/go/github.com/cbroglie/mapstructure/BUILD                                                        |   1 -
 contrib/go/examples/3rdparty/go/github.com/gorilla/context/BUILD                                                              |   4 +-
 contrib/go/examples/3rdparty/go/github.com/gorilla/mux/BUILD                                                                  |   4 +-
 contrib/go/examples/3rdparty/go/github.com/kr/pretty/BUILD                                                                    |   4 +-
 contrib/go/examples/3rdparty/go/github.com/kr/text/BUILD                                                                      |   4 +-
 contrib/go/examples/3rdparty/go/gopkg.in/check.v1/BUILD                                                                       |   4 +-
 contrib/go/examples/src/go/hello/BUILD                                                                                        |   1 -
 contrib/go/examples/src/go/libA/BUILD                                                                                         |   1 -
 contrib/go/examples/src/go/libB/BUILD                                                                                         |   1 -
 contrib/go/examples/src/go/libC/BUILD                                                                                         |   1 -
 contrib/go/examples/src/go/libD/BUILD                                                                                         |   4 +-
 contrib/go/examples/src/go/libE/BUILD                                                                                         |   4 +-
 contrib/go/examples/src/go/server/BUILD                                                                                       |   1 -
 contrib/go/src/python/pants/contrib/go/register.py                                                                            |  22 +++--
 contrib/go/src/python/pants/contrib/go/targets/go_binary.py                                                                   |   4 +
 contrib/go/src/python/pants/contrib/go/targets/go_library.py                                                                  |   4 +
 contrib/go/src/python/pants/contrib/go/targets/go_local_source.py                                                             |  26 ++++++
 contrib/go/src/python/pants/contrib/go/targets/go_remote_library.py                                                           |  53 +++++++----
 contrib/go/src/python/pants/contrib/go/tasks/go_buildgen.py                                                                   |  37 ++++----
 contrib/go/tests/python/pants_test/contrib/go/targets/BUILD                                                                   |  54 ++++++++++++
 contrib/go/tests/python/pants_test/contrib/go/targets/__init__.py                                                             |   0
 contrib/go/tests/python/pants_test/contrib/go/targets/go_local_source_test_base.py                                            |  69 +++++++++++++++
 contrib/go/{src/python/pants/contrib/go/targets/go_binary.py => tests/python/pants_test/contrib/go/targets/test_go_binary.py} |  12 ++-
 contrib/go/tests/python/pants_test/contrib/go/targets/test_go_library.py                                                      |  18 ++++
 contrib/go/tests/python/pants_test/contrib/go/targets/test_go_remote_library.py                                               | 106 ++++++++++++++++++++++
 contrib/go/tests/python/pants_test/contrib/go/tasks/test_go_buildgen.py                                                       |   5 +-
 src/python/pants/base/BUILD                                                                                                   |  11 +++
 src/python/pants/base/address.py                                                                                              |  18 +---
 src/python/pants/base/addressable.py                                                                                          |  74 +++++++++++++---
 src/python/pants/base/build_configuration.py                                                                                  | 239 +++++++++++++++++++++++++++++---------------------
 src/python/pants/base/build_file_address_mapper.py                                                                            |   3 +-
 src/python/pants/base/build_file_aliases.py                                                                                   |  85 ++++++++++++++----
 src/python/pants/base/build_file_type_factory.py                                                                              |  21 +++++
 src/python/pants/base/build_graph.py                                                                                          |  14 +--
 src/python/pants/base/parse_context.py                                                                                        |  18 +++-
 src/python/pants/base/source_root.py                                                                                          |  27 +++---
 src/python/pants/base/target.py                                                                                               |  46 +++++-----
 src/python/pants/base/target_addressable.py                                                                                   |  67 +++++++++++---
 tests/python/pants_test/base/test_address.py                                                                                  |  10 +--
 tests/python/pants_test/base/test_build_configuration.py                                                                      |  18 ++--
 tests/python/pants_test/base/test_build_file_address_mapper.py                                                                |  14 +--
 tests/python/pants_test/base/test_build_file_aliases.py                                                                       |  29 +++---
 tests/python/pants_test/base/test_build_file_parser.py                                                                        |   8 +-
 46 files changed, 849 insertions(+), 308 deletions(-)target_macro_factories

The contrib/go/examples BUILD tree was regenerated with the updated
GoBuildgen task via:
$ ./pants buildgen.go --materialize --remote contrib/go/examples::

CI went green here:
https://travis-ci.org/pantsbuild/pants/builds/79408257

Issues

  • 0
  • 4
  • 1
  • 5
Description From Last Updated
John Sirois
Eric Ayers
John Sirois
Stu Hood
John Sirois
John Sirois
John Sirois
John Sirois
John Sirois
Benjy Weinberger
John Sirois
John Sirois
Patrick Lawson
John Sirois
John Sirois
John Sirois
John Sirois
Review request changed

Status: Closed (submitted)

Stu Hood
Ship It!
Loading...