Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make accessing ToolchainInfo easier #50

Open
rickeylev opened this issue Jun 27, 2023 · 0 comments
Open

Make accessing ToolchainInfo easier #50

rickeylev opened this issue Jun 27, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@rickeylev
Copy link
Collaborator

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.

@rickeylev rickeylev added the enhancement New feature or request label Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant