bazel: Breaking change in Bazel CQuery due to Starlarkification of providers

Description of the bug:

The following cquery no longer works with Bazel 7:

bazel cquery "@bazel_tools//tools/jdk:current_java_toolchain" --output starlark --starlark:expr 'providers(target)["JavaToolchainInfo"].source_version'

It looks like that providers(target)["JavaToolchainInfo"] needs to be replaced with providers(target)['@@_builtins//:common/java/java_toolchain.bzl%JavaToolchainInfo'].source_version but it feels odd to require this verbosity now. Especially the label syntax looks subjective to further changes. It should be possible to select a provider without relying on the location.

What’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

echo "7.0.0.rc5" > .bazelversion

run the query

Have you found anything relevant by searching the web?

https://bazelbuild.slack.com/archives/CDCE4DFAP/p1702038149142419?thread_ts=1701990164.906629&cid=CDCE4DFAP

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

This needs to be documented. Ideally all those queries would continue to work, though.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks @hvadehra. Using --starlark:file works much better for this.

Oh, that looks doable.

BTW, that example doc needs fixing as well:

providers(target) returns a map whose keys are names of providers (for example, "DefaultInfo").

It should mention the specifics around keys instability from Bazel version to version.

I would have to do the filtering three times in a single line. I don’t think --starlark:expr allows assignments. I haven’t it figured out yet.

Is it necessary for the starlark code to be specified on the command line? If not, you could use --starlark:file instead. There are examples in the docs.

Thanks for confirming!

So we should just add this to the release notes as a breaking change.

Please do!