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

protoc-gen-go: remove generation of magic import comment #678

Closed
dsnet opened this issue Aug 13, 2018 · 12 comments · Fixed by #701
Closed

protoc-gen-go: remove generation of magic import comment #678

dsnet opened this issue Aug 13, 2018 · 12 comments · Fixed by #701
Assignees

Comments

@dsnet
Copy link
Member

dsnet commented Aug 13, 2018

This is a reversion of #267.

The Go tooling ecosystem in moving towards modules, where this import comment is being deprecated in favor of a go.mod file. The magic // import "path/to/package" comment may be used to initialize a go.mod file, but the use of go.mod supersedes the magic comment afterwards.

We may remove this now, or wait until module support is even more solidified.

@tandr
Copy link

tandr commented Aug 15, 2018

Or at least make it configurable somehow

neild added a commit that referenced this issue Sep 13, 2018
Usage of the import comment is being deprecated in favor of a go.mod
file as the Go ecosystem moves towards modules.

Fixes #678
neild added a commit that referenced this issue Sep 13, 2018
Usage of the import comment is being deprecated in favor of a go.mod
file as the Go ecosystem moves towards modules.

Fixes #678
neild added a commit that referenced this issue Sep 13, 2018
Usage of the import comment is being deprecated in favor of a go.mod
file as the Go ecosystem moves towards modules.

Fixes #678
neild added a commit that referenced this issue Sep 13, 2018
Usage of the import comment is being deprecated in favor of a go.mod
file as the Go ecosystem moves towards modules.

Fixes #678
@dsymonds
Copy link
Contributor

This move seems premature. While the package import comments might be deprecated, they will still be effective (and not harmful!) for likely quite some time. I'd wait at least a year on this.

@dsymonds dsymonds reopened this Sep 13, 2018
@neild
Copy link
Contributor

neild commented Sep 13, 2018

Are they particularly important to generate? We only started adding them relatively recently, and anyone who does want an import comment can include a handwritten stub .go file with just a package statement and the comment.

@dsymonds
Copy link
Contributor

They're useful in the ways that import comments in non-generated packages are useful: they ensure a package is only imported in a specific way (and this is doubly important for proto packages to avoid duplicate registrations!).

I could write a stub .go file, but I've already written the package name in an option go_package directive in the .proto file.

Note that they existed for a long time internal to Google. I can't remember why it wasn't generated externally for so long. But my point still stands: they're useful (that's why you added them earlier this year!), and will remain useful for quite some time. Modules aren't going to be widely adopted in the short term; it'll take some time.

@neild
Copy link
Contributor

neild commented Sep 13, 2018

I don't think the import comments ever existed internal to Google, did they? We build everything with Blaze, so option go_package never sets the import path--everything is explicitly set on the command-line and there isn't really a concept of importing something with the wrong path.

@dsymonds
Copy link
Contributor

Maybe I'm misremembering, or don't have the old emails any more.

@dsymonds
Copy link
Contributor

Anyway, I don't feel particularly strongly. I think they'd be useful to keep around for the next 6-12mo, and I don't see any harm in them, but it's your call.

@puellanivis
Copy link
Collaborator

As I remember it, internally at Google the option go_package was never a full import statement, and was always just the final name of the package alone, i.e. it went straight into the package statement: package ${GO_PACKAGE} without any munging.

The notion of having it as a full import path just kind of weirds me out, as it locks/locked you into building out of the GOPATH, which I was never a fan of.

@neild
Copy link
Contributor

neild commented Sep 15, 2018

Having the full import path in option go_package is important for generating accurate import statements. That is, a.proto imports b.proto, you need to know what (if any) import statement to put in a.pb.go. The best way to do that is to explicitly put that information in b.proto; the alternative is to specify all the import paths on the command line, which is error-prone and difficult to do by hand.

Internally to Google, we do pass everything on the command-line because the build system (Blaze) knows the import paths and can easily construct complex protoc invocations. Other systems build systems like Bazel presumably do the same thing. So the only thing option go_package gets used for inside Google is to set the package name (and it probably shouldn't do even that, because Blaze knows that too).

But for users who just want to run protoc --go_out=. foo.proto on the command line or from a Makefile, it's important to make things work well without needing complex invocations like protoc --go_out=Ma.proto=import/path/of/a,Mb.proto=import/path/of/b,... foo.proto. Import paths in the go_package option let us do that.

And once we know the import path, it seems reasonable to put it in a // import comment, because why not?

Anyway, I don't feel strongly about this either way. On one hand the import comment seems harmless to me; on the other hand it's trivial to drop in a stub .go file with the desired import comment and it's less simple to remove it from the generated code if you don't want it for some reason. I'll make the next comment a poll on what we should do.

@neild
Copy link
Contributor

neild commented Sep 15, 2018

POLL: Should we keep generating the // import "/path/to/package" comment?

Thumbs up for yes, thumbs down for no, heart for throw it all out and go back to XML. :)

@puellanivis
Copy link
Collaborator

I know the purpose of specifying the full import, but like I said, it locked you into doing everything in the GOPATH. I was also mostly just looking to add more Google input.

Of course also in Google the option go_package was necessary when I was there, because internal Go could handle multiple packages in the same directory. (We all know why that didn’t make it out to the wild though, because importing path/to/your/package_name/package_name was super annoying. ;) )

@dsnet
Copy link
Member Author

dsnet commented Oct 29, 2018

Removal made in #701 from #678 (comment) it seems that the general opinion is to remove them.

@dsnet dsnet closed this as completed Oct 29, 2018
@golang golang locked as resolved 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
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants