noincompatible_enable_deprecated_label_apis
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Motivation
Several old Starlark APIs related to labels had confusing names and/or behavior. This change deprecates those old APIs in favor of new ones with clearer names and intent.
### Description
When `--incompatible_enable_deprecated_label_apis` is set to False:
* `native.repository_name()` is removed. Use `native.repo_name()` instead, which has a shorter name, and doesn't include a leading `@`.
* `Label.workspace_name` is removed. Use `Label.repo_name` instead, which has a clearer name, and behaves identically as the removed field.
* `Label.relative()` is removed. It has never functioned well with repo mapping. Instead, use the new method `Label.same_package_label()`, alongside the existing `native.package_relative_label()` and `Label()`.
### Incompatible Flag
--incompatible_enable_deprecated_label_apis
### Migration Guide
* `native.repository_name()` can be replaced with `'@' + native.repo_name()`.
* `Label.workspace_name` can be replaced with `Label.repo_name`.
* Depending on the use case, `Label.relative()` can be replaced with:
* if the argument is always a package-relative label (such as `:foo`), use `Label.same_package_label('foo')` instaed.
* if you're trying to relativize a label string from the context of a package in a macro, use `native.package_relative_label()` instead.
* if you're trying to relativize a label string from the context of the .bzl file containing the currently running code, use `Label()` instead.
The newer APIs are only available in 7.1.0+. If backwards compatibility is a concern, use `hasattr()`.
### In which Bazel LTS version will this incompatible change be enabled?
Bazel 8
### Additional Context
_No response_
### TODO List
- [x] Implement the incompatible change at Bazel HEAD and guard it behind a flag. (https://github.com/bazelbuild/bazel/commit/1bcb68c6b7ce065ba884e6d6573bd87aebae4c3b)
- [x] Backport the incompatible flag to the latest LTS release. (https://github.com/bazelbuild/bazel/pull/20977)
- [ ] Test the incompatible change with [downstream projects](https://github.com/bazelbuild/continuous-integration/blob/master/docs/downstream-testing.md#bazel-downstream-testing) and inform broken projects.
- [ ] Flip the incompatible flag at Bazel HEAD.
- [ ] Delete the incompatible flag and the old behavior at Bazel HEAD.
Contributor guide
Assessment
This issue has not been assessed yet.