start moving common things here

This commit is contained in:
Jeff Carr 2024-11-29 23:19:09 -06:00
parent 3d260a0219
commit e88341d808
3 changed files with 76 additions and 2 deletions

View File

@ -89,7 +89,7 @@ func (repo *Repo) gitVersionByName(name string) (string, error) {
}
return strings.TrimSpace(output), nil
}
if ! repo.IsBranch(name) {
if !repo.IsBranch(name) {
// tag does not exist
log.Log(GITPBWARN, "LocalTagExists()", name, "did not exist")
return "", errors.New("gitDescribeByName() git fatal: Not a valid object name: " + name)

74
repo.protofiles.go Normal file
View File

@ -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
}