-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Today, if you're testing a rule that returns platform_common.ToolchainInfo, getting at the value is a bit awkward -- ToolchainInfo is a single provider type, but it carries toolchain-specific attributes.
The regular TargetSubject.provider function can work, but it means you have to manually unwrap the values to continue returning a Subject object. For example, if you have a toolchain rule such as:
def mylang_toolchain(ctx):
return [ToolchainInfo(my_lang_info=MyLangInfo(...))]
A naive rules-testing accessor would look like:
toolchain_info = target.provider(ToolchainInfo, factory=my_lang_toolchain_info_subject_new)
my_lang_info = toolchain_info.my_lang_info()
my_lang_info.whatever().equals(...)
I suppose my_lang_toolchain_info could be a lambda that did the unwrapping directly. In either case, this is kind of annoying.
A few API ideas:
# 1. special accessor on TargetSubject that accepts the attr name
target.toolchain_attr("my_lang_info", factory=my_lang_info_subject_new)
# 2. Generic ToolchainInfoSubject with attr-based accessor
target.provider(ToolchainInfo).attr("my_lang_info", factory=my_lang_info_subject_new)
(1) seems like a convenience API for (2). (2) seems like potential overkill -- ToolchainInfo is basically a plain struct and doesn't have any well known fields. So other than an attr() method, I don't know what else it would have.