I'm a hundred percent in favor of removing source root declarations from BUILD files. That's another source of global state we can excise. A while back we also discussed putting them either in pants.ini, another special INI, JSON, or YAML file, or in magically named config files throughout the source tree.
Inferring roots from patterns would be a nice bonus but its a bit slow pre-fs-watcher.
Inferring roots from patterns would be a nice bonus but its a bit slow pre-fs-watcher.I might have been misunderstanding SourceRoots a bit... my understanding was that we didn't scan for source roots, but that we instead waited until a lookup for the source root of a 'Target' arrived, and then returned it. The inference I was talking about would happen lazily at sourceroot lookup time. Will double check.
Inferring roots from patterns would be a nice bonus but its a bit slow pre-fs-watcher.I might have been misunderstanding SourceRoots a bit... my understanding was that we didn't scan for source roots, but that we instead waited until a lookup for the source root of a 'Target' arrived, and then returned it. The inference I was talking about would happen lazily at sourceroot lookup time. Will double check.But I think it would be good to kill the lazy as well.
Inferring roots from patterns would be a nice bonus but its a bit slow pre-fs-watcher.I might have been misunderstanding SourceRoots a bit... my understanding was that we didn't scan for source roots, but that we instead waited until a lookup for the source root of a 'Target' arrived, and then returned it. The inference I was talking about would happen lazily at sourceroot lookup time. Will double check.But I think it would be good to kill the lazy as well.
Ok... so we're actually talking about killing the SourceRoot singleton then? I agree, but it might be out of scope for this improvement... maybe as a second review?
On Fri, Aug 1, 2014 at 1:00 PM, Stu Hood <stu...@twitter.com> wrote:
Once you setup your BUILD files the only change to these patterns is going to be in conjunction with corresponding changes to BUILD filesI see the purpose of BUILD files to be precisely for storing targets, and nothing more:Ok, I think I'm having a disconnect because that is not what I heard at the Pants summit. I heard that we were moving away from that, that a target is only one kind of thing you can store in a BUILD file, and that is part of the reason why AddressMapper is being refactored right now. From Patrick's design document:"The proposal here is that we should generalize the notion of BUILD files to exposing Addressable objects, regardless of what the semantics of those objects are. This separates out the notion of parsing BUILD files and mapping addresses from the notion of a Target DAG..."Again, in this case, I'd argue that the configuration information about which paths contain targets is tightly coupled to the BUILD file contents and BUILD files don't exist independently of a directory layout. You can't just move them around without breaking everything.More reasons not to put them in pants.ini: I don't see any other places pants. ini where we reference target aliases like 'java_library', 'scala_library', ...This is a little bit off topic, but frankly, its very confusing to understand why something is being placed in a BUILD file vs. pants. ini. Look at this from the default pants.ini:```[protobuf-gen]supportdir: bin/protobufversion: 2.4.1javadeps: ['3rdparty:protobuf-%(version)s']```IMHO, the javadeps specification is no different than just defining a BUILD target (but in some proprietary format). Why not just depend on something well known in a BUILD file (BUILD.tools?)dependencies(name='protobuf-gen-deps'dependencies=['3rdparty:protobuf-2.4.1',],]Note that the latter option seems to be what was done for junit.you can see from Patrick's reaction that he probably agrees. He wants to cache target definitions in memory via the fswatch stuff, but having SourceRoots changing in BUILD files in addition to targets would add another dimension of complexity to that.Although they are used to manipulate filenames/Targets, SourceRoots are more closely related to repository layout. And deciding how your repository is laid out is not something you want to individual teams to be able to override. In some regards, this is a thing that maven gets very right: they chose a convention, and made it very difficult to use anything else. In this case, pants would be allowing the repo/build/test owner to set the repo layout however they choose, but closing the loophole that allows individual teams to fiddle with it.and I can't see any reason you'd want to specify or override this on the command line.Yea, I wasn't suggesting that it would be beneficial to override from the command line... just that Benjy's work will result in a large cleanup of pants.ini, as other things that have reasonable defaults move out of that file.On Fri, Aug 1, 2014 at 9:46 AM, Eric Ayers <zun...@squareup.com> wrote:
On Fri, Aug 1, 2014 at 12:36 PM, Stu Hood <stu...@twitter.com> wrote:
(Did you mean to reply-all? can re-reply publicly if so)
What would folks think about doing away with SourceRoot.register in BUILD files, and instead defining source roots as a set of patterns in pants.ini.
Off the cuff, I'm not in favor of this so much. Why pants.ini instead of a BUILD file? I thought we were trying to get crap out of pants.ini. I just went through upgrading pants in our repo and there was all kinds of cruft I had to manually merge in with my hand edited changes.One of the strongest points of pants (in my mind), is that it encourages an org to centralize responsibility for things... including boilerplate. The fact that BUILD files all have to repeat themselves to call maven_layout (or for any other repetitive/obvious task) feels like a bug to me.I'm not convinced that is a good reason to use pants.ini for this information. The directory layout and target contents of this repo are tightly coupled to BUILD files. Once you setup your BUILD files the only change to these patterns is going to be in conjunction with corresponding changes to BUILD files, and I can't see any reason you'd want to specify or override this on the command line.In this case, by centralizing accepted layouts, you'd also be helping keep your repo consistent. As it stands users could choose to skip using maven_layout and invent their own convention, which would make the codebase inconsistent and more difficult to grok. The fact that they don't know this is the only saving grace =)Granted, the pants.ini contains a lot of stuff that could just be defaults... I expect Benjy's work on flags/options will shake it up quite a bit in the right direction.
On Thu, Jul 31, 2014 at 8:46 PM, 'Stu Hood' via Pants Developers <pants...@googlegroups.com> wrote:
Source roots are currently a stateful part of build file parsing which occasionally (depending on parse order) mean that target restrictions aren't applied within sourceroots.Additionally, we've recently needed to diverge from the public maven_layout in order to install additional targets into the source root definitions.
We are in the same boat here.
What would folks think about doing away with SourceRoot.register in BUILD files, and instead defining source roots as a set of patterns in pants.ini.
Off the cuff, I'm not in favor of this so much. Why pants.ini instead of a BUILD file? I thought we were trying to get crap out of pants.ini. I just went through upgrading pants in our repo and there was all kinds of cruft I had to manually merge in with my hand edited changes.
The patterns would be matched against filenames to determine the absolute path to the source root. One simplifying restriction would be to ignore nested source roots.Example:
- for a pattern like 'src/main/java', we'd match any prefix of directories under the build root that contained `src/main/java`:
- 'path/to/my/project/src/main/java'
- 'src/main/java'
- but, assuming there was also a 'src/main/scala' pattern, only the first pattern would be applied:
- 'project/src/main/scala/src/main/java' -> 'project/src/main/scala'
----It should be fairly straightforward implementation wise: scan all inferred source roots first, and if an existing root isn't found, find the earliest pattern match and add it to the set of inferred roots.