Refactor Intermediate Target Generation Logic

Review Request #4277 - Created Oct. 3, 2016 and submitted

Information
Yujie Chen
pants
3917
Reviewers
pants-reviews
gmalmquist, peiyu, stuhood

The current intermediate target logic uses integer index to tag target name. This has 2 major problems:
1. This creates output difference between v1 and v2 engine. In v1 engine, parse_context is created for each BUILD file. Thus the index will be initialized to 0 for each BUILD file. But in v2 engine, only 1 parse_context will ever be created, which means index will only be initialized to 0 at the beginning and keep growing afterwards. This causes output intermediate target names being different between v1 and v2 engine.
2. The current logic will create a new target every time it sees "scoped, intransitive, or provided" field, even though they may refer to the same target, which leads to redundant intermediate targets.

This review does:
1. Extract a common base class IntermediateTargetFactory. IntransitiveDependencyFactory, ProvidedDependencyFactory and ScopedDependencyFactory all subclass IntermediateTargetFactory.
2. The base class holds a class variable which is a set that holds the tuples ("intermediate target name", "relpath to BUILD file"). This is to make sure a unique target is created only once in each dir (The reason we choose dir but not the entire repo is that v2 engine has undeterminded execution order, thus the intermediate target may be created in non-determined dirs if we want to enforce this uniqueness in repo level).
3. Instead of using index, hash target's full adress and its scope to generate an identifier.
4. Add some integration tests

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

Issues

  • 0
  • 3
  • 0
  • 3
Description From Last Updated
Stu Hood
Stu Hood
Yujie Chen
Stu Hood
Yi Cheng
Garrett Malmquist
Mateo Rodriguez
Kris Wilson
Yujie Chen
Yujie Chen
Review request changed

Status: Closed (submitted)

Change Summary:

Merged as https://github.com/pantsbuild/pants/commit/924b78c5a75ef2e0fd7a3640f8c2ec82c9c9f657.
Thanks Stu, Yi, Garrett, Mateo and Kris!

Loading...