Skip to content

Support external repository labels in package_group#28811

Closed
meteorcloudy wants to merge 3 commits intobazelbuild:masterfrom
meteorcloudy:fix-package-group-external-repos
Closed

Support external repository labels in package_group#28811
meteorcloudy wants to merge 3 commits intobazelbuild:masterfrom
meteorcloudy:fix-package-group-external-repos

Conversation

@meteorcloudy
Copy link
Copy Markdown
Member

@meteorcloudy meteorcloudy commented Feb 26, 2026

Description

This PR enables package_group to correctly interpret labels that include external repositories (e.g., @module//... or @module//:__subpackages__).

Motivation

Previously, PackageSpecification.java strictly required package names to start with //, failing on labels with repository prefixes. This made it impossible to define a package_group that includes packages from other Bzlmod modules. This change leverages Label.parseWithRepoContext to correctly resolve repository mapping and validate package specifications within the context of the repository where the package_group is defined.

Fixes an issue where bazel build would fail when a package_group referenced an external repository in its packages attribute.

Build API Changes

Yes. This change affects the behavior of the package_group rule and the visibility() function in .bzl files.

  1. Has this been discussed in a design doc or issue? No, but the change and impact should be straightforward to understand.
  2. Is the change backward compatible? Yes, it relaxes a restriction that previously caused errors.
  3. If it's a breaking change, what is the migration plan? N/A

Checklist

  • I have added tests for the new use cases (if any).
  • I have updated the documentation (if applicable).

Release Notes

RELNOTES: package_group now supports labels with external repositories in the packages attribute.

@meteorcloudy meteorcloudy requested a review from a team as a code owner February 26, 2026 10:44
@meteorcloudy meteorcloudy requested review from gregestren and removed request for a team February 26, 2026 10:44
@github-actions github-actions Bot added team-Configurability platforms, toolchains, cquery, select(), config transitions awaiting-review PR is awaiting review from an assigned reviewer labels Feb 26, 2026
@meteorcloudy meteorcloudy marked this pull request as draft February 26, 2026 10:45
@meteorcloudy meteorcloudy removed the request for review from gregestren February 26, 2026 10:45
@meteorcloudy meteorcloudy force-pushed the fix-package-group-external-repos branch 2 times, most recently from 2ec99a5 to 2b4c509 Compare February 26, 2026 12:40
@meteorcloudy
Copy link
Copy Markdown
Member Author

@brandjon @Wyverald What do you think about this change?

@mkruskal-google needs this for limiting certain abseil targets visibility to a specific new BCR module.

     visibility = [ "@foo//bar:__subpackages__"],

already works when you have a bazel_dep on foo (assuming this dependency won't cause much problem), this change allows such declaration also in package_group.

@fmeum
Copy link
Copy Markdown
Collaborator

fmeum commented Feb 26, 2026

Does this work with nodep deps? That would resolve concerns about increased dep footprint.

@meteorcloudy
Copy link
Copy Markdown
Member Author

@fmeum Unfortunately no, nodep requires repo_name = None, so the label will be invalid. @mkruskal-google is aware of the dep footprint problem, but it should be fine for this specific case (just a standard C++ library).

@meteorcloudy
Copy link
Copy Markdown
Member Author

FYI @gregestren

@meteorcloudy meteorcloudy marked this pull request as ready for review February 27, 2026 11:46
*/
public static PackageSpecification fromStringForBzlVisibility(
RepositoryName repositoryName, String spec) throws EvalException {
RepositoryMapping mapper, RepositoryName repositoryName, String spec) throws EvalException {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/mapper/repoMapping/ ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

package_group(
name = "banana",
packages = ["@veggies//:cucumber"],
packages = ["@@veggies//cucumber"],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AFAICT there's no test that exercises the repo mapping logic (ie. single @). can you add one?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch, added!

@meteorcloudy meteorcloudy force-pushed the fix-package-group-external-repos branch from 2b4c509 to bced873 Compare March 4, 2026 14:02
@Wyverald Wyverald added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Mar 4, 2026
@meteorcloudy
Copy link
Copy Markdown
Member Author

@bazel-io fork 9.1.0

@meteorcloudy
Copy link
Copy Markdown
Member Author

@bazel-io fork 8.7.0

@copybara-service copybara-service Bot closed this in dfe9326 Mar 5, 2026
@github-actions github-actions Bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Mar 5, 2026
bazel-io pushed a commit to bazel-io/bazel that referenced this pull request Mar 5, 2026
### Description

This PR enables `package_group` to correctly interpret labels that include external repositories (e.g., `@module//...` or `@module//:__subpackages__`).

### Motivation

Previously, `PackageSpecification.java` strictly required package names to start with `//`, failing on labels with repository prefixes. This made it impossible to define a `package_group` that includes packages from other Bzlmod modules. This change leverages `Label.parseWithRepoContext` to correctly resolve repository mapping and validate package specifications within the context of the repository where the `package_group` is defined.

Fixes an issue where bazel build would fail when a `package_group` referenced an external repository in its `packages` attribute.

### Build API Changes

Yes. This change affects the behavior of the `package_group` rule and the `visibility()` function in `.bzl` files.

1. Has this been discussed in a design doc or issue? No, but the change and impact should be straightforward to understand.
2. Is the change backward compatible? Yes, it relaxes a restriction that previously caused errors.
3. If it's a breaking change, what is the migration plan? N/A

### Checklist

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes

RELNOTES: `package_group` now supports labels with external repositories in the `packages` attribute.

Closes bazelbuild#28811.

PiperOrigin-RevId: 878957471
Change-Id: Ic84df870374fb8c6f6f24d6fdff388d909750469
@meteorcloudy
Copy link
Copy Markdown
Member Author

@bazel-io fork 9.0.1

bazel-io pushed a commit to bazel-io/bazel that referenced this pull request Mar 5, 2026
### Description

This PR enables `package_group` to correctly interpret labels that include external repositories (e.g., `@module//...` or `@module//:__subpackages__`).

### Motivation

Previously, `PackageSpecification.java` strictly required package names to start with `//`, failing on labels with repository prefixes. This made it impossible to define a `package_group` that includes packages from other Bzlmod modules. This change leverages `Label.parseWithRepoContext` to correctly resolve repository mapping and validate package specifications within the context of the repository where the `package_group` is defined.

Fixes an issue where bazel build would fail when a `package_group` referenced an external repository in its `packages` attribute.

### Build API Changes

Yes. This change affects the behavior of the `package_group` rule and the `visibility()` function in `.bzl` files.

1. Has this been discussed in a design doc or issue? No, but the change and impact should be straightforward to understand.
2. Is the change backward compatible? Yes, it relaxes a restriction that previously caused errors.
3. If it's a breaking change, what is the migration plan? N/A

### Checklist

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes

RELNOTES: `package_group` now supports labels with external repositories in the `packages` attribute.

Closes bazelbuild#28811.

PiperOrigin-RevId: 878957471
Change-Id: Ic84df870374fb8c6f6f24d6fdff388d909750469
meteorcloudy added a commit to meteorcloudy/bazel that referenced this pull request Mar 5, 2026
This PR enables `package_group` to correctly interpret labels that include external repositories (e.g., `@module//...` or `@module//:__subpackages__`).

Previously, `PackageSpecification.java` strictly required package names to start with `//`, failing on labels with repository prefixes. This made it impossible to define a `package_group` that includes packages from other Bzlmod modules. This change leverages `Label.parseWithRepoContext` to correctly resolve repository mapping and validate package specifications within the context of the repository where the `package_group` is defined.

Fixes an issue where bazel build would fail when a `package_group` referenced an external repository in its `packages` attribute.

Yes. This change affects the behavior of the `package_group` rule and the `visibility()` function in `.bzl` files.

1. Has this been discussed in a design doc or issue? No, but the change and impact should be straightforward to understand.
2. Is the change backward compatible? Yes, it relaxes a restriction that previously caused errors.
3. If it's a breaking change, what is the migration plan? N/A

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

RELNOTES: `package_group` now supports labels with external repositories in the `packages` attribute.

Closes bazelbuild#28811.

PiperOrigin-RevId: 878957471
Change-Id: Ic84df870374fb8c6f6f24d6fdff388d909750469
meteorcloudy added a commit to meteorcloudy/bazel that referenced this pull request Mar 5, 2026
This PR enables `package_group` to correctly interpret labels that include external repositories (e.g., `@module//...` or `@module//:__subpackages__`).

Previously, `PackageSpecification.java` strictly required package names to start with `//`, failing on labels with repository prefixes. This made it impossible to define a `package_group` that includes packages from other Bzlmod modules. This change leverages `Label.parseWithRepoContext` to correctly resolve repository mapping and validate package specifications within the context of the repository where the `package_group` is defined.

Fixes an issue where bazel build would fail when a `package_group` referenced an external repository in its `packages` attribute.

Yes. This change affects the behavior of the `package_group` rule and the `visibility()` function in `.bzl` files.

1. Has this been discussed in a design doc or issue? No, but the change and impact should be straightforward to understand.
2. Is the change backward compatible? Yes, it relaxes a restriction that previously caused errors.
3. If it's a breaking change, what is the migration plan? N/A

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

RELNOTES: `package_group` now supports labels with external repositories in the `packages` attribute.

Closes bazelbuild#28811.

PiperOrigin-RevId: 878957471
Change-Id: Ic84df870374fb8c6f6f24d6fdff388d909750469
meteorcloudy added a commit to meteorcloudy/bazel that referenced this pull request Mar 5, 2026
This PR enables `package_group` to correctly interpret labels that include external repositories (e.g., `@module//...` or `@module//:__subpackages__`).

Previously, `PackageSpecification.java` strictly required package names to start with `//`, failing on labels with repository prefixes. This made it impossible to define a `package_group` that includes packages from other Bzlmod modules. This change leverages `Label.parseWithRepoContext` to correctly resolve repository mapping and validate package specifications within the context of the repository where the `package_group` is defined.

Fixes an issue where bazel build would fail when a `package_group` referenced an external repository in its `packages` attribute.

Yes. This change affects the behavior of the `package_group` rule and the `visibility()` function in `.bzl` files.

1. Has this been discussed in a design doc or issue? No, but the change and impact should be straightforward to understand.
2. Is the change backward compatible? Yes, it relaxes a restriction that previously caused errors.
3. If it's a breaking change, what is the migration plan? N/A

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

RELNOTES: `package_group` now supports labels with external repositories in the `packages` attribute.

Closes bazelbuild#28811.

PiperOrigin-RevId: 878957471
Change-Id: Ic84df870374fb8c6f6f24d6fdff388d909750469
github-merge-queue Bot pushed a commit that referenced this pull request Mar 5, 2026
…28895)

### Description

This PR enables `package_group` to correctly interpret labels that
include external repositories (e.g., `@module//...` or
`@module//:__subpackages__`).

### Motivation

Previously, `PackageSpecification.java` strictly required package names
to start with `//`, failing on labels with repository prefixes. This
made it impossible to define a `package_group` that includes packages
from other Bzlmod modules. This change leverages
`Label.parseWithRepoContext` to correctly resolve repository mapping and
validate package specifications within the context of the repository
where the `package_group` is defined.

Fixes an issue where bazel build would fail when a `package_group`
referenced an external repository in its `packages` attribute.

### Build API Changes

Yes. This change affects the behavior of the `package_group` rule and
the `visibility()` function in `.bzl` files.

1. Has this been discussed in a design doc or issue? No, but the change
and impact should be straightforward to understand.
2. Is the change backward compatible? Yes, it relaxes a restriction that
previously caused errors.
3. If it's a breaking change, what is the migration plan? N/A

### Checklist

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes

RELNOTES: `package_group` now supports labels with external repositories
in the `packages` attribute.

Closes #28811.

PiperOrigin-RevId: 878957471
Change-Id: Ic84df870374fb8c6f6f24d6fdff388d909750469

Commit
dfe9326

Co-authored-by: Yun Peng <[email protected]>
github-merge-queue Bot pushed a commit that referenced this pull request Mar 5, 2026
…28893)

### Description

This PR enables `package_group` to correctly interpret labels that
include external repositories (e.g., `@module//...` or
`@module//:__subpackages__`).

### Motivation

Previously, `PackageSpecification.java` strictly required package names
to start with `//`, failing on labels with repository prefixes. This
made it impossible to define a `package_group` that includes packages
from other Bzlmod modules. This change leverages
`Label.parseWithRepoContext` to correctly resolve repository mapping and
validate package specifications within the context of the repository
where the `package_group` is defined.

Fixes an issue where bazel build would fail when a `package_group`
referenced an external repository in its `packages` attribute.

### Build API Changes

Yes. This change affects the behavior of the `package_group` rule and
the `visibility()` function in `.bzl` files.

1. Has this been discussed in a design doc or issue? No, but the change
and impact should be straightforward to understand.
2. Is the change backward compatible? Yes, it relaxes a restriction that
previously caused errors.
3. If it's a breaking change, what is the migration plan? N/A

### Checklist

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes

RELNOTES: `package_group` now supports labels with external repositories
in the `packages` attribute.

Closes #28811.

PiperOrigin-RevId: 878957471
Change-Id: Ic84df870374fb8c6f6f24d6fdff388d909750469

Commit
dfe9326

Co-authored-by: Yun Peng <[email protected]>
@meteorcloudy
Copy link
Copy Markdown
Member Author

Rolled back at 4eac06f due to internal breakages.

@meteorcloudy
Copy link
Copy Markdown
Member Author

Likely we just need to clean up the depot, so we don't have to rollback in release branches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-Configurability platforms, toolchains, cquery, select(), config transitions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants