Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add aquery output format with one command per line #22389

Open
pcc opened this issue May 15, 2024 · 2 comments
Open

Add aquery output format with one command per line #22389

pcc opened this issue May 15, 2024 · 2 comments
Labels
awaiting-user-response Awaiting a response from the author team-CLI Console UI type: feature request

Comments

@pcc
Copy link

pcc commented May 15, 2024

Description of the feature request:

Make it so that bazel aquery --output=commands prints a list of commands with one command per line, similar to ninja -t commands.

Which category does this issue belong to?

CLI

What underlying problem are you trying to solve with this feature?

When debugging build issues I frequently need to extract specific compile commands. Although bazel aquery 'deps(target)' prints the command lines used to build a specific target, each command will be printed over N lines with one argument per line, which makes it harder to use command line tools to extract commands. For example, I cannot grep the output for a particular file name to extract all commands dealing with that file. And when I copy-paste the command into my terminal to edit it before running it, one-line-per-argument would typically cause the command to become taller than my terminal window, which makes it harder to edit in most shells. When working with Ninja-based build systems, I normally use the commands tool and grep its output. With Bazel I ended up writing an awk script that converts the aquery output into the one-line-per-command format:

#!/usr/bin/awk -f

ORS=""

match($0, /Command Line: \((.*) \\/, a) {
  print a[1];
  print " ";
}
match($0, /^    (.*) \\$/, a) {
  print a[1];
  print " ";
}
match($0, /^    (.*)\)$/, a) {
  print a[1];
  print "\n";
}

But this script is clearly sensitive to Bazel's specific aquery format, which I imagine might change in the future. It also doesn't include environment variables, which fortunately I haven't needed so far. I guess it might be possible to feed one of the proto output formats into a separate program that converts the protos into the one-line-per-command format, but that would be a lot more work than my simple awk script. So the request is to add a straightforward and future-proof way to print the command list in this format, for example by adding an --output=commands flag.

Which operating system are you running Bazel on?

Linux

What is the output of bazel info release?

release 7.1.2

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

@joeleba
Copy link
Member

joeleba commented May 28, 2024

Have you tried --output=(proto|jsonproto|textproto)? You'd have a dedicated field for arguments

repeated string arguments = 6;

@joeleba joeleba added awaiting-user-response Awaiting a response from the author and removed untriaged labels May 28, 2024
@pcc
Copy link
Author

pcc commented May 28, 2024

As I mentioned in my initial feature request, I'm sure that it would be possible to write a tool that parses the protobuf written by one of the proto output formats, and writes out the commands in the desired format. But should every user who wants the command list in this format write their own tool? I expect that it wouldn't just be me who would use such a tool: a Google search for ninja -t commands reveals that many users use the Ninja tool output in the way that I usually do. So it seems that it would be more convenient for many folks if the output format were implemented as part of Bazel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-user-response Awaiting a response from the author team-CLI Console UI type: feature request
Projects
None yet
Development

No branches or pull requests

5 participants