Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion descriptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ type descriptorSet struct {
seen map[string]struct{}
ignoreFiles map[string]struct{}
descProto string
protoPath string
}

func newDescriptorSet(ignoreFiles []string, d string) *descriptorSet {
func newDescriptorSet(ignoreFiles []string, d, p string) *descriptorSet {
ifm := make(map[string]struct{}, len(ignoreFiles))
for _, ignore := range ignoreFiles {
ifm[ignore] = struct{}{}
Expand All @@ -30,6 +31,7 @@ func newDescriptorSet(ignoreFiles []string, d string) *descriptorSet {
seen: make(map[string]struct{}),
ignoreFiles: ifm,
descProto: d,
protoPath: p,
}
}

Expand Down Expand Up @@ -67,6 +69,8 @@ func (d *descriptorSet) marshalTo(w io.Writer) error {
"protoc",
"--decode",
"google.protobuf.FileDescriptorSet",
"--proto_path",
d.protoPath,
d.descProto,
}

Expand Down
14 changes: 7 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ func main() {
}
}

descProto, err := descriptorProto(c.Includes.After)
descProto, protoPath, err := descriptorProto(c.Includes.After)
if err != nil {
log.Fatalln(err)
}

// Aggregate descriptors for each descriptor prefix.
descriptorSets := map[string]*descriptorSet{}
for _, stable := range c.Descriptors {
descriptorSets[stable.Prefix] = newDescriptorSet(stable.IgnoreFiles, descProto)
descriptorSets[stable.Prefix] = newDescriptorSet(stable.IgnoreFiles, descProto, protoPath)
}

shouldGenerateDescriptors := func(p string) bool {
Expand Down Expand Up @@ -340,19 +340,19 @@ func gopathJoin(gopath, element string) string {
}

// descriptorProto returns the full path to google/protobuf/descriptor.proto
// which might be different depending on whether it was installed. The argument
// is the list of paths to check.
func descriptorProto(paths []string) (string, error) {
// (which might be different depending on whether it was installed), and
// the path where it was found. The argument is the list of paths to check.
func descriptorProto(paths []string) (string, string, error) {
const descProto = "google/protobuf/descriptor.proto"

for _, dir := range paths {
file := path.Join(dir, descProto)
if _, err := os.Stat(file); err == nil {
return file, err
return file, dir, err
}
}

return "", fmt.Errorf("File %q not found (looked in: %v)", descProto, paths)
return "", "", fmt.Errorf("File %q not found (looked in: %v)", descProto, paths)
}

var errVendorNotFound = fmt.Errorf("no vendor dir found")
Expand Down