Skip to content

Commit

Permalink
tmpl: Support vendored instances of protoc-gen-go/descriptor.
Browse files Browse the repository at this point in the history
This is needed when this package is vendored via Go 1.6 /vendor/ support.

The PkgPath returned value does not strip /vendor/ prefix, as documented in golang/go#12739.
  • Loading branch information
dmitshur committed Feb 23, 2016
1 parent 36e54d8 commit 98c62fc
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tmpl/util.go
Expand Up @@ -296,7 +296,9 @@ func (f *tmplFuncs) resolvePkgPath(pkg string) string {
func (f *tmplFuncs) location(x interface{}) *descriptor.SourceCodeInfo_Location {
// Validate that we got a sane type from the template.
pkgPath := reflect.Indirect(reflect.ValueOf(x)).Type().PkgPath()
if pkgPath != "" && pkgPath != "github.com/golang/protobuf/protoc-gen-go/descriptor" {
if pkgPath != "" && pkgPath != "github.com/golang/protobuf/protoc-gen-go/descriptor" &&
!strings.HasSuffix(pkgPath, "/vendor/github.com/golang/protobuf/protoc-gen-go/descriptor") {

panic("expected descriptor type; got " + fmt.Sprintf("%q", pkgPath))
}

Expand Down

0 comments on commit 98c62fc

Please sign in to comment.