works with mutex and without again

This commit is contained in:
Jeff Carr 2025-01-11 03:19:34 -06:00
parent 502826cf8c
commit 76968c90e8
3 changed files with 19 additions and 7 deletions

View File

@ -2,8 +2,8 @@ VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d_%H%M) BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
simple: build simple: build
# make -C example clean simpleMutexGlobal goimports vet make -C example clean simpleMutexGlobal goimports vet
make -C example clean simpleMutexProtoc goimports vet # make -C example clean simpleMutexProtoc goimports vet
full: install clean auto goimports vet build test install full: install clean auto goimports vet build test install
@echo everything worked and the example ran @echo everything worked and the example ran

View File

@ -48,7 +48,10 @@ func (pb *Files) addMutex(f *File) error {
w, _ := os.OpenFile(f.Pbfilename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) w, _ := os.OpenFile(f.Pbfilename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
// the default is to insert a mutex directly into the struct
if argv.Mutex {
pbHeaderComment(w) pbHeaderComment(w)
}
lines := strings.Split(string(data), "\n") lines := strings.Split(string(data), "\n")
for _, line := range lines { for _, line := range lines {
@ -59,6 +62,12 @@ func (pb *Files) addMutex(f *File) error {
// fmt.Fprintln(w, "package "+"main") // fmt.Fprintln(w, "package "+"main")
continue continue
} }
// the default is to insert a mutex directly into the struct
if !argv.Mutex {
// mutex is not to be added, only fix the package name
fmt.Fprintln(w, line)
continue
}
if f.structMatch(line) { if f.structMatch(line) {
if argv.Mutex { if argv.Mutex {
@ -78,11 +87,14 @@ func (pb *Files) addMutex(f *File) error {
fmt.Fprintln(w, line) fmt.Fprintln(w, line)
} }
} }
if argv.Mutex {
// verify every structure was found
for _, msg := range f.MsgNames { for _, msg := range f.MsgNames {
if !msg.MutexFound && msg.DoMutex { if !msg.MutexFound && msg.DoMutex {
return fmt.Errorf("addMutex() parse didn't work for %s", msg.Name) return fmt.Errorf("addMutex() parse didn't work for %s", msg.Name)
} }
} }
}
return nil return nil
} }

View File

@ -11,7 +11,7 @@ syntax = "proto3";
// "Fruits" MUST EXIST and start exactly this way // "Fruits" MUST EXIST and start exactly this way
// It must be "Fruit" + 's' and must match the name of this file: "fruit.proto" // It must be "Fruit" + 's' and must match the name of this file: "fruit.proto"
package fruit; package main;
import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp