Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
56 changes: 56 additions & 0 deletions .bazelrc.deleted_packages
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ repos:
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
14 changes: 8 additions & 6 deletions tools/update_deleted_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \) |
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This find command is a great improvement. To make it even more robust and consistent with the pre-commit trigger, consider a couple of adjustments:

  1. The .pre-commit-config.yaml for this hook triggers on WORKSPACE.bzlmod files, but this find command doesn't look for them. It would be good to add it for consistency.
  2. The pre-commit files regex is also missing the gazelle directory and BUILD files (it only has BUILD.bazel). While that's in another file, it would be good to update it as part of this PR to ensure the hook triggers correctly. The regex in .pre-commit-config.yaml should probably be ^((examples|tests|gazelle)/.*/(MODULE.bazel|WORKSPACE|WORKSPACE.bzlmod|BUILD.bazel|BUILD)|.bazelrc)$.

Making these consistent will prevent future confusion.

Suggested change
find examples tests gazelle \( -name WORKSPACE -or -name MODULE.bazel \) |
find examples tests gazelle \( -name WORKSPACE -or -name MODULE.bazel -or -name WORKSPACE.bzlmod \) |

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" |
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This grep command filters out the gazelle/docs path. For future maintainability, it would be beneficial to add a comment explaining why this specific path is excluded from the deleted_packages list.

sort -u |
paste -sd, -\
)#" $DIR/.bazelrc && rm .bazelrc.bak
sed 's/^/common --deleted_packages=/g'
} | tee "$DIR"/.bazelrc.deleted_packages