Only emit buildozer add deps if export exists#1389
Open
fzakaria wants to merge 1 commit intobazelbuild:mainfrom
Open
Only emit buildozer add deps if export exists#1389fzakaria wants to merge 1 commit intobazelbuild:mainfrom
fzakaria wants to merge 1 commit intobazelbuild:mainfrom
Conversation
Previously, unused_deps would emit `add deps` for all the exports of a particular label that it was removing. If there were no exports, the buildozer commands would fail complaining about having 0 arguments. ``` > buildozer "add deps $(bazel query 'labels(exports, @maven//:com_google_guava_guava)' | tr '\n' ' ')" //http-server/ce-kafka-http-server:http-server-test-jar INFO: Invocation ID: cd696714-cd65-497d-b2cd-206dc679a610 Loading: 0 packages loaded INFO: Empty results Too few arguments for command 'add', expected at least 2. ``` We now guard against running the buildozer command only if the query returns values. ``` > deps=$(bazel query 'labels(exports, @maven//:com_google_guava_guava)' | tr '\n' ' '); [ -n "$deps" ] && buildozer "add deps $deps" //http-server/ce-kafka-http-server:http-server-test-jar INFO: Invocation ID: f7d9a5fe-ef85-4ea8-8ac7-8eed6ae1a158 Loading: 0 packages loaded INFO: Empty results ```
AnnaSvalova
approved these changes
Nov 7, 2025
| // add dep's exported dependencies to label before removing dep | ||
| fmt.Printf("buildozer \"add deps $(%s query 'labels(exports, %s)' | tr '\\n' ' ')\" %s\n", *buildTool, str.Value, label) | ||
| fmt.Printf( | ||
| "deps=$(%s query 'labels(exports, %s)' | tr '\\n' ' '); [ -n \"$deps\" ] && buildozer \"add deps $deps\" %s\n", |
Collaborator
There was a problem hiding this comment.
LGMT but we might have to roll it back if some tools analyze the output and rely on the buildozer add deps prefix to automatically run it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, unused_deps would emit
add depsfor all the exports of a particular label that it was removing. If there were no exports, the buildozer commands would fail complaining about having 0 arguments.We now guard against running the buildozer command only if the query returns values.