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

Make bazel mod tidy work with include() #22455

Closed
wants to merge 2 commits into from
Closed

Conversation

Wyverald
Copy link
Member

We now generate fixup commands targeting include()d segments in addition to the root MODULE.bazel file itself. Fixup commands are grouped by file, and then passed to Buildozer using -f - (i.e. multiple commands for multiple files, passed in using stdin).

  • For repos to add, we find the first usage with the correct prod/dev type and add them there.
  • For repos to remove, we remove them from whichever usage had them.
  • At the end, all module files and included segments are formatted.

Fixes #22063

@Wyverald Wyverald added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. area-Bzlmod Bzlmod-specific PRs, issues, and feature requests awaiting-review PR is awaiting review from an assigned reviewer labels May 20, 2024
@Wyverald Wyverald requested a review from fmeum May 20, 2024 19:52
@Wyverald
Copy link
Member Author

Tests will fail until a new buildozer release (with bazelbuild/buildtools@1429e15). Tested locally with a patched buildozer and it passes.

rootUsage.getProxies().stream().filter(p -> !p.isDevDependency()).findFirst().get();
moduleFilePathToCommandsBuilder.put(
firstNonDevProxy.getContainingModuleFilePath(),
makeUseRepoCommand("use_repo_add", firstNonDevProxy.getProxyName(), importsToAdd));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens here if the proxy is not exported? I agree we don't need to support this case, but how bad is the failure?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the proxy name would be the empty string, resulting in commands like use_repo_add repo1 repo2, which means repo1 would be interpreted as the exported name...

I changed it so that unexported proxies would be treated as if they're exported as _unnamed_usage. Will probably tip people off that these are supposed to be named.

We now generate fixup commands targeting `include()`d segments in addition to the root MODULE.bazel file itself. Fixup commands are grouped by file, and then passed to Buildozer using `-f -` (i.e. multiple commands for multiple files, passed in using stdin).

- For repos to add, we find the first usage with the correct prod/dev type and add them there.
- For repos to remove, we remove them from whichever usage had them.
- At the end, all module files and included segments are formatted.

Fixes #22063
@github-actions github-actions bot removed the awaiting-review PR is awaiting review from an assigned reviewer label May 23, 2024
bazel-io pushed a commit to bazel-io/bazel that referenced this pull request May 23, 2024
We now generate fixup commands targeting `include()`d segments in addition to the root MODULE.bazel file itself. Fixup commands are grouped by file, and then passed to Buildozer using `-f -` (i.e. multiple commands for multiple files, passed in using stdin).

- For repos to add, we find the first usage with the correct prod/dev type and add them there.
- For repos to remove, we remove them from whichever usage had them.
- At the end, all module files and included segments are formatted.

Fixes bazelbuild#22063

Closes bazelbuild#22455.

PiperOrigin-RevId: 636680730
Change-Id: Id894a449d8d1cdf39271ea3a724a91aebc51befb
@Wyverald Wyverald deleted the wyv-include-tidy branch May 23, 2024 23:37
Wyverald added a commit that referenced this pull request May 24, 2024
We now generate fixup commands targeting `include()`d segments in addition to the root MODULE.bazel file itself. Fixup commands are grouped by file, and then passed to Buildozer using `-f -` (i.e. multiple commands for multiple files, passed in using stdin).

- For repos to add, we find the first usage with the correct prod/dev type and add them there.
- For repos to remove, we remove them from whichever usage had them.
- At the end, all module files and included segments are formatted.

Fixes #22063

Closes #22455.

PiperOrigin-RevId: 636680730
Change-Id: Id894a449d8d1cdf39271ea3a724a91aebc51befb
github-merge-queue bot pushed a commit that referenced this pull request May 24, 2024
We now generate fixup commands targeting `include()`d segments in
addition to the root MODULE.bazel file itself. Fixup commands are
grouped by file, and then passed to Buildozer using `-f -` (i.e.
multiple commands for multiple files, passed in using stdin).

- For repos to add, we find the first usage with the correct prod/dev
type and add them there.
- For repos to remove, we remove them from whichever usage had them.
- At the end, all module files and included segments are formatted.

Fixes #22063

Closes #22455.

PiperOrigin-RevId: 636680730
Change-Id: Id894a449d8d1cdf39271ea3a724a91aebc51befb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Bzlmod Bzlmod-specific PRs, issues, and feature requests team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make bazel mod tidy work with include()
2 participants