Fix module directory structure in the presence of globs #483
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NOTE: This PR still has a hack in it (described in point 1 of "Solution"). We should either fix it or formalize it before merging.
Problem
By default IntelliJ will include subdirectories of a module as source files when compiling it. Pants allows targets to decide whether subdirectories should be included or not (via
globs
andrglobs
in thesources
field of a target).Some targets have broken subdirectories (they do not compile), which is allowed and compliant with the 1:1:1 recommendation of pants, provided that they don't use
rglobs
to declare theirsources
. For instance, consider the following folder structure:In this case, IntelliJ will try to include the sources in
server/config
when compilingserver
, which leads to a false failure.Solution
There were two major changes to solve this:
1.- Manually exclude all the subfolders of a module that are not content roots.
This is made possible because
export-dep-as-jar
expands the globs in the source fields and reports as content roots the complete set of subfolders covered by it. However, thePantsSourceRootCompressor
messes with theroots
field ofTargetInfo
, and therefore a hack was introduced (the first commit) to keep that information around.2.- We stopped marking content roots as
SOURCE
andTEST
. Marking them as such leads the IntelliJ compiler to fail with double-imports when compiling a project. It's not really necessary to mark anything but the base content roots (the directories where the BUILD file lives) as SOURCES, since IntelliJ modules will recursively include subfolders that are not excluded (this is what go us into this mess in the first place).