Skip to content

Only emit buildozer add deps if export exists#1389

Open
fzakaria wants to merge 1 commit intobazelbuild:mainfrom
fzakaria:fzakaria/export-only-on-success
Open

Only emit buildozer add deps if export exists#1389
fzakaria wants to merge 1 commit intobazelbuild:mainfrom
fzakaria:fzakaria/export-only-on-success

Conversation

@fzakaria
Copy link
Copy Markdown
Contributor

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

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
```
// 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",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@AnnaSvalova AnnaSvalova enabled auto-merge (squash) November 7, 2025 13:33
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.

2 participants