Skip to content
Merged
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
8 changes: 6 additions & 2 deletions 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
includeDir string
}

func newDescriptorSet(ignoreFiles []string, d string) *descriptorSet {
func newDescriptorSet(ignoreFiles []string, d string, i 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,
includeDir: i,
}
}

Expand All @@ -56,7 +58,7 @@ func (d *descriptorSet) add(descs ...*descriptor.FileDescriptorProto) {
//
// This is equivalent to the following command:
//
// cat merged.pb | protoc --decode google.protobuf.FileDescriptorSet /path/to/google/protobuf/descriptor.proto
// cat merged.pb | protoc -I /path/to --decode google.protobuf.FileDescriptorSet /path/to/google/protobuf/descriptor.proto
func (d *descriptorSet) marshalTo(w io.Writer) error {
p, err := proto.Marshal(&d.merged)
if err != nil {
Expand All @@ -65,6 +67,8 @@ func (d *descriptorSet) marshalTo(w io.Writer) error {

args := []string{
"protoc",
"-I",
d.includeDir,
"--decode",
"google.protobuf.FileDescriptorSet",
d.descProto,
Expand Down
10 changes: 5 additions & 5 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, includeDir, 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, includeDir)
}

shouldGenerateDescriptors := func(p string) bool {
Expand Down Expand Up @@ -342,17 +342,17 @@ 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) {
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