Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix module directory structure in the presence of globs #483

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

blorente
Copy link
Contributor

@blorente blorente commented Jan 23, 2020

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 and rglobs in the sources 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 their sources. For instance, consider the following folder structure:

\_ server/
   \_ BUILD (sources=glob("*.java"))
      ServerBuilder.java
      Server.java
   \_ config/
      \_ BUILD
         ServerConfig.java // This file is broken and doesn't compile.

In this case, IntelliJ will try to include the sources in server/config when compiling server, 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, the PantsSourceRootCompressor messes with the roots field of TargetInfo, and therefore a hack was introduced (the first commit) to keep that information around.
2.- We stopped marking content roots as SOURCE and TEST. 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).

@blorente blorente changed the title [WIP] Fix module directory structure in the presence of globs Fix module directory structure in the presence of globs Jan 23, 2020
@blorente blorente marked this pull request as ready for review January 23, 2020 17:51
@hrfuller hrfuller removed their request for review February 6, 2024 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant