-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an
alias_kind
directive to configure wrapper macros (#1986)
**What type of PR is this?** Feature **What package or component does this PR mostly affect?** cmd/gazelle **What does this PR do? Why is it needed?** Introduces an `alias_kind` directive to instruct gazelle for how to handle wrapper macros. Wrapper macros are starlark macros around rules that gazelle knows how to understand. A wrapper macro will have the same attrs that the underlying rule kind has, but likely does additional things like setting up common deps or generating additional targets. A common pattern for creating wrapper macros that gazelle should understand is the custom `rule.verb` usecase described here - https://bazel.build/rules/verbs-tutorial. Gazelle should still be able to understand how to index and update a wrapper macro as long as it is told what underlying rule the wrapper macro should be considered as. `alias_kind` is unique from `map_kind` in that it does not force a rule into the kind that is specified in the `alias_kind` directive. In the above "verbs" example, someone may configure a wrapper macro around a `py_binary` target, while still wanting to keep other py_binary targets around in their BUILD file. `map_kind` would not allow this, as it would force ALL py_binary targets into the mapped kind. **Which issues(s) does this PR fix?** Fixes #18 **Other notes for review** Getting this functionality required a few changes that I'll discuss here since the map_kind and wrapper macro functionality is similar, yet subtly different: 1. We now pass the wrapper macro config into the rule merger so that it can match an existing wrapper macro against the newly generated rule, even though their kinds are not strictly the same. The mapped_kind functionality did not need to do this, as the kind mapping logic in fix-update.go handles updating the generated rule to match the new kind prior to build file merging. We cannot do something similar here, as the wrapper macro pattern should not force all rules to exist in the new type. Instead, it should instruct the merger that the newly generated rule can match the wrapper macro. 2. Update the metaresolver to perform a lookup in the wrapper macro configuration. When we come across a wrapper macro, we need to use the inverseKindMapper so that we correctly update the existing rule's kind prior to sending it off to a language extension to be indexed.
- Loading branch information
1 parent
2898dda
commit 46d1f66
Showing
8 changed files
with
454 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.