fix: do not break the root package when //gazelle is a package (#4530) The `//:gazelle_downloader_configs` filegroup referenced `gazelle/downloader_cfg.bazelrc` and `gazelle/downloader_config.cfg` as plain labels. That only works in the rules_python dev workspace, where `.bazelrc.deleted_packages` disables `//gazelle`. When rules_python is used as an external repository that contains `gazelle/BUILD.bazel` (e.g. via `git_override` or `local_path_override`), these labels cross a package boundary and are invalid, so loading any target in the root package fails: ``` ERROR: .../external/rules_python+/BUILD.bazel:89:10: Label '@@rules_python+//:gazelle/downloader_config.cfg' is invalid because '@@rules_python+//gazelle' is a subpackage; perhaps you meant to put the colon here: '@@rules_python+//gazelle:downloader_config.cfg'? ``` This becomes a blocker once every target depends on a root package target, e.g. the default `package_metadata` added in #4276. Use a `glob` with `allow_empty = True` instead. It does not cross package boundaries, so it is empty for external users and still picks up the files in the dev workspace, where `//tests/dev:sync_downloader_configs_test` consumes them.
diff --git a/BUILD.bazel b/BUILD.bazel index 4af7346..6fc1b87 100644 --- a/BUILD.bazel +++ b/BUILD.bazel
@@ -72,7 +72,6 @@ visibility = ["//docs:__subpackages__"], ) -# LINT.IfChange(synced_files) filegroup( name = "downloader_configs", srcs = [ @@ -88,13 +87,16 @@ # gazelle/BUILD.bazel and treats gazelle/* as part of //. filegroup( name = "gazelle_downloader_configs", - srcs = [ - "gazelle/downloader_cfg.bazelrc", - "gazelle/downloader_config.cfg", - ], + # Use a glob because //gazelle is a real package when rules_python is used + # as an external repository. Plain labels would be invalid there and fail + # loading of every target in the root package. The glob does not cross + # package boundaries, so it is empty in that case. + srcs = glob( + ["gazelle/downloader_*"], + allow_empty = True, + ), visibility = ["//tests:__subpackages__"], ) -# LINT.ThenChange(//dev/sync_downloader_configs.py:synced_files) filegroup( name = "distribution",
diff --git a/news/gazelle-downloader-configs.fixed.md b/news/gazelle-downloader-configs.fixed.md new file mode 100644 index 0000000..174eabc --- /dev/null +++ b/news/gazelle-downloader-configs.fixed.md
@@ -0,0 +1,5 @@ +Fixed loading of the root `@rules_python//` package when `rules_python` is +used as an external repository that includes the `gazelle` directory, e.g. +via `git_override` or `local_path_override`. Previously, the internal +`//:gazelle_downloader_configs` target used labels that crossed into the +`//gazelle` package and failed loading of every target in the root package.
diff --git a/sphinxdocs/BUILD.bazel b/sphinxdocs/BUILD.bazel index 3a496db..6eceef1 100644 --- a/sphinxdocs/BUILD.bazel +++ b/sphinxdocs/BUILD.bazel
@@ -11,7 +11,7 @@ ], visibility = ["@rules_python//tests:__subpackages__"], ) -# LINT.ThenChange(//BUILD.bazel:synced_files) +# LINT.ThenChange(//dev/sync_downloader_configs.py:synced_files) filegroup( name = "distribution",