bazelbazel-aspect

How to propagate between aspects


I am applying aspects but somehow seem to do something wrong. Imaging the famous reference picture.

enter image description here

In my case A is:

deps_aspect = aspect(
    implementation = _deps_aspect_impl,
    attr_aspects = ["resource_deps"],
    attrs = {
    },
)

For A(W), _deps_aspect_impl returns:

    return struct(
        dep_files = set(),
    )

Now, if I understood the documentation correctly, I should be able to access A(W) dep_files via resource_deps in A(Y).

If for A(Y), _deps_aspect_impl I do:

print("DIR: %s" % dir(ctx.rule.attr))

There is no resource_deps printed (and I cannot access it).

Am I understanding something wrong or how is this supposed to work?


Solution

  • So the problem was that I did not catch various nuances right.

    1. attr_aspects are recursive. Which means once you apply, they propagate downwards the graph. So the attributes are global for that one apply. Perhaps it would be better to be able to specify a dict with kind -> attr mapping.

    2. Due to 1. you really need to have a look at kind, so you have different code paths (the one thing I did right).

    3. Data can NOT be propagated via the shadow graph. I imagined that before. You can only propagate on "solid" rule attrs.