Skip to content

protoc-gen-go: add paths=source_relative option #533

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

Closed
wants to merge 12 commits into from

Conversation

neild
Copy link
Contributor

@neild neild commented Feb 26, 2018

When --go_out=paths=source_relative:., output filenames are always
derived from the input filenames. For example, the output file
for a/b/c.proto will always be a/b/c.pb.go, regardless of the
presence or absence of a go_package option in the input file.

Fixes #515.

Change-Id: I7483449e68f65757bc459233b1644636b98885b9

When --go_out=paths=source_relative:., output filenames are always
derived from the input filenames. For example, the output file
for a/b/c.proto will always be a/b/c.pb.go, regardless of the
presence or absence of a go_package option in the input file.

Fixes golang#515.

Change-Id: I7483449e68f65757bc459233b1644636b98885b9
@neild neild requested a review from dsnet February 26, 2018 20:52
neild and others added 4 commits February 26, 2018 14:25
Add a "// import <path>" comment to the package line when the source
file includes a `go_package` option containing an import path.

Change-Id: I84a397c91e84b10339e7131592b75bd1d6ded432
No particular reason for this to be a ./ import, and it confuses vgo.
As part of the recent protobuf optimization work, we started generating
Unmarshal and Marshal methods on generated messages. These were done to
support the table-driven implementation within the proto package.

We are renaming Marshal as XXX_Marshal and Unmarshal as XXX_Unmarshal
to make it clear that users are not supposed to call these directly.
There are several reasons for the rename:
* The Marshal method assumes that deterministic is the only option we
would ever support for protos, and is not very forward compatible.
* The presence of a deterministic boolean is confusing for users,
where many set it without considering whether it is necessary.
* The Unmarshal method has a slightly different semantic than the previously
documented proto.Unmarshaler interface. The documented Unmarshal specifies
that Reset is called, while the new method does no such thing. The semantic
difference warrants a rename of the method.
* Some users in the Go community depend on these methods not being
generated by default.

Fixes golang#530
Test importing in a variety of configurations:
  - Two files in the same Go and proto package.
  - Two files in the same Go package, but different proto packages.
  - Two files in different Go packages, but the same proto package.
  - Public imports.
  - Two files in the same package which each import a different
    Go package with the same name. (i.e., demonstrate whether rewrites
    of package names cross file boundaries.)
  - Imports which conflict with standard imports (e.g., "fmt").
@neild neild changed the title [dev] protoc-gen-go: add paths=source_relative option protoc-gen-go: add paths=source_relative option Mar 1, 2018
neild added 4 commits March 1, 2018 10:42
New tests weren't updated for renamed Marshal/Unmarshal methods.
We're only testing with 1.6+, so claiming support for earlier versions is dubious.
Remove generate code dependencies on the order in which source files were
provided to the compiler. In other words, "protoc a.proto b.proto" produces
the same output as "protoc b.proto a.proto".

- Include the proto package version assertion in all files.

- Use the source file name and contents to generate unique var names for
  file descriptors, rather than the file index. In other words,
  "fileDescriptor_imp_81275c260ac30f8b" rather than "fileDescriptor0".

Makes the generated code more stable in the face of unrelated changes
(i.e., adding a new file to a package won't cause generated code for
other files in irrelevant ways), as well as trivial changes in the
protoc command line.

Removes the requirement that all files in a package be compiled at
the same time. Compiling each file individually will produce the same
results as compiling all at once.
protoc-gen-go: add test for various generation params

Add tests for import_prefix and Ma.proto=package.
@@ -56,7 +56,7 @@ func TestGolden(t *testing.T) {
"protoc",
"--plugin=protoc-gen-go="+os.Args[0],
"-Itestdata",
"--go_out=plugins=grpc:"+workdir,
"--go_out=paths=source_relative,plugins=grpc:"+workdir,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test really exercises the feature you're adding.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a couple test cases to the parameters test.


The protocol buffer language has a concept of "packages" which does not
correspond well to the Go notion of packages. In generated Go code,
each source `.proto` file is associated with a single Go package. The
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"is associated with" => "can only be associated with"

The previous phrase seems to suggest one-to-one relationship.
The later allows for a many-to-one relationship.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think "can only be associated with" is any less 1-1. Reworked this section a bit; PTAL.

README.md Outdated
option go_package = "github.com/golang/protobuf/ptypes/any";

The protocol buffer compiler will attempt to derive a package name and
import path if when a `go_package` option is not present, but it is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"if when" => "only if"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

README.md Outdated
import path if when a `go_package` option is not present, but it is
best to always specify one explicitly.

The filename of generated files may be produced in one of two ways.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps:

The output name of the generated file is always produced the same way where the .proto suffix is replaced with .pb.go (e.g., "foo.proto" is named "foo.pb.go").
However, the output directory is selected in one of two ways.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phrased a bit differently; PTAL.

README.md Outdated
- Relative to the input file:

protoc --go_out=paths=source_relative:. inputs/x.proto
# generate ./inputs/x.proto
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you mean ./inputs/x.pb.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

README.md Outdated
- `import_prefix=xxx` - a prefix that is added onto the beginning of
all imports. Useful for things like generating protos in a
subdirectory, or regenerating vendored protobufs in-place.
all imports. Supported for backwards compatibility, but rarely useful.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps use the word "deprecated" somewhere in here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to a "deprecated" section.

@@ -625,6 +637,15 @@ func (g *Generator) CommandLineParameters(parameter string) {
g.ImportPrefix = v
case "import_path":
g.PackageImportPath = v
case "paths":
switch v {
case "import":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this undocumented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

neild added 3 commits March 2, 2018 15:27
When --go_out=paths=source_relative:., output filenames are always
derived from the input filenames. For example, the output file
for a/b/c.proto will always be a/b/c.pb.go, regardless of the
presence or absence of a go_package option in the input file.

Fixes golang#515.

Change-Id: I7483449e68f65757bc459233b1644636b98885b9
@googlebot
Copy link
Collaborator

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this State. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

1 similar comment
@googlebot
Copy link
Collaborator

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this State. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@dsnet
Copy link
Member

dsnet commented Mar 2, 2018

Yay... git pull does a merge instead of rebase.

@neild
Copy link
Contributor Author

neild commented Mar 2, 2018

I have absolutely no idea what's gone wrong here. Is this fixable, or should I just start a new PR?

@dsnet
Copy link
Member

dsnet commented Mar 3, 2018

You could do some "git rebase" magic and then do a "git push -f"...

I would just create a new PR.

@neild
Copy link
Contributor Author

neild commented Mar 3, 2018

#544

@neild neild closed this Mar 3, 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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants