-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
[rule] Allow deleting attributes from Starlark rule()
function
#24151
base: master
Are you sure you want to change the base?
[rule] Allow deleting attributes from Starlark rule()
function
#24151
Conversation
This is useful for rules like `rules_license`'s `license()` rule that are typically used via `package(default_package_metadata = [":license"]). Since there's an implicit dependency from every target in the package to what's declared in `default_package_metadata`, rules intended for this purpose need to be wrapped in a macro today. ```starlark _license = rule( # ... ) def license(**kwargs): _license(package_metadata = [], **kwargs) ``` With this change, wrapping the rule is no longer necessary. ```starlark license = rule( # ... deleted_attrs = ["package_metadata"], ) ```
Converting to draft for now since this is purely a POC whether something like this would work at all. @lberki do you see any obvious issues with exposing something like this to Starlark before I send time creating a design doc? |
The macro approach could be "inlined" via the new |
Not on the implementation side. In fact, I do understand what you want to use this for in |
Mhm I tried that yesterday, but my naive approach of filtering out Do I understand correctly that |
Nope def _set_package_metadata(**kwargs):
args = {k: v for k, v in kwargs.items()}
args["package_metadata"] = []
return args |
I can see that this feature becomes a foot-gun when extending an existing rule via subrules. Maybe we should only allow it only when there's no I don't have a usecase outside on |
This is useful for rules like
rules_license
'slicense()
rule that are typically used via `package(default_package_metadata = [":license"]).Since there's an implicit dependency from every target in the package to what's declared in
default_package_metadata
, rules intended for this purpose need to be wrapped in a macro today.With this change, wrapping the rule is no longer necessary.