summaryrefslogtreecommitdiff
path: root/protoc.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-30 13:48:50 -0600
committerJeff Carr <[email protected]>2024-11-30 13:48:50 -0600
commitb1172af227f7893d29dbad88a47855a95cec8bcc (patch)
treef0f85ad6e77ed86df4058fb7494762ea52ab31c9 /protoc.go
parentd24d8368993da167be40d6276956f378120af18b (diff)
run protoc with the right paths
Diffstat (limited to 'protoc.go')
-rw-r--r--protoc.go78
1 files changed, 50 insertions, 28 deletions
diff --git a/protoc.go b/protoc.go
index b67effa..acd6ad7 100644
--- a/protoc.go
+++ b/protoc.go
@@ -5,6 +5,7 @@ package main
import (
"errors"
"os"
+ "path/filepath"
"strings"
"go.wit.com/lib/gui/shell"
@@ -23,6 +24,13 @@ import (
// forgeConfig.proto
func protocBuild(names map[string]string) error {
+ // read in the .proto file
+ data, err := os.ReadFile(names["protofile"])
+ if err != nil {
+ // log.Info("open config file :", err)
+ return err
+ }
+
// have to figure out how to run protoc so initialize forge
forge = forgepb.Init()
// forge.ConfigPrintTable()
@@ -31,47 +39,61 @@ func protocBuild(names map[string]string) error {
log.Info("")
if shell.Exists(names["protoc"]) {
log.Info("protoc file already created", names["protoc"])
- return nil
+ // return nil
}
log.Info("make protoc file:", names["protoc"])
log.Info("go src", forge.GetGoSrc())
pwd, _ := os.Getwd()
log.Info("go.Getwd()", pwd)
- if ! strings.HasPrefix(pwd, forge.GetGoSrc()) {
+ if !strings.HasPrefix(pwd, forge.GetGoSrc()) {
return errors.New("paths don't match")
}
gopath := strings.TrimPrefix(pwd, forge.GetGoSrc())
+ gopath = strings.Trim(gopath, "/")
log.Info("gopath", gopath)
- return errors.New("make protoc here")
-}
-
-/*
- data, err := os.ReadFile(fullname)
- if err != nil {
- // log.Info("open config file :", err)
- return err
- }
-
- w, _ := os.OpenFile(names["protobase"]+".pb.go", os.O_WRONLY|os.O_CREATE, 0600)
-
- var found bool
+ cmd := []string{"protoc", "--go_out=."}
+ cmd = append(cmd, "--proto_path="+gopath)
+ cmd = append(cmd, "--go_opt=M"+names["protofile"]+"="+gopath)
+ // look for included proto files
lines := strings.Split(string(data), "\n")
for _, line := range lines {
// log.Info("line:", line)
- start := "type " + names["Bases"] + " struct {"
- if strings.HasSuffix(line, start) {
- found = true
- log.Info("FOUND line:", line)
- fmt.Fprintln(w, line)
- fmt.Fprintln(w, "\tsync.RWMutex // auto-added by go.wit.com/apps/autogenpb")
- fmt.Fprintln(w, "")
- } else {
- fmt.Fprintln(w, line)
+ if strings.HasPrefix(line, "import ") {
+ parts := strings.Split(line, "\"")
+ protofile := parts[1]
+ if shell.Exists(protofile) {
+ log.Info("adding import", protofile)
+ cmd = append(cmd, "--go_opt=M"+protofile+"="+gopath)
+ } else {
+ basepath, pname := filepath.Split(protofile)
+ if basepath == "" {
+ log.Warn("import line:", line, "missing proto file:", pname)
+ log.Warn("protoc will probably fail here")
+ } else {
+ log.Warn("need to check basepath here", basepath, pname)
+ }
+ }
}
+ /*
+ start := "type " + names["Bases"] + " struct {"
+ if strings.HasSuffix(line, start) {
+ found = true
+ log.Info("FOUND line:", line)
+ fmt.Fprintln(w, line)
+ fmt.Fprintln(w, "\tsync.RWMutex // auto-added by go.wit.com/apps/autogenpb")
+ fmt.Fprintln(w, "")
+ } else {
+ fmt.Fprintln(w, line)
+ }
+ */
}
- // os.Exit(-1)
- if found {
- return nil
+
+ cmd = append(cmd, names["protofile"])
+ log.Info("\tpwd", forge.GetGoSrc())
+ for i, s := range cmd {
+ log.Info("\t", i, s)
}
-*/
+ shell.PathRun(forge.GetGoSrc(), cmd)
+ return nil
+}