bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
23.2k stars 4.06k forks source link

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

Open jin opened 3 years ago

jin commented 3 years ago

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": <unknown object com.google.devtools.build.lib.analysis.FileProvider>, "FilesToRunProvider": <unknown object com.google.devtools.build.lib.analysis.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 suggests that --include_aspects will make cquery follow aspects and therefore create the new KindInfo provider as well.

kilian-funk commented 1 year ago

@aiuto Any progress on this issue?

Today I spent half a day searching for a bug in my code before I found this issue.

Thanks for an update.

tpasternak commented 9 months ago

Btw folks did you find any workaround for that?