bazelbuild / bazelbuild/bazel

`cquery --output=starlark --starlark:expr="providers(target)" --include_aspects` doesn't show providers introduced by aspect

Open
#14,090 2 comments 1 reaction 0 assignees View on GitHub
P2 query bugs team-Configurability type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

Repro:

```
% cat WORKSPACE
% cat BUILD
load("//:myrule.bzl", "myrule")

exports_files(["a.txt"])

filegroup(
name = "files",
srcs = ["a.txt"],
)

myrule(name = "my_rule")

% cat myrule.bzl
MyRuleInfo = provider()

def _myrule_impl(ctx):
return [MyRuleInfo()]

myrule = rule(
implementation = _myrule_impl
)

% cat kind.bzl
KindInfo = provider(fields = {"kind": "kind of target"})

def _kind_aspect_impl(target, ctx):
print(ctx.rule.kind)
extra_output = ctx.actions.declare_file(target.label.name + "_extra")
ctx.actions.write(
output = extra_output,
content = "test",
)
return [
KindInfo(kind = ctx.rule.kind),
DefaultInfo(files = depset([extra_output])),
]

kind_aspect = aspect(
implementation = _kind_aspect_impl,
)

% bazelisk cquery :my_rule --output=starlark --starlark:expr="providers(target)" --aspects=kind.bzl%kind_aspect --include_aspects
DEBUG: /Users/jingwen/code/scratch/aspects-cquery/kind.bzl:4:10: myrule
INFO: Analyzed target //:my_rule (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
{"//:myrule.bzl%MyRuleInfo": struct(), "FileProvider": , "FilesToRunProvider": , "OutputGroupInfo": struct(_hidden_top_level_INTERNAL_ = depset([]))}
INFO: Elapsed time: 0.120s
INFO: 0 processes.
INFO: Build completed successfully, 0 total actions
```

I expected `//:kind.bzl%KindInfo` to also be in the cquery result, but it's not there. The [documentation](https://docs.bazel.build/versions/main/cquery.html#include_aspects-boolean-default-true) suggests that `--include_aspects` will make cquery follow aspects and therefore create the new `KindInfo` provider as well.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the cquery command from the issue with WORKSPACE, BUILD, myrule.bzl, and kind.bzl. Trace the --include_aspects handling and provider reporting, then add or update coverage so the result includes //:kind.bzl%KindInfo when the aspect is applied.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.