Convertion from Label to Target within transition

17 views
Skip to first unread message

Kirill Zabelin

unread,
Jun 23, 2022, 8:47:49 AMJun 23
to bazel-...@googlegroups.com
Hi everyone!

Documentation about attr.label has the following line about 'label' field - https://bazel.build/rules/lib/attr#label

```
At analysis time (within the rule's implementation function), when retrieving the attribute value from ctx.attr, labels are replaced by the corresponding Targets. This allows you to access the providers of the currrent target's dependencies.
```

Is it possible to somehow achieve the same effect within transition or repository_rule? Somehow convert Lable to Target?

Thanks,
Kirill

Xudong Yang

unread,
Jun 23, 2022, 8:55:16 AMJun 23
to Kirill Zabelin, bazel-discuss
This is not possible in repository rules, because at the time repository rules are evaluated, analysis hasn't started yet. (Caveat: repo rule evaluation and analysis are technically interleaved but we don't allow you to "analyze" an arbitrary label in repo rules anyway, since that could result in cyclic dependencies.)

What are you trying to do?

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CALFCR5M82pHqs1GEROa9FpRh7rkuxusz%3D4dYZXf70rhjDreAaA%40mail.gmail.com.

Kirill Zabelin

unread,
Jun 24, 2022, 5:40:08 AMJun 24
to Xudong Yang, bazel-discuss
Ok, got it about the repository rule, thanks!

What about transition? As far as I know both transitions and rules are evaluated during the analysis stage.

Currently I am trying integrate kconfig with bazel. For this I want to make a transition take a look at output files of specific targets and based on output change configuration.

It seems that there is a TODO for something like this. I found this comment in ./src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkAttributeTransitionProvider.java

```
 *
 * <p>TODO(bazel-team): Consider allowing dependency-typed attributes to actually return providers
 * instead of just labels (see {@link StarlarkAttributesCollection#addAttribute}).
 */
```

--
Kirill

чт, 23 июн. 2022 г. в 15:55, Xudong Yang <w...@bazel.build>:
Reply all
Reply to author
Forward
0 new messages