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

proposal: protoc-gen-go: generator.WriteImport() #141

Closed
zellyn opened this issue Mar 3, 2016 · 1 comment
Closed

proposal: protoc-gen-go: generator.WriteImport() #141

zellyn opened this issue Mar 3, 2016 · 1 comment
Labels

Comments

@zellyn
Copy link
Contributor

zellyn commented Mar 3, 2016

Goal

per-file import uniquification

Why?

  1. It makes output deterministic. Currently, changing the order of input files, or even adding a new import to one file can result in changes to other files.
  2. It's a big step towards being able to generate files one at a time, or multiple packages at a time, as protoc does for other languages. Numerous people have requested this, the ability to generate file-at-a-time was only recently broken, and it's otherwise easy to fix.
  3. It cleans up the generated code when multiple plugin-plugins use the same packages.

I am happy to write this code if there's general support, and I don't believe the changes would be intrusive.

Current operation

Currently, plugins call RegisterUniquePackageName once per imported name. This happens globally (ie. once per run).

Proposed addition

Add a method WriteImport(f *FileDescriptor, desiredName string, importPath string) (prefix string)

This would generate an import statement in the output, as well as returning a prefix string to use when referring to objects from that package.

  • If importPath is the same package as the FileDescriptor, no import is generated, and an empty prefix is returned.
  • If importPath has already been imported in the file, no import is generated, and the previous prefix is returned.
  • If desiredName has already been used by a different import in this file, or reserved by RegisterUniquePackageName, a unique import alias is generated for the import. The prefix returned is the alias followed by . The alias is added to the blacklist used by RegisterUniquePackageName.

This change would allow incremental movement from RegisterUniquePackageName towards WriteImport, and both could coexist.

@dsymonds @jhump @tamird @awalterschulze

@dsnet dsnet changed the title Proposal: generator.WriteImport() proposal: protoc-gen-go: generator.WriteImport() Feb 14, 2018
@dsnet dsnet added the proposal label Feb 14, 2018
@dsnet
Copy link
Member

dsnet commented Mar 8, 2018

Support for plugins in general needs to be discussed. If we decide to provide first-class support for plugins, there will probably be an entire redesign.

Closing this in favor of the umbrella issue #547.

@dsnet dsnet closed this as completed Mar 8, 2018
@golang golang locked and limited conversation to collaborators Jun 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants