bazel-gazelle icon indicating copy to clipboard operation
bazel-gazelle copied to clipboard

feat: "include" directive

Open f0rmiga opened this issue 4 years ago • 7 comments

What type of PR is this?

Feature

What package or component does this PR mostly affect?

all

What does this PR do? Why is it needed?

Adds the include directive that takes precedence over exclude.

Which issues(s) does this PR fix?

None

Other notes for review

f0rmiga avatar Mar 07 '22 22:03 f0rmiga

Is this desired? If so, I can adjust the tests.

f0rmiga avatar Mar 07 '22 22:03 f0rmiga

Is this desired? If so, I can adjust the tests.

I think it would be better to start with a problem statement rather than a solution.

What problem are you trying to solve with this feature?

sluongng avatar Mar 08 '22 14:03 sluongng

I think it would be better to start with a problem statement rather than a solution.

Here is the problem we encountered:

Many of our developers have additional directories inside the workspace directory. For example, they might have additional copies of the repo to be able to toggle between the two. They might have additional data folders, e.g. when the app runs locally, it deposits some data in a folder in the workspace. They might have back ups of node_modules from a prior state of the repo.

In all of these cases, gazelle happily hangs forever as it tries to parse a node modules backup or a copy of the repo or lots of data files. In some cases (as in with the copy of the repo), gazelle even crashes due to duplicate rules encountered.

Without this patch, gazelle was nearly impossible to adopt for us.

aptenodytes-forsteri avatar Mar 08 '22 14:03 aptenodytes-forsteri

I guess I should add that there was near consensus among our developers that gazelle directories should be opt-in, because there is no telling what additional directories might crop up in the workspace.

Before this patch, we had (for example):

# gazelle:exclude artifactory/
# gazelle:exclude bazel-*/
# gazelle:exclude additional_data1/
# gazelle:exclude submodule_1/
# gazelle:exclude additional_data_2/
# gazelle:exclude additional_data_3/
# gazelle:exclude keys/
# gazelle:exclude logs/
# gazelle:exclude **/*node_modules*/
# gazelle:exclude out/
# gazelle:exclude submodule_2/
# gazelle:exclude tools/
# gazelle:exclude version/
# gazelle:exclude .yarn/

After, we could basically do:

# gazelle:include src/
# gazelle:include src/**

aptenodytes-forsteri avatar Mar 08 '22 14:03 aptenodytes-forsteri

Filed https://github.com/bazelbuild/bazel-gazelle/issues/1188 to track.

aptenodytes-forsteri avatar Mar 08 '22 14:03 aptenodytes-forsteri

I'd love to help get this in. @f0rmiga do you have bandwidth to address the comments? If not happy to contribute on your fork either as a direct collab or via PR to your branch

Whoaa512 avatar May 14 '22 08:05 Whoaa512

@Whoaa512 - I can address it later today. Thanks for the ping. Somehow this one got lost on my list.

f0rmiga avatar May 14 '22 17:05 f0rmiga