bazelbuild / bazelbuild/bazel

Accessing aspects from cquery Starlark output

Open
#13,866 13 comments 3 reactions 0 assignees View on GitHub
cquery_aspects P3 team-Configurability type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the feature request:

Make providers returned by aspects requested on the command-line available to cquery Starlark output.

### Feature requests: what underlying problem are you trying to solve with this feature?

I would like to process information, that is extracted from a target by an aspect, in a cquery using the Starlark output mode.

In particular, I am trying to access the value of a rule attribute that is not accessible through any of the providers returned by the rule itself.

For a minimal repro:
- Checkout https://github.com/aherrmann/bazel-query-aspects
- Run
```
$ bazel cquery \
--include_aspects=True \
--aspects=//:defs.bzl%my_aspect \
//... \
--output=starlark --starlark:expr '"CQUERY {}: {}".format(target.label, providers(target).keys())'
```
- Output
```
DEBUG: .../defs.bzl:20:10: ASPECT struct(content = "foo")
CQUERY //:rule: ["FileProvider", "FilesToRunProvider", "OutputGroupInfo"]
```
- Observe that the aspect is executed, but the returned provider `MyProvider` is not listed in the cquery output.

### What operating system are you running Bazel on?

Ubuntu 21.04

### What's the output of `bazel info release`?

```
$ bazel info release
release 4.1.0
```

Contributor guide

Open the contributing guide

Research direction

Start with the linked minimal reproduction and run the provided bazel cquery command using --include_aspects, --aspects, and --output=starlark. Trace how providers(target) is populated for the cquery Starlark output; done means the MyProvider returned by the requested aspect appears in that provider list.

Written by the indexing model from the issue text.

Assessment

Domain
build-system, cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.