src-d / proteus

Generate .proto files from Go source code.
https://blog.sourced.tech/post/proteus/
MIT License
735 stars 70 forks source link

generated code uses wrong package #84

Closed smola closed 6 years ago

smola commented 7 years ago
$ go get github.com/bblfsh/sdk
$ cd $GOPATH/src/github.com/bblfsh/sdk
$ proteus  -f $GOPATH/src/github.com/bblfsh/sdk/protos -p github.com/bblfsh/sdk/protocol -p github.com/bblfsh/sdk/uast --verbose
$ go build ./protocol/...
# github.com/bblfsh/sdk/protocol
protocol/generated.pb.go:503: undefined: github_com_bblfsh_sdk_uast in github_com_bblfsh_sdk_uast.Node
protocol/generated.pb.go:723: undefined: github_com_bblfsh_sdk_uast in github_com_bblfsh_sdk_uast.Node

The following patch applied manually to the generated code makes it build again:

diff --git a/protocol/generated.pb.go b/protocol/generated.pb.go
index cb0e03b..6b03fce 100644
--- a/protocol/generated.pb.go
+++ b/protocol/generated.pb.go
@@ -20,7 +20,7 @@ import proto "github.com/golang/protobuf/proto"
 import fmt "fmt"
 import math "math"
 import _ "github.com/gogo/protobuf/gogoproto"
-import _ "github.com/bblfsh/sdk/uast"
+import github_com_bblfsh_sdk_uast "github.com/bblfsh/sdk/uast"

 import (
        context "golang.org/x/net/context"
smola commented 7 years ago

I was not using master. Updating proteus to master and have the following error instead:

➜  sdk git:(a1f8dde) ✗ proteus  -f $GOPATH/src/github.com/bblfsh/sdk/protos -p github.com/bblfsh/sdk/protocol -p github.com/bblfsh/sdk/uast --verbose
WARN: ignoring type interface{Next() /home/smola/dev/go/src/github.com/bblfsh/sdk/uast.Path}
WARN: ignoring type interface{Step(); /home/smola/dev/go/src/github.com/bblfsh/sdk/uast.PathIter}
INFO: Generated proto: /home/smola/dev/go/src/github.com/bblfsh/sdk/protos/github.com/bblfsh/sdk/protocol/generated.proto
INFO: Generated proto: /home/smola/dev/go/src/github.com/bblfsh/sdk/protos/github.com/bblfsh/sdk/uast/generated.proto
github.com/bblfsh/sdk/uast/generated.proto: File not found.
github.com/bblfsh/sdk/protos/github.com/bblfsh/sdk/protocol/generated.proto: Import "github.com/bblfsh/sdk/uast/generated.proto" was not found or had errors.
github.com/bblfsh/sdk/protos/github.com/bblfsh/sdk/protocol/generated.proto:24:9: "github.com.bblfsh.sdk.uast.Node" is not defined.
github.com/bblfsh/sdk/protos/github.com/bblfsh/sdk/protocol/generated.proto:40:9: "github.com.bblfsh.sdk.uast.Node" is not defined.
error generating Go files from "/home/smola/dev/go/src/github.com/bblfsh/sdk/protos/github.com/bblfsh/sdk/protocol/generated.proto": exit status 1
smola commented 7 years ago

When calling protoc for the second package (protocol) it does not find the proto file for the first package (uast). My workaround is calling: proteus -f $GOPATH/src -p github.com/bblfsh/sdk/uast -p github.com/bblfsh/sdk/protocol --verbose so that path for Go code and proto files are the same.

And then I'm back to the original error of this issue, which I'm patching manually.

erizocosmico commented 7 years ago

PR sent to gogo/protobuf with the fix https://github.com/gogo/protobuf/pull/336

abeaumont commented 7 years ago

It's working correctly now, I think it can be closed. Thanks @erizocosmico for the fix!