summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile14
-rw-r--r--addMutex.go4
-rw-r--r--main.go15
-rw-r--r--protoc.go68
-rw-r--r--sort.go6
-rw-r--r--testSort/Makefile34
-rw-r--r--testSort/main.go37
7 files changed, 94 insertions, 84 deletions
diff --git a/Makefile b/Makefile
index 146b125..e302457 100644
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,11 @@
VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d)
-run: clean build
- make -C testautogen/ all
- make -C testSort/
+run: build
-test:
- ./autogenpb --dry-run --proto test.proto --lobase gitTag --upbase GitTag --sort "ByPath,Refname"
+test: build
+ @# make -C testautogen/ all
+ cd testautogen; pwd; ../autogenpb --proto test.proto
vet:
@GO111MODULE=off go vet
@@ -22,7 +21,6 @@ install:
goimports:
goimports -w *.go
- make -C testSort/ goimports
redomod:
rm -f go.*
@@ -35,6 +33,6 @@ reset:
reset
clean:
+ -rm -f go.*
-rm -f autogenpb
- make -C testautogen/ clean
- make -C testSort/ clean
+ @#make -C testautogen/ clean
diff --git a/addMutex.go b/addMutex.go
index fa56a82..efa8501 100644
--- a/addMutex.go
+++ b/addMutex.go
@@ -1,6 +1,8 @@
package main
-// eh, screw it, just add the damned mutex to the pb.go file
+// will this help things?
+// this is a hack for testing for now
+// cram a mutex in the pb.go file
import (
"errors"
diff --git a/main.go b/main.go
index a0575eb..cbff6a6 100644
--- a/main.go
+++ b/main.go
@@ -1,4 +1,6 @@
+//go:build go1.20
// +build go1.20
+
package main
import (
@@ -7,6 +9,7 @@ import (
"github.com/alexflint/go-arg"
"go.wit.com/lib/gui/shell"
+ "go.wit.com/lib/protobuf/forgepb"
"go.wit.com/log"
"golang.org/x/text/cases"
"golang.org/x/text/language"
@@ -17,6 +20,7 @@ var VERSION string
var BUILDTIME string
var sortmap map[string]string
+var forge *forgepb.Forge // forgepb figures out how to run protoc correctly if it's needed
func main() {
pp := arg.MustParse(&argv)
@@ -48,7 +52,6 @@ func main() {
if !shell.Exists("go.sum") {
shell.Run([]string{"go", "mod", "init"})
shell.Run([]string{"go", "mod", "tidy"})
- shell.Run([]string{"go", "mod", "edit", "-go=1.20"})
}
cmd := []string{"go", "list", "-f", "'{{.Name}}'"}
@@ -86,6 +89,16 @@ func main() {
os.Exit(0)
}
+ 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)
+
// add mutex
if err := addMutex(sortmap); err == nil {
log.Info("adding mutex to existing protoc-gen-go file worked")
diff --git a/protoc.go b/protoc.go
new file mode 100644
index 0000000..f3b545d
--- /dev/null
+++ b/protoc.go
@@ -0,0 +1,68 @@
+package main
+
+// auto run protoc with the correct args
+
+import (
+ "errors"
+ "os"
+
+ "go.wit.com/lib/gui/shell"
+ "go.wit.com/lib/protobuf/forgepb"
+ "go.wit.com/log"
+)
+
+// 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 \
+// test.proto
+
+// forgeConfig.pb.go: forgeConfig.proto
+// cd ~/go/src && protoc --go_out=. --proto_path=go.wit.com/apps/autogenpb/testautogen \
+// --go_opt=MforgeConfig.proto=go.wit.com/apps/autogenpb/testautogen \
+// forgeConfig.proto
+
+func protocBuild(names map[string]string) error {
+ // have to figure out how to run protoc so initialize forge
+ forge = forgepb.Init()
+ // forge.ConfigPrintTable()
+ os.Setenv("REPO_WORK_PATH", forge.GetGoSrc())
+
+ log.Info("")
+ if shell.Exists(names["protoc"]) {
+ log.Info("protoc file already created", names["protoc"])
+ return nil
+ }
+ log.Info("make protoc file:", names["protoc"])
+ log.Info("go src", forge.GetGoSrc())
+ 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
+
+ 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)
+ }
+ }
+ // os.Exit(-1)
+ if found {
+ return nil
+ }
+ */
diff --git a/sort.go b/sort.go
index e6ec300..4409eba 100644
--- a/sort.go
+++ b/sort.go
@@ -8,7 +8,7 @@ import (
)
func makeSortfile() {
- f, _ := os.OpenFile(sortmap["protobase"] + ".sort.pb.go", os.O_WRONLY|os.O_CREATE, 0600)
+ f, _ := os.OpenFile(sortmap["protobase"]+".sort.pb.go", os.O_WRONLY|os.O_CREATE, 0600)
header(f, sortmap)
syncLock(f, sortmap)
@@ -18,8 +18,8 @@ func makeSortfile() {
iterSortAll(f, sortmap)
if argv.Append != "" {
- sortmap["append"] = string(argv.Append)
- iterAppend(f, sortmap) // Append() enforce unique key argv.Append
+ sortmap["append"] = string(argv.Append)
+ iterAppend(f, sortmap) // Append() enforce unique key argv.Append
}
for _, s := range argv.Sort {
diff --git a/testSort/Makefile b/testSort/Makefile
deleted file mode 100644
index 88a8320..0000000
--- a/testSort/Makefile
+++ /dev/null
@@ -1,34 +0,0 @@
-VERSION = $(shell git describe --tags)
-BUILDTIME = $(shell date +%Y.%m.%d)
-
-run: clean build
- ./testSort
-
-vet:
- @GO111MODULE=off go vet
- @echo this go library package builds okay
-
-build:
- GO111MODULE=off go build \
- -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
-
-install:
- GO111MODULE=off go install \
- -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
-
-goimports:
- goimports -w *.go
- # // to globally reset paths:
- # // gofmt -w -r "go.wit.com/gui -> go.wit.com/gui/gui" .
-
-redomod:
- rm -f go.*
- GO111MODULE= go mod init
- GO111MODULE= go mod tidy
-
-reset:
- # clear your terminal
- reset
-
-clean:
- -rm -f *.pb.go testSort
diff --git a/testSort/main.go b/testSort/main.go
deleted file mode 100644
index f20361f..0000000
--- a/testSort/main.go
+++ /dev/null
@@ -1,37 +0,0 @@
-package main
-
-import (
- "log"
-
- // "go.wit.com/apps/autogenpb/testautogen"
-)
-
-func main() {
- log.Println("empty because go mod tidy failed")
- log.Println("why does go mod tidy fail when this is here?")
- // go: go.wit.com/apps/autogenpb/testSort imports
- // go.wit.com/apps/autogenpb/testautogen: cannot find module providing package go.wit.com/apps/autogenpb/testautogen: unrecognized import path "go.wit.com/apps/autogenpb/testautogen": parse https://go.wit.com/apps/autogenpb/testautogen?go-get=1: no go-import meta tags ()
-
- /*
- all := new(testautogen.GitTags)
- // newt := new(testautogen.GitTag)
-
- new1 := testautogen.GitTag{
- Refname: "master",
- Objectname: "blah",
- }
- all.Append(&new1)
-
- new2 := testautogen.GitTag{
- Refname: "devel",
- Objectname: "j23jljalse",
- }
- all.Append(&new2)
-
- loop := all.SortByPath()
- for loop.Scan() {
- t := loop.Next()
- log.Println("hello testSort t.Refname =", t.Refname, t.Objectname)
- }
- */
-}