chore(bazelrc): fix the update-deleted-packages script (#3425)

Before this we were relying on an upstream script, but because how we
are building our docs we need to customize how it is working. What is
more, the format was hard to maintain and prone to human errors.

This splits out the deleted packages code into a separate rc file that
is much easier to work with.

Split out of #3421
diff --git a/.bazelrc b/.bazelrc
index f9e00fe..6473f10 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -2,16 +2,11 @@
 # Trick bazel into treating BUILD files under examples/* as being regular files
 # This lets us glob() up all the files inside the examples to make them inputs to tests
 # (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it)
-# To update these lines, execute
-# `bazel run @rules_bazel_integration_test//tools:update_deleted_packages`
-build --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,gazelle/python/private,rules_python-repro,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered,tests/modules/another_module,tests/modules/other,tests/modules/other/nspkg_delta,tests/modules/other/nspkg_gamma,tests/modules/other/nspkg_single,tests/modules/other/simple_v1,tests/modules/other/simple_v2,tests/modules/other/with_external_data,tests/whl_with_build_files/testdata,tests/whl_with_build_files/testdata/somepkg,tests/whl_with_build_files/testdata/somepkg-1.0.dist-info,tests/whl_with_build_files/testdata/somepkg/subpkg
-query --deleted_packages=examples/build_file_generation,examples/build_file_generation/random_number_generator,examples/bzlmod,examples/bzlmod_build_file_generation,examples/bzlmod_build_file_generation/other_module/other_module/pkg,examples/bzlmod_build_file_generation/runfiles,examples/bzlmod/entry_points,examples/bzlmod/entry_points/tests,examples/bzlmod/libs/my_lib,examples/bzlmod/other_module,examples/bzlmod/other_module/other_module/pkg,examples/bzlmod/patches,examples/bzlmod/py_proto_library,examples/bzlmod/py_proto_library/example.com/another_proto,examples/bzlmod/py_proto_library/example.com/proto,examples/bzlmod/runfiles,examples/bzlmod/tests,examples/bzlmod/tests/other_module,examples/bzlmod/whl_mods,examples/multi_python_versions/libs/my_lib,examples/multi_python_versions/requirements,examples/multi_python_versions/tests,examples/pip_parse,examples/pip_parse_vendored,examples/pip_repository_annotations,examples/py_proto_library,examples/py_proto_library/example.com/another_proto,examples/py_proto_library/example.com/proto,gazelle,gazelle/manifest,gazelle/manifest/generate,gazelle/manifest/hasher,gazelle/manifest/test,gazelle/modules_mapping,gazelle/python,gazelle/pythonconfig,gazelle/python/private,rules_python-repro,tests/integration/compile_pip_requirements,tests/integration/compile_pip_requirements_test_from_external_repo,tests/integration/custom_commands,tests/integration/ignore_root_user_error,tests/integration/ignore_root_user_error/submodule,tests/integration/local_toolchains,tests/integration/pip_parse,tests/integration/pip_parse/empty,tests/integration/py_cc_toolchain_registered,tests/modules/another_module,tests/modules/other,tests/modules/other/nspkg_delta,tests/modules/other/nspkg_gamma,tests/modules/other/nspkg_single,tests/modules/other/simple_v1,tests/modules/other/simple_v2,tests/modules/other/with_external_data,tests/whl_with_build_files/testdata,tests/whl_with_build_files/testdata/somepkg,tests/whl_with_build_files/testdata/somepkg-1.0.dist-info,tests/whl_with_build_files/testdata/somepkg/subpkg
+# To update the file, execute
+import %workspace%/.bazelrc.deleted_packages
 
 test --test_output=errors
 
-common --deleted_packages=gazelle/examples/bzlmod_build_file_generation
-common --deleted_packages=gazelle/examples/bzlmod_build_file_generation/runfiles
-
 # Do NOT implicitly create empty __init__.py files in the runfiles tree.
 # By default, these are created in every directory containing Python source code
 # or shared libraries, and every parent directory of those directories,
diff --git a/.bazelrc.deleted_packages b/.bazelrc.deleted_packages
new file mode 100644
index 0000000..45e433a
--- /dev/null
+++ b/.bazelrc.deleted_packages
@@ -0,0 +1,56 @@
+# Generated via './tools/update_deleted_packages.sh'
+common --deleted_packages=examples/build_file_generation
+common --deleted_packages=examples/build_file_generation/random_number_generator
+common --deleted_packages=examples/bzlmod
+common --deleted_packages=examples/bzlmod/entry_points
+common --deleted_packages=examples/bzlmod/entry_points/tests
+common --deleted_packages=examples/bzlmod/libs/my_lib
+common --deleted_packages=examples/bzlmod/other_module
+common --deleted_packages=examples/bzlmod/other_module/other_module/pkg
+common --deleted_packages=examples/bzlmod/patches
+common --deleted_packages=examples/bzlmod/py_proto_library
+common --deleted_packages=examples/bzlmod/py_proto_library/example.com/another_proto
+common --deleted_packages=examples/bzlmod/py_proto_library/example.com/proto
+common --deleted_packages=examples/bzlmod/py_proto_library/foo_external
+common --deleted_packages=examples/bzlmod/runfiles
+common --deleted_packages=examples/bzlmod/tests
+common --deleted_packages=examples/bzlmod/tests/other_module
+common --deleted_packages=examples/bzlmod/whl_mods
+common --deleted_packages=examples/multi_python_versions/libs/my_lib
+common --deleted_packages=examples/multi_python_versions/requirements
+common --deleted_packages=examples/multi_python_versions/tests
+common --deleted_packages=examples/pip_parse
+common --deleted_packages=examples/pip_parse_vendored
+common --deleted_packages=examples/pip_repository_annotations
+common --deleted_packages=examples/py_proto_library
+common --deleted_packages=examples/py_proto_library/example.com/another_proto
+common --deleted_packages=examples/py_proto_library/example.com/proto
+common --deleted_packages=gazelle
+common --deleted_packages=gazelle/examples/bzlmod_build_file_generation
+common --deleted_packages=gazelle/examples/bzlmod_build_file_generation/other_module/other_module/pkg
+common --deleted_packages=gazelle/examples/bzlmod_build_file_generation/runfiles
+common --deleted_packages=gazelle/manifest
+common --deleted_packages=gazelle/manifest/generate
+common --deleted_packages=gazelle/manifest/hasher
+common --deleted_packages=gazelle/manifest/test
+common --deleted_packages=gazelle/modules_mapping
+common --deleted_packages=gazelle/python
+common --deleted_packages=gazelle/pythonconfig
+common --deleted_packages=gazelle/python/private
+common --deleted_packages=tests/integration/compile_pip_requirements
+common --deleted_packages=tests/integration/compile_pip_requirements_test_from_external_repo
+common --deleted_packages=tests/integration/custom_commands
+common --deleted_packages=tests/integration/ignore_root_user_error
+common --deleted_packages=tests/integration/ignore_root_user_error/submodule
+common --deleted_packages=tests/integration/local_toolchains
+common --deleted_packages=tests/integration/pip_parse
+common --deleted_packages=tests/integration/pip_parse/empty
+common --deleted_packages=tests/integration/py_cc_toolchain_registered
+common --deleted_packages=tests/modules/another_module
+common --deleted_packages=tests/modules/other
+common --deleted_packages=tests/modules/other/nspkg_delta
+common --deleted_packages=tests/modules/other/nspkg_gamma
+common --deleted_packages=tests/modules/other/nspkg_single
+common --deleted_packages=tests/modules/other/simple_v1
+common --deleted_packages=tests/modules/other/simple_v2
+common --deleted_packages=tests/modules/other/with_external_data
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 91e449f..57d31f5 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -48,6 +48,6 @@
         language: system
         # 7.x is necessary until https://github.com/bazel-contrib/rules_bazel_integration_test/pull/414
         # is merged and released
-        entry: env USE_BAZEL_VERSION=7.x bazel run @rules_bazel_integration_test//tools:update_deleted_packages
+        entry: ./tools/update_deleted_packages.sh
         files: ^((examples|tests)/.*/(MODULE.bazel|WORKSPACE|WORKSPACE.bzlmod|BUILD.bazel)|.bazelrc)$
         pass_filenames: false
diff --git a/tools/update_deleted_packages.sh b/tools/update_deleted_packages.sh
index 17e33d1..83bed91 100755
--- a/tools/update_deleted_packages.sh
+++ b/tools/update_deleted_packages.sh
@@ -23,17 +23,19 @@
 #   2. For each of the directories, get all directories that contains a BUILD.bazel file.
 #   3. Sort and remove duplicates.
 
-set -euxo pipefail
+set -euo pipefail
 
 DIR="$(dirname $0)/.."
 cd $DIR
 
 # The sed -i.bak pattern is compatible between macos and linux
-sed -i.bak "/^[^#].*--deleted_packages/s#=.*#=$(\
-    find examples/*/* tests/*/* \( -name WORKSPACE -or -name MODULE.bazel \) |
+{
+    echo "# Generated via './tools/update_deleted_packages.sh'"
+    find examples tests gazelle \( -name WORKSPACE -or -name MODULE.bazel \) |
         xargs -n 1 dirname |
-        xargs -n 1 -I{} find {} \( -name BUILD -or -name BUILD.bazel \) |
+        xargs -I{} find {} \( -name BUILD -or -name BUILD.bazel \) |
         xargs -n 1 dirname |
+        grep -v "gazelle/docs" |
         sort -u |
-        paste -sd, -\
-)#" $DIR/.bazelrc && rm .bazelrc.bak
+        sed 's/^/common --deleted_packages=/g' 
+} | tee "$DIR"/.bazelrc.deleted_packages