start moving common things here
This commit is contained in:
parent
3d260a0219
commit
e88341d808
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue