bazelisk icon indicating copy to clipboard operation
bazelisk copied to clipboard

CLI completion or short names for bazel targets

Open peakschris opened this issue 10 months ago • 7 comments

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 -> full target name

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

peakschris avatar Feb 02 '25 16:02 peakschris

Did you try shell completion? https://bazel.build/install/completion

An alternative would be alias targets: https://bazel.build/reference/be/general#alias

meisterT avatar Feb 04 '25 10:02 meisterT

@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?

peakschris avatar Feb 04 '25 10:02 peakschris

It does complete targets on Unix (with bash it also completes targets in external repos), but I'm less sure about Windows.

fmeum avatar Feb 04 '25 11:02 fmeum

@peakschris which OS are you on? Have you tried completing target names?

meisterT avatar Feb 06 '25 08:02 meisterT

@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.

peakschris avatar Feb 06 '25 09:02 peakschris

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.

fmeum avatar Feb 06 '25 10:02 fmeum

This is actually the most upvoted issue of Bazelisk: https://github.com/bazelbuild/bazelisk/issues/29

meteorcloudy avatar Mar 26 '25 09:03 meteorcloudy