summaryrefslogtreecommitdiff
path: root/repo.protofiles.go
diff options
context:
space:
mode:
Diffstat (limited to 'repo.protofiles.go')
-rw-r--r--repo.protofiles.go74
1 files changed, 74 insertions, 0 deletions
diff --git a/repo.protofiles.go b/repo.protofiles.go
new file mode 100644
index 0000000..81a4b6f
--- /dev/null
+++ b/repo.protofiles.go
@@ -0,0 +1,74 @@
+package gitpb
+
+import (
+ "errors"
+ "os"
+ "path/filepath"
+ "strings"
+
+ "go.wit.com/log"
+)
+
+// This returns the list of autogenerated protobuf files
+// it assumes any file *.pb.go is autogenerated
+//
+// this are made from protoc / proto-gen-go
+// these packages also use go.wit.com/apps/autogenpb
+//
+// errors() if a .proto file does not have an autogenerated .pb.go file
+func (repo *Repo) IsProtobuf() (bool, []string, error) {
+ fullp, fullc, err := scanForProtobuf(repo.FullPath)
+ protos := make(map[string]string)
+ protoc := make(map[string]string)
+ var anyfound bool = false
+ var allc []string
+ for _, s := range fullp {
+ filebase := filepath.Base(s)
+ name := strings.TrimSuffix(filebase, ".proto")
+ anyfound = true
+ protos[name] = s
+ }
+ for pname, _ := range protos {
+ var found bool = false
+ for _, s := range fullc {
+ cfilebase := filepath.Base(s)
+ cname := strings.TrimSuffix(cfilebase, ".pb.go")
+ protoc[cname] = s
+ if cname == pname {
+ found = true
+ allc = append(allc, cfilebase)
+ }
+ }
+ if found {
+ // log.Info("found ok")
+ } else {
+ log.Info("missing compiled proto file:", pname+"pb.go")
+ err = errors.New("compiled file " + pname + ".pb.go missing")
+ }
+ }
+ return anyfound, allc, err
+}
+
+func scanForProtobuf(srcDir string) ([]string, []string, error) {
+ var protofiles []string
+ var compiled []string
+ err := filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
+ if err != nil {
+ log.Log(GITPBWARN, "Error accessing path:", path, err)
+ return err
+ }
+
+ if strings.HasSuffix(path, ".proto") {
+ //
+ protofiles = append(protofiles, path)
+ }
+
+ if strings.HasSuffix(path, ".pb.go") {
+ compiled = append(compiled, path)
+ }
+
+ return nil
+ })
+
+ return protofiles, compiled, err
+}