Skip to content

Conversation

@rickeylev
Copy link
Collaborator

The --deleted_package lines are so long they can't be manually updated.
They were only put onto a single line because older Bazel versions didn't
support accumulative behavior.

Along the way, switch to using common command for them, too. The supported
Bazel versions are new enough to support it.

@rickeylev rickeylev requested a review from aignas as a code owner October 17, 2025 23:54
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @rickeylev, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses the challenge of managing excessively long --deleted_packages configurations within the .bazelrc file. By adopting a multi-line approach using the common command, it enhances the clarity and ease of updating these package lists. The changes include a refactored update script and a streamlined pre-commit hook, making the configuration more robust and user-friendly.

Highlights

  • Refactored Bazel Configuration: The --deleted_packages flag in .bazelrc has been refactored from a single, very long comma-separated line to multiple common --deleted_packages entries, each on its own line. This significantly improves readability and maintainability, leveraging newer Bazel versions' support for accumulative flag behavior.
  • Updated Package Updater Script: The tools/update_deleted_packages.sh script has been rewritten to generate the new multi-line common --deleted_packages entries, ensuring the .bazelrc file is correctly updated with the improved format.
  • Simplified Pre-commit Hook: The update-deleted-packages pre-commit hook in .pre-commit-config.yaml now directly calls the tools/update_deleted_packages.sh script, removing the previous bazel run command and specific Bazel version environment variable.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@rickeylev rickeylev marked this pull request as draft October 17, 2025 23:55
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the .bazelrc and .pre-commit-config.yaml files to update how deleted packages are handled. It changes the .bazelrc file to list deleted packages on separate lines using the common --deleted_packages format and updates the .pre-commit-config.yaml to use the tools/update_deleted_packages.sh script directly. The update_deleted_packages.sh script is also modified to find Bazel sub-workspaces and mark them as ignored by the root level Bazel project. The changes improve the readability and maintainability of the deleted packages list and simplify the update process.

echo "$end_marker" >> "$tmpfile"

# Write the content after the end marker
sed "1,/$end_marker/d" "$BAZELRC" >> "$tmpfile"
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The sed command uses 1,/$end_marker/d to delete lines from the beginning of the file up to and including the end marker. This could be problematic if the end marker is not found, as it would delete the entire file. Consider adding a check to ensure that the end marker exists before running this command, or use a more robust approach that doesn't rely on deleting lines based on a marker.

Comment on lines +7 to +8
# GENERATED_DELETED_PACKAGES_START
common --deleted_packages=examples/build_file_generation
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The comment # GENERATED_DELETED_PACKAGES_START should be placed on the line immediately before the first common --deleted_packages entry to clearly demarcate the start of the generated section.

Comment on lines +138 to +139
common --deleted_packages=tests/modules/other/with_external_data
# GENERATED_DELETED_PACKAGES_END
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The comment # GENERATED_DELETED_PACKAGES_END should be placed on the line immediately after the last common --deleted_packages entry to clearly demarcate the end of the generated section.

Comment on lines +30 to +36
find . -mindepth 2 \( -name WORKSPACE -o -name MODULE.bazel \) |
while read -r marker; do
workspace_dir="$(dirname "$marker")"
echo "$workspace_dir"
find "$workspace_dir" \( -name BUILD -o -name BUILD.bazel \) -exec dirname {} \;
done
) | sed 's#^\./##'
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The find command within the found_packages function could be simplified by combining the -name options into a single expression using -o (OR operator) and grouping them with parentheses. This improves readability and potentially performance.

Also, the sed command at the end of the function can be simplified by using the s#^ ./## pattern instead of s#^./## to remove the leading ./ from the paths.

Suggested change
find . -mindepth 2 \( -name WORKSPACE -o -name MODULE.bazel \) |
while read -r marker; do
workspace_dir="$(dirname "$marker")"
echo "$workspace_dir"
find "$workspace_dir" \( -name BUILD -o -name BUILD.bazel \) -exec dirname {} \;
done
) | sed 's#^\./##'
find . -mindepth 2 \( -name WORKSPACE -o -name MODULE.bazel \) |
while read -r marker; do
workspace_dir="$(dirname "$marker")"
echo "$workspace_dir"
find "$workspace_dir" \( -name BUILD -o -name BUILD.bazel \) -exec dirname {} \;
done
) | sed 's#^./##'

tmpfile=$(mktemp)

# Write the content before the start marker
sed "/$start_marker/q" "$BAZELRC" > "$tmpfile"
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The sed command uses the q option to quit after finding the start marker. This is efficient, but it might be more robust to use a different approach that ensures the entire file is processed, especially if the start marker is not found. Consider using a different sed command that doesn't rely on quitting mid-file.

Comment on lines +57 to +59
for pkg in $packages; do
echo "common --deleted_packages=$pkg" >> "$tmpfile"
done
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using a while loop to iterate through the packages is less efficient than using printf to generate all the lines at once and then appending them to the file. This reduces the number of write operations and improves performance. Also, consider adding a check to ensure that the package variable is not empty before appending it to the file.

Suggested change
for pkg in $packages; do
echo "common --deleted_packages=$pkg" >> "$tmpfile"
done
printf "common --deleted_packages=%s\n" "$packages" >> "$tmpfile"

local packages
# Set LC_COLLATE so that "/" sorts before "_", which makes
# for slightly nicer ordering with file paths
packages=$(found_packages | LC_COLLATE=C sort | uniq)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The variable packages is assigned the output of found_packages | LC_COLLATE=C sort | uniq. If found_packages returns an error, this error will not be propagated because it's part of a pipeline. To ensure that errors are caught, it's better to store the output of found_packages in a temporary variable and check its exit code before proceeding.

Also, consider using tr '\n' ' ' instead of a loop to concatenate the packages into a single string, as it's more efficient.

@rickeylev
Copy link
Collaborator Author

It seems like this added the entire gazelle sub-tree, which wasn't all listed before.

I think that's the correct thing to do, but I'm confused how things were working previously if those files weren't ignored. Shouldn't ... have been matching files under gazelle and giving errors?

In any case, it looks like an exception for //gazelle/docs needs to be made -- it gets fed into our doc gen. Or maybe we should change that to a @gazelle_whatever reference instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant