CLI completion or short names for bazel targets
Description of the feature request:
Our users are asking for easier ways to enter target names for a given build. They don't like having to type the full path to each target. One option is for us to programatically generate a list of top-level aliases - one for every binary (around 7000 in our large repo) in a bzl file and load that into top level BUILD.bazel. Another is to implement a bazel query that generates a shell completion config file.
Our binary target names are unique.
Does anyone have any experience with either of these approaches? Is there any prior art out there that we can reuse?
For target //src/very/long/path/to/target/sometimes/even/longer:libMySharedLibrary
Option1: bazel build //:libMySharedLibrary
Option2: bazel build //src/very/long
Thanks!
Which category does this issue belong to?
CLI
What underlying problem are you trying to solve with this feature?
No response
Which operating system are you running Bazel on?
Windows
What is the output of bazel info release?
8.0.1
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 ?
Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
No response
Did you try shell completion? https://bazel.build/install/completion
An alternative would be alias targets: https://bazel.build/reference/be/general#alias
@meisterT I had a look at shell completion, but it appears to only complete command line parameters and not target names. Have I missed something?
It does complete targets on Unix (with bash it also completes targets in external repos), but I'm less sure about Windows.
@peakschris which OS are you on? Have you tried completing target names?
@fmeum thanks for clarifying, I hadn't realised that it completes target names.
@meisterT I'm on windows
Firstly, I ran into the problem that I couldn't install the bash completion script, because I install bazel from bazelisk. I cloned the bazel repo and attempted the bazel build command but that ran into issues with my configuration (unrelated to the script, I guess). Anyhow, I found the bash completion script in an old internet archive for android.
I've tried both bash completion and zsh completion in the appropriate shells on windows. Unfortunately they are both very slow, taking around 5 seconds to complete each path segment. Our monorepo has around 7000 end-user targets and around 700,000 items in the build graph. So it is not really usable and not worth enabling for us.
I will try again on linux and see if they perform better in native environment.
It would be great if completion could be built into the bazelisk binary. Both because that's how most users install Bazel and also because Go would be a much more convenient and performant language to implement this in.
This is actually the most upvoted issue of Bazelisk: https://github.com/bazelbuild/bazelisk/issues/29