-
Notifications
You must be signed in to change notification settings - Fork 18k
x/vgo: non Go source files (eg descriptor.proto) and generated code (eg ) #25957
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
Comments
Perhaps |
I think this issue touches on the discussion over in #14120 (comment). @ianlancetaylor - is /cc @alandonovan |
What does I don't think it is enough, as generate and build steps;
issue 1Currently use gopath to construct paths to protobufs.
This could potentially change to; in shell or
go generate specific solution as an aside, it would be nice to have multi line go generate commands issue 2As part of a build multiple package need to generate code. The package of the generated code is not generally known by the generate step. In the worst case, the directory tree after code gen could look like
Thinking about it, the above isn't the worst case. Worse is if Setting the worster case aside, could above could be solved by
Worked example.We keep our proto files is a separate repo. Including protos that extend Directory structure / env vars // gen.go - in top level dir of package
package example // import "internal.repo/myproject/example"
// 1.
//go:generate mkdir -p vendor
//go:generate protoc -I$PB_PATH/include -I$API_WORKSPACE --go_out=plugins=grpc:vendor options/myannotations.proto
//2.
//go:generate protoc -I$PB_PATH/include -I$API_WORKSPACE -I$API_WORKSPACE/myproject/example -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=plugins=grpc:. example.proto
//3.
//go:generate protoc -I$PB_PATH/include -I$API_WORKSPACE -I$API_WORKSPACE/myproject/example -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-gateway_out=logtostderr=true:. example.proto
//go:generate protoc -I$PB_PATH/include -I$API_WORKSPACE -I$API_WORKSPACE/myproject/example -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --swagger_out=logtostderr=true:. example.proto Then
Hope this help. |
If we implemented |
@millergarym I think the following would solve the worked example you gave:
// gen.go - in top level dir of package
package example // import "internal.repo/myproject/example"
// import internal.repo/api as a side effect, simply
// to ensure we have dependency visible to vgo
import _ "internal.repo/api"
// 1.
//go:generate mkdir -p vendor
//go:generate bash -c "protoc -I$PB_PATH/include -I$$(vgo list -f '{{.Dir}}' internal.repo/api) --go_out=plugins=grpc:vendor options/myannotations.proto"
//2.
//go:generate bash -c "protoc -I$PB_PATH/include -I$$(vgo list -f '{{.Dir}}' internal.repo/api) -I$$(vgo list -f '{{.Dir}}' internal.repo/api)/myproject/example -I$$(vgo list -f '{{.Dir}}' github.com/grpc-ecosystem/grpc-gateway) -I$$(vgo list -f '{{.Dir}}' github.com/grpc-ecosystem/grpc-gateway)/third_party/googleapis --go_out=plugins=grpc:. example.proto"
//3.
//go:generate bash -c "protoc -I$PB_PATH/include -I$$(vgo list -f '{{.Dir}}' internal.repo/api) -I$$(vgo list -f '{{.Dir}}' internal.repo/api)/myproject/example -I$$(vgo list -f '{{.Dir}}' github.com/grpc-ecosystem/grpc-gateway) -I$$(vgo list -f '{{.Dir}}' github.com/grpc-ecosystem/grpc-gateway)/third_party/googleapis --grpc-gateway_out=logtostderr=true:. example.proto"
//go:generate protoc -I$PB_PATH/include -I$$(vgo list -f '{{.Dir}}' internal.repo/api) -I$$(vgo list -f '{{.Dir}}' internal.repo/api)/myproject/example -I$$(vgo list -f '{{.Dir}}' github.com/grpc-ecosystem/grpc-gateway) -I$$(vgo list -f '{{.Dir}}' github.com/grpc-ecosystem/grpc-gateway)/third_party/googleapis --swagger_out=logtostderr=true:. example.proto Essentially:
Therefore I don't think you need the One thing I can see is that use of
This adds complexity to
This adds some complexity to
/cc @alandonovan for any relevant |
There is currently one gotcha, the directory needs to contain at least one Go source file.
works. but
doesn't. I really don't want to be putting dummy go source in the Should we post an issue again vgo list? |
Indeed. So then references to this repo can simply be via an environment variable then, much like |
(@ianlancetaylor, go generate already runs the generator in the source directory, so $SRCDIR wouldn't add anything.) I don't have an answer for the fascinating abuse of vendor to hold generated pb.go files, but that's at least not specific to vgo - as @millergarym pointed out above ("worster"), that wasn't safe already. Now it's just disallowed entirely. I don't quite understand what the solution was for the lack of magic vendor tricks, but @millergarym's last message makes it sound like the only problem left is
(Note that this works will all currently supported versions of Go, not just vgo.) |
@rsc, that doesn't seem to work if the whole repo has no .go files at all
E.g., I need this file https://github.com/googleapis/googleapis/blob/master/google/rpc/status.proto in order to resolve an import from another proto source in my project.
the repos gets downloaded and unpacked, thus I managed to hack it up with:
It has the suboptimal effect of "polluting" go.mod with a non-Go repo, which will get cleaned up at next |
What version of Go are you using (
go version
)?go version go1.10.3 windows/amd64
Does this issue reproduce with the latest release?
yes
What did you do?
Path to non-Go source files
Using
go generate
or other scripts to run protoc the directory containing protobuf is needed (for includes). This is now dynamic, depending on the version ofgb.xjqchip.workers.dev/golang/protobuf
. This issue exists for all non Go code, protobufs are being used as a concrete example.The directory has changed from
$GOPATH/src/github.com/golang/protobuf/protoc-gen-go/
to
$GOPATH/src/mod/github.com/golang/[email protected]/protoc-gen-go/
Generated Go code (not in the top level vendor directory)
As part of a clean build multiple packages may need to generate code. Restricting generated code to all be in the top level vendor directory is constraining. Eg. protobuf extensions.
Discussion
Path to non-Go source files
vgo list
might be enough to construct a path to the thirdparty source.vgo
to get the pathgo generate
Generated Go code (not in the top level vendor directory)
Any suggestions?
The text was updated successfully, but these errors were encountered: