go-clone --build
This commit is contained in:
parent
7a1c1e3180
commit
f888dab0f2
4
Makefile
4
Makefile
|
@ -1,11 +1,11 @@
|
||||||
VERSION = $(shell git describe --tags)
|
VERSION = $(shell git describe --tags)
|
||||||
BUILDTIME = $(shell date +%Y.%m.%d)
|
BUILDTIME = $(shell date +%Y.%m.%d)
|
||||||
|
|
||||||
run: build vet
|
run: vet build
|
||||||
|
|
||||||
vet:
|
vet:
|
||||||
@GO111MODULE=off go vet
|
@GO111MODULE=off go vet
|
||||||
@echo this go library package builds okay
|
@echo this go binary package should build okay
|
||||||
|
|
||||||
build:
|
build:
|
||||||
GO111MODULE=off go build \
|
GO111MODULE=off go build \
|
||||||
|
|
29
main.go
29
main.go
|
@ -31,6 +31,7 @@ func main() {
|
||||||
// you need a proto file
|
// you need a proto file
|
||||||
if argv.Proto == "" {
|
if argv.Proto == "" {
|
||||||
log.Info("you must provide --proto <filename>")
|
log.Info("you must provide --proto <filename>")
|
||||||
|
pp.WriteHelp(os.Stdout)
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,24 +47,28 @@ func main() {
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// you need --upbase and --lobase
|
if err := findGlobalAutogenpb(argv.Proto); err != nil {
|
||||||
if argv.Proto == "" {
|
log.Info("autogenpb parse error:", err)
|
||||||
pp.WriteHelp(os.Stdout)
|
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !shell.Exists("go.sum") {
|
if !shell.Exists("go.sum") {
|
||||||
shell.Run([]string{"go", "mod", "init"})
|
shell.RunQuiet([]string{"go", "mod", "init"})
|
||||||
shell.Run([]string{"go", "mod", "tidy"})
|
shell.RunQuiet([]string{"go", "mod", "tidy"})
|
||||||
|
shell.RunQuiet([]string{"go", "mod", "edit", "-go=1.18"}) // TODO: make this a global
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: switch to using forgepb
|
||||||
|
// switch to forgepb
|
||||||
|
os.Setenv("GO111MODULE", "off") // keeps go list working if go version is back versioned for compatability
|
||||||
cmd := []string{"go", "list", "-f", "'{{.Name}}'"}
|
cmd := []string{"go", "list", "-f", "'{{.Name}}'"}
|
||||||
result := shell.Run(cmd)
|
result := shell.RunQuiet(cmd)
|
||||||
|
os.Unsetenv("GO111MODULE")
|
||||||
|
|
||||||
packageName := strings.Join(result.Stdout, "\n")
|
packageName := strings.Join(result.Stdout, "\n")
|
||||||
packageName = strings.TrimSpace(packageName)
|
packageName = strings.TrimSpace(packageName)
|
||||||
packageName = strings.Trim(packageName, "'")
|
packageName = strings.Trim(packageName, "'")
|
||||||
log.Info("packageName == ", packageName)
|
// log.Info("packageName == ", packageName)
|
||||||
|
|
||||||
protobase := strings.TrimSuffix(argv.Proto, ".proto")
|
protobase := strings.TrimSuffix(argv.Proto, ".proto")
|
||||||
|
|
||||||
|
@ -112,11 +117,11 @@ func main() {
|
||||||
// seems to work, but proto.Marshal() breaks with nil reference
|
// seems to work, but proto.Marshal() breaks with nil reference
|
||||||
if argv.Mutex {
|
if argv.Mutex {
|
||||||
if err := addMutex(sortmap); err == nil {
|
if err := addMutex(sortmap); err == nil {
|
||||||
log.Info("adding mutex to existing protoc-gen-go file worked")
|
// log.Info("adding mutex to existing protoc-gen-go file worked")
|
||||||
sortmap["mutex"] = "true"
|
sortmap["mutex"] = "true"
|
||||||
sortmap["lock"] = "all"
|
sortmap["lock"] = "all"
|
||||||
} else {
|
} else {
|
||||||
log.Info("adding mutex to existing protoc-gen-go file did not work")
|
log.Info("adding mutex to existing protoc-gen-go file did not work", err)
|
||||||
sortmap["mutex"] = "false"
|
sortmap["mutex"] = "false"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,7 +135,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.NoSort {
|
if argv.NoSort {
|
||||||
log.Info("not making sort.pb.go file (--no-sort == true)")
|
// log.Info("not making sort.pb.go file (--no-sort == true)")
|
||||||
} else {
|
} else {
|
||||||
if len(uniqueKeys) != 0 {
|
if len(uniqueKeys) != 0 {
|
||||||
}
|
}
|
||||||
|
@ -138,10 +143,8 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.NoMarshal {
|
if argv.NoMarshal {
|
||||||
log.Info("not making marshal.pb.go file (--no-marshal == true)")
|
// log.Info("not making marshal.pb.go file (--no-marshal == true)")
|
||||||
} else {
|
} else {
|
||||||
if len(marshalKeys) != 0 {
|
|
||||||
}
|
|
||||||
// make the foo.marshal.pb.go file
|
// make the foo.marshal.pb.go file
|
||||||
marshal(sortmap)
|
marshal(sortmap)
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ func marshal(names map[string]string) {
|
||||||
fmt.Fprintln(w, "")
|
fmt.Fprintln(w, "")
|
||||||
|
|
||||||
for _, v := range marshalKeys {
|
for _, v := range marshalKeys {
|
||||||
log.Info("found marshal key in .proto", v)
|
// log.Info("found marshal key in .proto", v)
|
||||||
marshalThing(w, v)
|
marshalThing(w, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
//
|
//
|
||||||
// adds fields to []marshal and []unique
|
// adds fields to []marshal and []unique
|
||||||
func findAutogenpb(names map[string]string) error {
|
func findAutogenpb(names map[string]string) error {
|
||||||
log.Info("starting findAutogenpb() on", names["protofile"])
|
// log.Info("starting findAutogenpb() on", names["protofile"])
|
||||||
// read in the .proto file
|
// read in the .proto file
|
||||||
data, err := os.ReadFile(names["protofile"])
|
data, err := os.ReadFile(names["protofile"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -30,15 +30,52 @@ func findAutogenpb(names map[string]string) error {
|
||||||
parts := strings.Fields(line)
|
parts := strings.Fields(line)
|
||||||
if strings.Contains(line, "autogenpb:marshal") {
|
if strings.Contains(line, "autogenpb:marshal") {
|
||||||
newm := parts[1]
|
newm := parts[1]
|
||||||
log.Info("found marshal", newm)
|
// log.Info("found marshal", newm)
|
||||||
marshalKeys = append(marshalKeys, newm)
|
marshalKeys = append(marshalKeys, newm)
|
||||||
}
|
}
|
||||||
if strings.Contains(line, "autogenpb:unique") {
|
if strings.Contains(line, "autogenpb:unique") {
|
||||||
newu := parts[1]
|
newu := parts[1]
|
||||||
newu = cases.Title(language.English, cases.NoLower).String(newu)
|
newu = cases.Title(language.English, cases.NoLower).String(newu)
|
||||||
log.Info("found unique field", newu)
|
// log.Info("found unique field", newu)
|
||||||
uniqueKeys = append(uniqueKeys, newu)
|
uniqueKeys = append(uniqueKeys, newu)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findGlobalAutogenpb(filename string) error {
|
||||||
|
// log.Info("starting findAutogenpb() on", filename)
|
||||||
|
// read in the .proto file
|
||||||
|
data, err := os.ReadFile(filename)
|
||||||
|
if err != nil {
|
||||||
|
// log.Info("open config file :", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
lines := strings.Split(string(data), "\n")
|
||||||
|
for _, line := range lines {
|
||||||
|
if strings.Contains(line, "autogenpb:ignoreproto") {
|
||||||
|
// ignore this protofile completely (don't make foo.pb.go)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
if strings.Contains(line, "autogenpb:no-marshal") {
|
||||||
|
// don't marshal anything (don't make foo.marshal.pb.go)
|
||||||
|
argv.NoMarshal = true
|
||||||
|
}
|
||||||
|
if strings.Contains(line, "autogenpb:no-sort") {
|
||||||
|
// don't sort anything (don't make foo.sort.pb.go)
|
||||||
|
argv.NoSort = true
|
||||||
|
}
|
||||||
|
if strings.Contains(line, "autogenpb:mutex") {
|
||||||
|
// try the mutex hack
|
||||||
|
argv.Mutex = true
|
||||||
|
}
|
||||||
|
if strings.Contains(line, "autogenpb:gover:") {
|
||||||
|
// todo: parse the output here
|
||||||
|
parts := strings.Split(line, "autogenpb:gover:")
|
||||||
|
log.Info("found gover:", parts[1])
|
||||||
|
argv.Mutex = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
4
sort.go
4
sort.go
|
@ -5,8 +5,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go.wit.com/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeSortfile() {
|
func makeSortfile() {
|
||||||
|
@ -30,7 +28,7 @@ func makeSortfile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range uniqueKeys {
|
for _, s := range uniqueKeys {
|
||||||
log.Info("found unique key in .proto", s)
|
// log.Info("found unique key in .proto", s)
|
||||||
sortmap["sortBy"] = s
|
sortmap["sortBy"] = s
|
||||||
sortmap["sortKey"] = s
|
sortmap["sortKey"] = s
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue