summaryrefslogtreecommitdiff
path: root/repo.protofiles.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-05 22:06:44 -0600
committerJeff Carr <[email protected]>2025-03-05 22:06:44 -0600
commit9ad119374690fef75e32464d926a4673a79824db (patch)
treed0cbb8a8e6422b6487ab617a804d735e46d0c272 /repo.protofiles.go
parentf58f7df9ac1e2d1d8af5e866c74917b4dffb58f2 (diff)
rearrange codev0.0.93v0.0.92v0.0.91
Diffstat (limited to 'repo.protofiles.go')
-rw-r--r--repo.protofiles.go121
1 files changed, 0 insertions, 121 deletions
diff --git a/repo.protofiles.go b/repo.protofiles.go
deleted file mode 100644
index 146f506..0000000
--- a/repo.protofiles.go
+++ /dev/null
@@ -1,121 +0,0 @@
-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
- for _, s := range fullp {
- filebase := filepath.Base(s)
- name := strings.TrimSuffix(filebase, ".proto")
- anyfound = true
- protos[name] = s
- }
- // make sure every .proto file has a .pb.go file
- 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
- }
- }
- if found {
- // log.Info("found ok")
- } else {
- // log.Info("gitpb: IsProtobuf() missing compiled proto file:", pname+".pb.go")
- err = errors.New("compiled file " + pname + ".pb.go missing")
- }
- }
-
- // assume every .pb.go file is autogenerated
- var allc []string
- for _, testf := range fullc {
- if strings.HasSuffix(testf, ".pb.go") {
- basef := filepath.Base(testf)
- allc = append(allc, basef) // no, not the 3.5" floppy disks
- }
- }
- return anyfound, allc, err
-}
-
-// look for any proto files. do not enter directories
-// note: good golang libraries are best done in a single directory
-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(WARN, "Error accessing path:", path, err)
- return err
- }
-
- // ignore the start dir
- if srcDir == path {
- return nil
- }
-
- if strings.HasSuffix(path, ".proto") {
- //
- protofiles = append(protofiles, path)
- }
-
- if strings.HasSuffix(path, ".pb.go") {
- compiled = append(compiled, path)
- }
-
- // don't go into any directories
- if info.IsDir() {
- return filepath.SkipDir
- }
- return nil
- })
-
- return protofiles, compiled, err
-}
-
-func (repo *Repo) GetProtoFiles() ([]string, error) {
- var protofiles []string
- srcDir := repo.GetFullPath()
- err := filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
- if err != nil {
- log.Log(WARN, "Error accessing path:", path, err)
- return err
- }
-
- // ignore the start dir
- if srcDir == path {
- return nil
- }
-
- if strings.HasSuffix(path, ".proto") {
- //
- protofiles = append(protofiles, path)
- }
-
- if info.IsDir() {
- return filepath.SkipDir
- }
- return nil
- })
-
- return protofiles, err
-}