Skip to content

Conversation

@fzakaria
Copy link
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
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