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

[FR] .bazelignore should support wildcard prefix #7093

Open
or-shachar opened this issue Jan 11, 2019 · 15 comments
Open

[FR] .bazelignore should support wildcard prefix #7093

or-shachar opened this issue Jan 11, 2019 · 15 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: feature request

Comments

@or-shachar
Copy link
Contributor

Description of the feature request:

Currently .bazelignore supports only full relative path prefix without any wildcards

I have many node_modules subfolders in my repo that I want to ignore.
With .gitignore I'd just need to put: node_modules and it will be ignored by git.
With .bazelignore I need to specify each folder by it's full relative path from workspace root.

I suggest to adjust behavior to the way .gitignore and save our users the trouble of collecting all folders.

What operating system are you running Bazel on?

We tested it on linux with bazel 0.20.0 and 0.21.0

@iirina iirina added untriaged team-Bazel General Bazel product/strategy issues labels Jan 14, 2019
@ittaiz
Copy link
Member

ittaiz commented Jan 29, 2019

@iirina @dslomov when can we expect this to be triaged?

@dslomov dslomov added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. and removed team-Bazel General Bazel product/strategy issues labels Jul 19, 2019
@laurentlb laurentlb added P3 We're not considering working on this, but happy to review a PR. (No assignee) type: feature request and removed untriaged labels Jul 26, 2019
@jupp0r
Copy link

jupp0r commented Jan 17, 2020

Is somebody working on this issue? If not, I'd like to start working on a patch.

@gregmagolan
Copy link
Contributor

gregmagolan commented Feb 13, 2020

+1 for the Angular repo. .bazelrc could be a few lines with wildcards instead of

node_modules
dist
aio/content
aio/node_modules
aio/tools/examples/shared/node_modules
integration/bazel/node_modules
integration/bazel/.yarn_local_cache
integration/bazel-schematics/node_modules
integration/bazel-schematics/.yarn_local_cache
integration/bazel-schematics/demo
integration/cli-hello-world-ivy-compat/node_modules
integration/cli-hello-world-ivy-compat/node_modules
integration/cli-hello-world-ivy-i18n/node_modules
integration/cli-hello-world-ivy-minimal/node_modules
integration/cli-hello-world-lazy/node_modules
integration/cli-hello-world-lazy-rollup/node_modules
integration/dynamic-compiler/node_modules
integration/hello_world__closure/node_modules
integration/hello_world__systemjs_umd/node_modules
integration/i18n/node_modules
integration/injectable-def/node_modules
integration/ivy-i18n/node_modules
integration/language_service_plugin/node_modules
integration/ng_elements/node_modules
integration/ng_update/node_modules
integration/ng_update_migrations/node_modules
integration/ngcc/node_modules
integration/platform-server/node_modules
integration/service-worker-schema/node_modules
integration/side-effects/node_modules
integration/terser/node_modules
integration/typings_test_ts36/node_modules
integration/cli-hello-world/.yarn_local_cache
integration/cli-hello-world-ivy-compat/.yarn_local_cache
integration/cli-hello-world-ivy-i18n/.yarn_local_cache
integration/cli-hello-world-ivy-minimal/.yarn_local_cache
integration/cli-hello-world-lazy/.yarn_local_cache
integration/cli-hello-world-lazy-rollup/.yarn_local_cache
integration/dynamic-compiler/.yarn_local_cache
integration/hello_world__closure/.yarn_local_cache
integration/hello_world__systemjs_umd/.yarn_local_cache
integration/i18n/.yarn_local_cache
integration/injectable-def/.yarn_local_cache
integration/ivy-i18n/.yarn_local_cache
integration/language_service_plugin/.yarn_local_cache
integration/ng_elements/.yarn_local_cache
integration/ng_update/.yarn_local_cache
integration/ng_update_migrations/.yarn_local_cache
integration/ngcc/.yarn_local_cache
integration/platform-server/.yarn_local_cache
integration/service-worker-schema/.yarn_local_cache
integration/side-effects/.yarn_local_cache
integration/terser/.yarn_local_cache
integration/typings_test_ts36/.yarn_local_cache
packages/bazel/node_modules

@cgruber
Copy link
Contributor

cgruber commented Feb 28, 2020

+1 for all the rules_* repos, which typically have a variety of sub-repos to handle testing the rules.

@philwo philwo added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Jun 15, 2020
patrickt added a commit to github/semantic that referenced this issue Jul 13, 2020
@tclem ran into an issue where he had built `semantic-source` from the
`semantic-source` directory; `cabal` placed a `dist-newstyle`
directory there, which was fouling up Bazel due to the fact that
`cabal` generates binary files called `BUILD`, and Bazel tries to
interpret these files as package configurations. Not good!

We can't use a glob here because .bazelignore files don't support
globbing (bazelbuild/bazel#7093), so it
suffices to ignore all the projects' `dist-newstyle` directories so
that no one runs into this again.
robrix pushed a commit to github/semantic that referenced this issue Jul 16, 2020
@tclem ran into an issue where he had built `semantic-source` from the
`semantic-source` directory; `cabal` placed a `dist-newstyle`
directory there, which was fouling up Bazel due to the fact that
`cabal` generates binary files called `BUILD`, and Bazel tries to
interpret these files as package configurations. Not good!

We can't use a glob here because .bazelignore files don't support
globbing (bazelbuild/bazel#7093), so it
suffices to ignore all the projects' `dist-newstyle` directories so
that no one runs into this again.
@David-Lam
Copy link

David-Lam commented Jul 27, 2021

Hi everyone! I have create a PR #13756 that add wildcard to .bazelignore. Feel free to review it. Thanks! @cgruber @ittaiz

@nkoroste
Copy link
Contributor

also related #13807

@philwo philwo removed the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Nov 29, 2021
@guw
Copy link
Contributor

guw commented Jan 11, 2022

Is this a dup of #8106?

hanwen pushed a commit to GerritCodeReview/gerrit that referenced this issue Jun 7, 2022
Bazel removed `managed_directories` feature on Bazel@HEAD, see: [1].
Design document is here: [2].

Also extend the .bazelignore and add explicitly the path to the
node_modules directories. Note, that Bazel currently doesn't support
the same semantic as .gitignore. For more details see this issue: [3]
and this issue specific to rules_nodejs: [4].

[1] bazelbuild/bazel#15463
[2] https://docs.google.com/document/d/1u9V5RUc7i6Urh8gGfnSurxpWA7JMRtwCi1Pr5BHeE44/edit
[3] bazelbuild/bazel#7093
[4] bazelbuild/bazel#8106

Release-Notes: skip
Change-Id: I5dc582e05e4116064fc06d438d4b8a8b57b6bb8d
@Toxaris
Copy link

Toxaris commented Jan 31, 2023

Experience report:

Like others, we have a monorepo where developers run bazel build //... but we also install NodeJS packages into node_modules folders in the source tree (to make the IDE happy). We would prefer to put **/node_modules into the .bazelignore, but since that is not supported, we have a script that generates the .bazelignore from the repo structure, and a check in our CI that the .bazelignore has been generated by the script.

Even with these precautions, we run into issues after the repo structure has changed upstream and a developer does git checkout or git pull on their machine. Developers will get the new .bazelignore but still have the old node_modules folders in their source tree. Since the node_module folders contain symlinks to internal dependencies, bazel will expand the dependency graph into a tree and find an exponential number of copies of our internal packages. It will either crash because of memory issues, or try to make sense of these weird packages and run into visibility issues.

I acknowledge that the root cause here is really that we put non-source files into the source tree, but we are not aware of a practical way to avoid that (short of building our own IDE plugins). Wildcards in the .bazelignore file would give us a much nicer development experience in practice.

dgp1130 added a commit to dgp1130/rules_prerender that referenced this issue Mar 8, 2023
This creates a new `pnpm-workspace.yaml` which makes it install `node_modules/` in all the `packages/*` directories. This wasn't necessary before because `rules_prerender` and `@rules_prerender/declarative_shadow_dom` don't have any external dependencies, but it is necessary to install package-specific dependencies.

Also updates `tsconfig.json` to work for any `@rules_prerender/*` packages instead of just `@rules_prerender/declarative_shadow_dom`.

`.bazelignore` needs to be updated as well, but doesn't support globs unfortunately (see bazelbuild/bazel#7093). `node_modules/` verification was also incorrectly being done on the user `.bazelignore` file, rather than `@rules_prerender`'s `.bazelignore` when loaded as an external workspace. Used a `Label()` constructor to fix that.
dgp1130 added a commit to dgp1130/rules_prerender that referenced this issue Mar 9, 2023
This creates a new `pnpm-workspace.yaml` which makes it install `node_modules/` in all the `packages/*` directories. This wasn't necessary before because `rules_prerender` and `@rules_prerender/declarative_shadow_dom` don't have any external dependencies, but it is necessary to install package-specific dependencies.

Also updates `tsconfig.json` to work for any `@rules_prerender/*` packages instead of just `@rules_prerender/declarative_shadow_dom`.

`.bazelignore` needs to be updated as well, but doesn't support globs unfortunately (see bazelbuild/bazel#7093). `node_modules/` verification was also incorrectly being done on the user `.bazelignore` file, rather than `@rules_prerender`'s `.bazelignore` when loaded as an external workspace. Used a `Label()` constructor to fix that.
dgp1130 added a commit to dgp1130/rules_prerender that referenced this issue Mar 9, 2023
This creates a new `pnpm-workspace.yaml` which makes it install `node_modules/` in all the `packages/*` directories. This wasn't necessary before because `rules_prerender` and `@rules_prerender/declarative_shadow_dom` don't have any external dependencies, but it is necessary to install package-specific dependencies.

Also updates `tsconfig.json` to work for any `@rules_prerender/*` packages instead of just `@rules_prerender/declarative_shadow_dom`.

`.bazelignore` needs to be updated as well, but doesn't support globs unfortunately (see bazelbuild/bazel#7093). `node_modules/` verification was also incorrectly being done on the user `.bazelignore` file, rather than `@rules_prerender`'s `.bazelignore` when loaded as an external workspace. Used a `Label()` constructor to fix that.
dgp1130 added a commit to dgp1130/rules_prerender that referenced this issue Mar 11, 2023
This creates a new `pnpm-workspace.yaml` which makes it install `node_modules/` in all the `packages/*` directories. This wasn't necessary before because `rules_prerender` and `@rules_prerender/declarative_shadow_dom` don't have any external dependencies, but it is necessary to install package-specific dependencies.

Also updates `tsconfig.json` to work for any `@rules_prerender/*` packages instead of just `@rules_prerender/declarative_shadow_dom`.

`.bazelignore` needs to be updated as well, but doesn't support globs unfortunately (see bazelbuild/bazel#7093). `node_modules/` verification was also incorrectly being done on the user `.bazelignore` file, rather than `@rules_prerender`'s `.bazelignore` when loaded as an external workspace. Used a `Label()` constructor to fix that.
@chadxzs
Copy link

chadxzs commented Apr 5, 2023

My team would really appreciate this feature. We're having issues right now because we're running into "infinite symlink expansion detected" when Bazel traverses into .terraform directories due to the way we are structuring our terraform code. It would be nice to be able to add a global .terraform ignore to prevent Bazel from encountering this.

Additionally, we're running into the same sort of issue with the node_modules being problematic and having to add an ignore line for each instance of this in our monorepo.

If we do a broad .bazelignore for a whole subtree that may contain these files, the IntelliJ Plugin for Bazel ignores these paths in the project view, which causes these paths to be excluded from things like code search which we value.

@dgoldstein0
Copy link

+1 to this.

Ran into this in the node_modules context, similar to @Toxaris, but probably a little simpler of a failure mode - rxjs is one dep of ours that uses some third party bazel rules, which crash any bazel queries that use ... over the folder after it's installed as we don't have the repositories it uses configured in our workspace.

I would love if .bazelignore worked more like .gitignore - e.g. support .gitignore syntax and/or support distributed .bazelignore files. (With the latter, we could make a yarn plugin that adds node_modules/.bazelignore whenever we yarn install - but the plugin approach obviously doesn't generalize to other folks' problems)

@dgoldstein0
Copy link

any chance of getting this prioritized? seems like this would be an easy thing to fix and a good experience win for users of .bazelignore.

@albertocavalcante
Copy link

Hey! Is there any ongoing effort in getting this implemented?

@armandomontanez
Copy link

When working in a project that has parallel CMake support via ExternalProject_Add , it'd be really nice if I could just .bazelignore cmake-* to prevent Bazel from trying to pick up the build directories produced by CMake.

@zbowling
Copy link

Any updates?

@David-Lam
Copy link

Hi folks! Sorry I no longer have time to complete this. Please feel free to take a stab if interested. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: feature request
Projects
None yet
Development

No branches or pull requests