summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.go31
-rw-r--r--protoc.go28
2 files changed, 27 insertions, 32 deletions
diff --git a/main.go b/main.go
index 4438297..7903111 100644
--- a/main.go
+++ b/main.go
@@ -138,41 +138,26 @@ func main() {
}
if argv.DryRun {
- for k, v := range sortmap {
- log.Info(k, "=", v)
- }
os.Exit(0)
}
// try to make foo.pb.go with protoc if it's not here
// this is helpful because the protoc-gen-go lines
// are also annoying to code by hand
- sortmap["protoc"] = protobase + ".pb.go"
- if !shell.Exists(sortmap["protoc"]) {
- if err := protocBuild(sortmap); err != nil {
+
+ pbfile := f.Filebase + ".pb.go"
+ // try to create the foo.pb.go file using protoc if it is not there
+ if !shell.Exists(pbfile) {
+ if err := pb.protocBuild(f, pbfile); err != nil {
log.Info("protoc build error:", err)
os.Exit(-1)
}
- pb.addMutex(f)
- // os.Exit(0)
- /*
- // experiment to add a mutex to the structs.
- // this might fix my other not so great lock implementation on sort (?)
- // seems to work, but proto.Marshal() breaks with nil reference
- if argv.Mutex {
- if err := addMutex(sortmap); err == nil {
- // log.Info("adding mutex to existing protoc-gen-go file worked")
- sortmap["mutex"] = "true"
- sortmap["lock"] = "all"
- } else {
- log.Info("adding mutex to existing protoc-gen-go file did not work", err)
- sortmap["mutex"] = "false"
- }
- }
- */
}
+ // try to add the Mutex to the pb.go file
+ pb.addMutex(f)
+
// if foo.pb.go still doesn't exist, protoc failed
// exit here
if !shell.Exists(sortmap["protoc"]) {
diff --git a/protoc.go b/protoc.go
index cc9246f..bab8c80 100644
--- a/protoc.go
+++ b/protoc.go
@@ -14,6 +14,17 @@ import (
"go.wit.com/log"
)
+// THIS GENERATES THIS cmd and then runs it:
+
+// autogenpb needs the commands:
+
+// protoc
+// gen-proto-go
+
+// these are in the GO tools
+
+// Thsese lines were taken from a working Makefile:
+
// test.pb.go: test.proto
// cd ~/go/src && protoc --go_out=. --proto_path=go.wit.com/apps/autogenpb/testautogen \
// --go_opt=Mtest.proto=go.wit.com/apps/autogenpb/testautogen \
@@ -24,20 +35,19 @@ import (
// --go_opt=MforgeConfig.proto=go.wit.com/apps/autogenpb/testautogen \
// forgeConfig.proto
-func protocBuild(names map[string]string) error {
+func (pb *Files) protocBuild(f *File, pbfile string) error {
// read in the .proto file
- data, err := os.ReadFile(names["protofile"])
+ data, err := os.ReadFile(f.Filename)
if err != nil {
// log.Info("open config file :", err)
return err
}
- log.Info("")
- if shell.Exists(names["protoc"]) {
- log.Info("protoc file already created", names["protoc"])
- // return nil
+ if shell.Exists(pbfile) {
+ log.Info("protoc file already created", pbfile)
+ return nil
}
- log.Info("make protoc file:", names["protoc"])
+ log.Info("Attempt to generate the protoc file:", pbfile)
// log.Info("go src", forge.GetGoSrc())
pwd, _ := os.Getwd()
log.Info("go.Getwd()", pwd)
@@ -54,7 +64,7 @@ func protocBuild(names map[string]string) error {
log.Info("gopath", gopath)
cmd := []string{"protoc", "--go_out=."}
cmd = append(cmd, "--proto_path="+gopath)
- cmd = append(cmd, "--go_opt=M"+names["protofile"]+"="+gopath)
+ cmd = append(cmd, "--go_opt=M"+f.Filename+"="+gopath)
// look for included proto files
lines := strings.Split(string(data), "\n")
@@ -90,7 +100,7 @@ func protocBuild(names map[string]string) error {
*/
}
- cmd = append(cmd, names["protofile"])
+ cmd = append(cmd, f.Filename)
log.Info("\tpwd", argv.GoSrc)
for i, s := range cmd {
log.Info("\t", i, s)