run protoc with the right paths
This commit is contained in:
parent
d24d836899
commit
b1172af227
11
main.go
11
main.go
|
@ -66,6 +66,7 @@ func main() {
|
|||
|
||||
sortmap = make(map[string]string)
|
||||
sortmap["package"] = packageName
|
||||
sortmap["protofile"] = argv.Proto
|
||||
sortmap["protobase"] = protobase
|
||||
if argv.LoBase == "" {
|
||||
// if not set, assumed to be protobase
|
||||
|
@ -89,15 +90,21 @@ func main() {
|
|||
os.Exit(0)
|
||||
}
|
||||
|
||||
// try to make foo.pb.go with protoc if it's not here
|
||||
sortmap["protoc"] = protobase + ".pb.go"
|
||||
if !shell.Exists(sortmap["protoc"]) {
|
||||
if err := protocBuild(sortmap); err != nil {
|
||||
log.Info("protoc build error:", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
os.Exit(0)
|
||||
|
||||
// if foo.pb.go still doesn't exist, protoc failed
|
||||
// exit here
|
||||
if !shell.Exists(sortmap["protoc"]) {
|
||||
log.Info("protoc build error.", sortmap["protoc"], "failed to be created with protoc and proto-gen-go")
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
// add mutex
|
||||
if err := addMutex(sortmap); err == nil {
|
||||
|
|
56
protoc.go
56
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,7 +39,7 @@ 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())
|
||||
|
@ -41,24 +49,33 @@ func protocBuild(names map[string]string) error {
|
|||
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)
|
||||
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
|
||||
|
@ -69,9 +86,14 @@ func protocBuild(names map[string]string) error {
|
|||
} else {
|
||||
fmt.Fprintln(w, line)
|
||||
}
|
||||
*/
|
||||
}
|
||||
// os.Exit(-1)
|
||||
if found {
|
||||
|
||||
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
|
||||
}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue