Skip to content

Commit 8775555

Browse files
authored
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
1 parent 44e7723 commit 8775555

File tree

4 files changed

+67
-14
lines changed

4 files changed

+67
-14
lines changed

.bazelrc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@
22
# Trick bazel into treating BUILD files under examples/* as being regular files
33
# This lets us glob() up all the files inside the examples to make them inputs to tests
44
# (Note, we cannot use `common --deleted_packages` because the bazel version command doesn't support it)
5-
# To update these lines, execute
6-
# `bazel run @rules_bazel_integration_test//tools:update_deleted_packages`
7-
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
8-
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
5+
# To update the file, execute
6+
import %workspace%/.bazelrc.deleted_packages
97

108
test --test_output=errors
119

12-
common --deleted_packages=gazelle/examples/bzlmod_build_file_generation
13-
common --deleted_packages=gazelle/examples/bzlmod_build_file_generation/runfiles
14-
1510
# Do NOT implicitly create empty __init__.py files in the runfiles tree.
1611
# By default, these are created in every directory containing Python source code
1712
# or shared libraries, and every parent directory of those directories,

.bazelrc.deleted_packages

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Generated via './tools/update_deleted_packages.sh'
2+
common --deleted_packages=examples/build_file_generation
3+
common --deleted_packages=examples/build_file_generation/random_number_generator
4+
common --deleted_packages=examples/bzlmod
5+
common --deleted_packages=examples/bzlmod/entry_points
6+
common --deleted_packages=examples/bzlmod/entry_points/tests
7+
common --deleted_packages=examples/bzlmod/libs/my_lib
8+
common --deleted_packages=examples/bzlmod/other_module
9+
common --deleted_packages=examples/bzlmod/other_module/other_module/pkg
10+
common --deleted_packages=examples/bzlmod/patches
11+
common --deleted_packages=examples/bzlmod/py_proto_library
12+
common --deleted_packages=examples/bzlmod/py_proto_library/example.com/another_proto
13+
common --deleted_packages=examples/bzlmod/py_proto_library/example.com/proto
14+
common --deleted_packages=examples/bzlmod/py_proto_library/foo_external
15+
common --deleted_packages=examples/bzlmod/runfiles
16+
common --deleted_packages=examples/bzlmod/tests
17+
common --deleted_packages=examples/bzlmod/tests/other_module
18+
common --deleted_packages=examples/bzlmod/whl_mods
19+
common --deleted_packages=examples/multi_python_versions/libs/my_lib
20+
common --deleted_packages=examples/multi_python_versions/requirements
21+
common --deleted_packages=examples/multi_python_versions/tests
22+
common --deleted_packages=examples/pip_parse
23+
common --deleted_packages=examples/pip_parse_vendored
24+
common --deleted_packages=examples/pip_repository_annotations
25+
common --deleted_packages=examples/py_proto_library
26+
common --deleted_packages=examples/py_proto_library/example.com/another_proto
27+
common --deleted_packages=examples/py_proto_library/example.com/proto
28+
common --deleted_packages=gazelle
29+
common --deleted_packages=gazelle/examples/bzlmod_build_file_generation
30+
common --deleted_packages=gazelle/examples/bzlmod_build_file_generation/other_module/other_module/pkg
31+
common --deleted_packages=gazelle/examples/bzlmod_build_file_generation/runfiles
32+
common --deleted_packages=gazelle/manifest
33+
common --deleted_packages=gazelle/manifest/generate
34+
common --deleted_packages=gazelle/manifest/hasher
35+
common --deleted_packages=gazelle/manifest/test
36+
common --deleted_packages=gazelle/modules_mapping
37+
common --deleted_packages=gazelle/python
38+
common --deleted_packages=gazelle/pythonconfig
39+
common --deleted_packages=gazelle/python/private
40+
common --deleted_packages=tests/integration/compile_pip_requirements
41+
common --deleted_packages=tests/integration/compile_pip_requirements_test_from_external_repo
42+
common --deleted_packages=tests/integration/custom_commands
43+
common --deleted_packages=tests/integration/ignore_root_user_error
44+
common --deleted_packages=tests/integration/ignore_root_user_error/submodule
45+
common --deleted_packages=tests/integration/local_toolchains
46+
common --deleted_packages=tests/integration/pip_parse
47+
common --deleted_packages=tests/integration/pip_parse/empty
48+
common --deleted_packages=tests/integration/py_cc_toolchain_registered
49+
common --deleted_packages=tests/modules/another_module
50+
common --deleted_packages=tests/modules/other
51+
common --deleted_packages=tests/modules/other/nspkg_delta
52+
common --deleted_packages=tests/modules/other/nspkg_gamma
53+
common --deleted_packages=tests/modules/other/nspkg_single
54+
common --deleted_packages=tests/modules/other/simple_v1
55+
common --deleted_packages=tests/modules/other/simple_v2
56+
common --deleted_packages=tests/modules/other/with_external_data

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ repos:
4848
language: system
4949
# 7.x is necessary until https://github.com/bazel-contrib/rules_bazel_integration_test/pull/414
5050
# is merged and released
51-
entry: env USE_BAZEL_VERSION=7.x bazel run @rules_bazel_integration_test//tools:update_deleted_packages
51+
entry: ./tools/update_deleted_packages.sh
5252
files: ^((examples|tests)/.*/(MODULE.bazel|WORKSPACE|WORKSPACE.bzlmod|BUILD.bazel)|.bazelrc)$
5353
pass_filenames: false

tools/update_deleted_packages.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,19 @@
2323
# 2. For each of the directories, get all directories that contains a BUILD.bazel file.
2424
# 3. Sort and remove duplicates.
2525

26-
set -euxo pipefail
26+
set -euo pipefail
2727

2828
DIR="$(dirname $0)/.."
2929
cd $DIR
3030

3131
# The sed -i.bak pattern is compatible between macos and linux
32-
sed -i.bak "/^[^#].*--deleted_packages/s#=.*#=$(\
33-
find examples/*/* tests/*/* \( -name WORKSPACE -or -name MODULE.bazel \) |
32+
{
33+
echo "# Generated via './tools/update_deleted_packages.sh'"
34+
find examples tests gazelle \( -name WORKSPACE -or -name MODULE.bazel \) |
3435
xargs -n 1 dirname |
35-
xargs -n 1 -I{} find {} \( -name BUILD -or -name BUILD.bazel \) |
36+
xargs -I{} find {} \( -name BUILD -or -name BUILD.bazel \) |
3637
xargs -n 1 dirname |
38+
grep -v "gazelle/docs" |
3739
sort -u |
38-
paste -sd, -\
39-
)#" $DIR/.bazelrc && rm .bazelrc.bak
40+
sed 's/^/common --deleted_packages=/g'
41+
} | tee "$DIR"/.bazelrc.deleted_packages

0 commit comments

Comments
 (0)