diff options
| -rw-r--r-- | file.proto | 96 | ||||
| -rw-r--r-- | human.go | 9 | ||||
| -rw-r--r-- | main.go | 31 | ||||
| -rw-r--r-- | protoc.go | 16 |
4 files changed, 81 insertions, 71 deletions
@@ -26,60 +26,60 @@ package main; // protobuf files to write out *.sort.pb.go and *.marshal.pb.go files // message MsgVar { - string varName = 1; // the variable name - string varType = 2; // the variable type - bool isRepeated = 3; // does the variable repeate - bool hasSort = 4; // marked with sort - bool hasUnique = 5; // marked with unique + string varName = 1; // the variable name + string varType = 2; // the variable type + bool isRepeated = 3; // does the variable repeate + bool hasSort = 4; // marked with sort + bool hasUnique = 5; // marked with unique } message MsgName { - string name = 1; // the name of the message aka struct. for this example: "Shelf" - string lockname = 2; // name of the lockfile. ends in Mu - bool doMarshal = 3; // if msg struct should have Marshal & Unmarshal functions - bool doMutex = 4; // true if a mutex is needed for the message struct - bool doProtocMutex = 5; // an experiment to insert a mutex into the protoc generated msg struct (bad idea?) - bool mutexFound = 6; // true if the mutex was added to the protoc pb.go file - repeated string sort = 7; // keys to sort on - repeated string unique = 8; // if the fields should have AppendUnique() functions - repeated MsgVar vars = 9; // store all the vars in the message - bool needIter = 10; // true if the sort iterator has not been generated yet - bool needAll = 11; // true if the sort iterator has not been generated yet - bool noMutex = 12; // only use the global mutex + string name = 1; // the name of the message aka struct. for this example: "Shelf" + string lockname = 2; // name of the lockfile. ends in Mu + bool doMarshal = 3; // if msg struct should have Marshal & Unmarshal functions + bool doMutex = 4; // true if a mutex is needed for the message struct + bool doProtocMutex = 5; // an experiment to insert a mutex into the protoc generated msg struct (bad idea?) + bool mutexFound = 6; // true if the mutex was added to the protoc pb.go file + repeated string sort = 7; // keys to sort on + repeated string unique = 8; // if the fields should have AppendUnique() functions + repeated MsgVar vars = 9; // store all the vars in the message + bool needIter = 10; // true if the sort iterator has not been generated yet + bool needAll = 11; // true if the sort iterator has not been generated yet + bool noMutex = 12; // only use the global mutex } message Sort { - string msgName = 1; // `autogenpb:unique` File - string varType = 2; // `autogenpb:unique` MsgName - string varName = 3; // `autogenpb:unique` msgNames, sortNames - string lockname = 4; // - bool needAll = 5; // + string msgName = 1; // `autogenpb:unique` File + string varType = 2; // `autogenpb:unique` MsgName + string varName = 3; // `autogenpb:unique` msgNames, sortNames + string lockname = 4; // + bool needAll = 5; // } message Find { - string parent = 1; // `autogenpb:unique` File - string varType = 2; // `autogenpb:unique` MsgName - string varName = 3; // `autogenpb:unique` msgNames, sortNames - bool needAll = 4; // + string parent = 1; // `autogenpb:unique` File + string varType = 2; // `autogenpb:unique` MsgName + string varName = 3; // `autogenpb:unique` msgNames, sortNames + bool needAll = 4; // } message File { - // `autogenpb:var:w io.Writer` - string Package = 1; // whatever the package name is at the top of the .go file - string filename = 2; // yellow.proto - string pbfilename = 3; // yellow.pb.go - string filebase = 4; // yellow - string uuid = 5; // the uuid to use in a func NewMsgName() - string version = 6; // the version to use in a func NewMsgName() - MsgName bases = 7; // the message in "plural" form - MsgName base = 8; // the primary repeated message for the master struct + // `autogenpb:var:w io.Writer` + string Package = 1; // whatever the package name is at the top of the .go file + string filename = 2; // yellow.proto + string pbfilename = 3; // yellow.pb.go + string filebase = 4; // yellow + string uuid = 5; // the uuid to use in a func NewMsgName() + string version = 6; // the version to use in a func NewMsgName() + MsgName bases = 7; // the message in "plural" form + MsgName base = 8; // the primary repeated message for the master struct - // every struct in this proto file, this file has: "Apple", "Apples", ... "File", etc... - repeated MsgName msgNames = 9; - repeated MsgName sortNames = 10; // variables that are repeated can have the standard functions generated (Sort(), etc) - map<string, string> iterMap = 11; - repeated Sort toSort = 12; // variables that are repeated can have the standard functions generated (Sort(), etc) - string goPath = 13; // the version to use in a func NewMsgName() + // every struct in this proto file, this file has: "Apple", "Apples", ... "File", etc... + repeated MsgName msgNames = 9; + repeated MsgName sortNames = 10; // variables that are repeated can have the standard functions generated (Sort(), etc) + map<string, string> iterMap = 11; + repeated Sort toSort = 12; // variables that are repeated can have the standard functions generated (Sort(), etc) + string goPath = 13; // the version to use in a func NewMsgName() } // I know, I know, the whole point of using protobuf @@ -88,15 +88,15 @@ message File { // trivial and empty protobuf message can marshal and identify all the files // also, this could be used to modify /usr/bin/file /usr/share/magic to identify the files // maybe this is already been done and is pointless, but it seems like a good idea -message Files { // `autogenpb:marshal` - string uuid = 1; // `autogenpb:uuid:6c9ae4dd-648d-4b51-9738-bd59fb8fafd5` - string version = 2; // `autogenpb:version:v0.0.38` - repeated File Files = 3; // an array of each .proto file in the working directory +message Files { // `autogenpb:marshal` + string uuid = 1; // `autogenpb:uuid:6c9ae4dd-648d-4b51-9738-bd59fb8fafd5` + string version = 2; // `autogenpb:version:v0.0.38` + repeated File Files = 3; // an array of each .proto file in the working directory } // this generic message is used by autogen to identify and // then dump the uuid and version from any arbitrary .pb file -message Identify { // `autogenpb:marshal` - string uuid = 1; // - string version = 2; // +message Identify { // `autogenpb:marshal` + string uuid = 1; // + string version = 2; // } @@ -5,13 +5,8 @@ package main import ( "fmt" - "os/exec" - "github.com/go-cmd/cmd" - "github.com/google/uuid" "go.wit.com/log" - "golang.org/x/text/cases" - "golang.org/x/text/language" ) // This was just going to be a function to print the results to stdout @@ -131,6 +126,7 @@ func (msg *MsgName) printMsg() { } } +/* func checkCmd(cmd string) { // path, err := exec.LookPath(cmd) _, err := exec.LookPath(cmd) @@ -160,6 +156,7 @@ func (pf *File) noPluralMessage() { log.Info("###########################################################################") badExit(fmt.Errorf("proto file error %s", pf.Filename)) } +*/ // message Fruits { // `autogenpb:marshal` `autogenpb:mutex` // string uuid = 1; // `autogenpb:uuid:be926ad9-f07f-484c-adf2-d96eeabf3079` @@ -167,6 +164,7 @@ func (pf *File) noPluralMessage() { // repeated Fruit Fruits = 3; // THIS MUST BE "Fruit" and then "Fruit" + "s" // } +/* func (pf *File) noUuid() { base := cases.Title(language.English, cases.NoLower).String(pf.Filebase) id := uuid.New() @@ -209,3 +207,4 @@ func userInstructions() { log.Info(" apt install protoc-gen-go # for protoc-gen-go") log.Info("") } +*/ @@ -1,9 +1,9 @@ //go:build go1.20 +// +build go1.20 + // Copyright 2017-2025 WIT.COM Inc. All rights reserved. // Use of this source code is governed by the GPL 3.0 -// +build go1.20 - // protobuf the way I am using them, require GO 1.20. I think. I could be wrong. // The Go Protocol Buffers library embeds a sync.Mutex within the MessageState struct to prevent unintended shallow copies of message structs // this optionally (but it is the default) inserts a mutex into the struct generated by protoc @@ -21,6 +21,7 @@ import ( "github.com/alexflint/go-arg" "github.com/go-cmd/cmd" + "go.wit.com/lib/fhelp" "go.wit.com/lib/gui/shell" "go.wit.com/log" ) @@ -102,16 +103,15 @@ func main() { argv.GoSrc = filepath.Join(homeDir, "go/src") } + var startpwd string + startpwd, _ = os.Getwd() + log.Info("start pwd = ", startpwd) if argv.GoPath == "" { - pwd, _ := os.Getwd() - argv.GoPath = strings.TrimPrefix(pwd, argv.GoSrc) + argv.GoPath = strings.TrimPrefix(startpwd, argv.GoSrc) argv.GoPath = strings.Trim(argv.GoPath, "/") } log.Info(argv.GoSrc, argv.GoPath) - pwd, _ := os.Getwd() - log.Info("pwd = ", pwd) - if !shell.Exists("go.sum") { shell.RunQuiet([]string{"go-mod-clean"}) if !shell.Exists("go.sum") { @@ -145,20 +145,29 @@ func main() { // 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 - checkCmd("protoc") - checkCmd("protoc-gen-go") + // checkCmd("protoc") + // checkCmd("protoc-gen-go") + + if !fhelp.CheckProtoc() { + badExit(fmt.Errorf("you do not have 'protoc' installed")) + } pf.Pbfilename = pf.Filebase + ".pb.go" // try to create the foo.pb.go file using protoc if it is not there if !shell.Exists(pf.Pbfilename) { - checkCmd("protoc") - checkCmd("protoc-gen-go") + if !fhelp.CheckProtoc() { + badExit(fmt.Errorf("you do not have 'protoc' installed")) + } + + // checkCmd("protoc") + // checkCmd("protoc-gen-go") if err := pb.protocBuild(pf); err != nil { badExit(err) } } + os.Chdir(startpwd) // try to add the Mutex to the pb.go file if err := pb.addMutex(pf); err != nil { @@ -96,16 +96,18 @@ func (pb *Files) protocBuild(pf *File) error { for i, s := range cmd { log.Info("\t", i, s) } - return runprotoc(argv.GoSrc, cmd) + os.Chdir(argv.GoSrc) + _, err = shell.RunVerbose(cmd) + return err } +/* func runprotoc(pwd string, mycmd []string) error { - result := shell.PathRun(argv.GoSrc, mycmd) - if result.Error != nil { - return userNotes(result) - } - if result.Exit != 0 { - return userNotes(result) + os.Chdir(argv.GoSrc) + err := shell.Exec(mycmd) + if err != nil { + return err } return nil } +*/ |
