-
-
Notifications
You must be signed in to change notification settings - Fork 662
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
Gazelle should resolve labels using declared import paths #859
Comments
"If there are multiple valid labels, Gazelle will emit an error" |
Yes. Gazelle errors are almost never fatal. When it fails to find a label for an import path, it won't emit a label for that import. So you'll need to manually add one with a |
Has this proposal been accepted? Has work started? If not, what's it blocked on? |
I'm actively working on this on a dev branch. I'm hoping to cut the first changes this week. |
Walk now calls its callback in all directories it traverses, whether or not they have buildable code or are outside of the subtrees Gazelle was asked to update. This is needed for import path indexing, since we'll need to scan rules in all directories. Related bazel-contrib#859
Walk now calls its callback in all directories it traverses, whether or not they have buildable code or are outside of the subtrees Gazelle was asked to update. This is needed for import path indexing, since we'll need to scan rules in all directories. Related #859
This will make it simpler to separate indexing and generating rules and resolving dependencies into separate phases. Related bazel-contrib#859
Previously, rules.Generator performed import resolution (using the resolve package) as it generated rules. With this change, Generator now produces a "_gazelle_imports" attribute, which is resolved and replaced with "deps". This is necessary since we must be able to index generated rules. We need to generate and index all rules, then resolve imports to deps in a separate phase. Related bazel-contrib#859
Previously, rules.Generator performed import resolution (using the resolve package) as it generated rules. With this change, Generator now produces a "_gazelle_imports" attribute, which is resolved and replaced with "deps". This is necessary since we must be able to index generated rules. We need to generate and index all rules, then resolve imports to deps in a separate phase. Related #859
(Unit tests will be in the PR to wire this into Resolver). Related bazel-contrib#859
(Unit tests will be in the PR to wire this into Resolver). Related #859
We need to merge some attributes on rules before indexing them. In particular, we need to merge "importpath" and "srcs", since these become keys in the index. It's important to account for '# keep' comments and '# gazelle:ignore' directives so we need to use the regular merging algorithm instead of something ad hoc in the indexer. However, we also need to merge deps after they're resolved. This means that we need to merge rules in two separate phases. Right after rules are generated, we merge everything except "deps". Then we resolve dependencies. Then we merge "deps" only. This should also prevent us from indexing rules that are deleted. Related bazel-contrib#859
We need to merge some attributes on rules before indexing them. In particular, we need to merge "importpath" and "srcs", since these become keys in the index. It's important to account for '# keep' comments and '# gazelle:ignore' directives so we need to use the regular merging algorithm instead of something ad hoc in the indexer. However, we also need to merge deps after they're resolved. This means that we need to merge rules in two separate phases. Right after rules are generated, we merge everything except "deps". Then we resolve dependencies. Then we merge "deps" only. This should also prevent us from indexing rules that are deleted. Related #859
Closing old Gazelle issues. This is mostly done. A few remaining open issues have been migrated to bazelbuild/bazel-gazelle. |
Currently, Gazelle converts import paths into Bazel labels by following a few simple conventions. This requires
go_library
to be in specific packages with specific names (go_default_library
) in order to work. This is causing an increasing amount of difficulty for several reasons.importpath
attributes in rules.go_proto_library
, there are multiple kinds of libraries with different naming conventions. (Generate new proto rules with gazelle #808)go_default_library
name at some point. (Use package name instead of go_default_library to define a default library #265)Smarter label resolution is a prerequisite for all of this.
Proposal
When Gazelle starts, it will build a table that maps import paths to labels and directories. This table will be populated by several mechanisms:
After build files and directories are scanned, Gazelle will generate rules for the packages it needs to update. Dependencies will be resolved using the table described above.
The text was updated successfully, but these errors were encountered: