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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: go
go:
- 1.7.x
- 1.8.x
- 1.10.x
- 1.11.x
- master
4 changes: 2 additions & 2 deletions Protobuild.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ plugins = ["grpc"]
# packages = ["github.com/gogo/protobuf"]

# Paths that will be added untouched to the end of the includes. We use
# `/usr/local/include` to pickup the common install location of protobuf.
# a few paths to pickup the common install locations for protobuf.
# This is the default.
# after = ["usr/local/include"]
# after = ["usr/local/include", "/usr/include"]

# This section let's us map protobuf imports to Go packages. These will become
# `-M` directives in the call to the go protobuf generator.
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func newDefaultConfig() config {
After []string
}{
Before: []string{"."},
After: []string{"/usr/local/include"},
After: []string{"/usr/local/include", "/usr/include"},
},
}
}
Expand Down
15 changes: 8 additions & 7 deletions descriptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ type descriptorSet struct {
merged descriptor.FileDescriptorSet
seen map[string]struct{}
ignoreFiles map[string]struct{}
descProto string
}

func newDescriptorSet(ignoreFiles ...string) *descriptorSet {
func newDescriptorSet(ignoreFiles []string, d string) *descriptorSet {
ifm := make(map[string]struct{}, len(ignoreFiles))
for _, ignore := range ignoreFiles {
ifm[ignore] = struct{}{}
}
return &descriptorSet{
seen: make(map[string]struct{}),
ignoreFiles: ifm,
descProto: d,
}
}

Expand All @@ -54,7 +56,7 @@ func (d *descriptorSet) add(descs ...*descriptor.FileDescriptorProto) {
//
// This is equivalent to the following command:
//
// cat merged.pb | protoc --decode google.protobuf.FileDescriptorSet /usr/local/include/google/protobuf/descriptor.proto
// cat merged.pb | protoc --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,18 +67,17 @@ func (d *descriptorSet) marshalTo(w io.Writer) error {
"protoc",
"--decode",
"google.protobuf.FileDescriptorSet",

// TODO(stevvooe): Come up with better way to resolve this path.
"-I/usr/local/include",
"/usr/local/include/google/protobuf/descriptor.proto",
d.descProto,
}

cmd := exec.Command(args[0], args[1:]...)
cmd.Stdin = bytes.NewReader(p)
cmd.Stdout = w
cmd.Stderr = os.Stderr

fmt.Println(strings.Join(args, " "))
if !quiet {
fmt.Println(strings.Join(args, " "))
}
return cmd.Run()
}

Expand Down
24 changes: 23 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
"syscall"
Expand Down Expand Up @@ -69,10 +70,15 @@ func main() {
}
}

descProto, 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...)
descriptorSets[stable.Prefix] = newDescriptorSet(stable.IgnoreFiles, descProto)
}

shouldGenerateDescriptors := func(p string) bool {
Expand Down Expand Up @@ -333,6 +339,22 @@ func gopathJoin(gopath, element string) string {
return strings.Join(elements, string(filepath.ListSeparator))
}

// 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) {
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 "", fmt.Errorf("File %q not found (looked in: %v)", descProto, paths)
}

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

// closestVendorDir walks up from dir until it finds the vendor directory.
Expand Down