// Copyright 2017-2025 WIT.COM Inc. All rights reserved. // Use of this source code is governed by the GPL 3.0 // 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 // go:generate autogenpb --proto file.proto package main import ( "errors" "os" "path/filepath" "go.wit.com/lib/ENV" "go.wit.com/log" ) func doClean(filebase string) error { globPattern := filebase + "*.pb.go" files, err := filepath.Glob(globPattern) if err != nil { log.Info("glob error", err, files) } for _, filename := range files { // err += os.Remove(filename) err = errors.Join(err, os.Remove(filename)) } log.Info("Removed:", files) return err } // is true if no errors and nothing is new func doMtime(filebase string) bool { var allerr error statf, err := os.Stat(filebase + ".proto") allerr = errors.Join(allerr, err) basetime := statf.ModTime() globPattern := filebase + "*.pb.go" files, err := filepath.Glob(globPattern) if err != nil { log.Info("glob error", err, files) allerr = errors.Join(allerr, err) } if len(files) == 0 { log.Info("no pb.go files found. need to re-run") return false } for _, filename := range files { fstats, err := os.Stat(filename) allerr = errors.Join(allerr, err) newtime := fstats.ModTime() if basetime.Before(newtime) { // everything is okay // log.Info(filebase+".proto was older than", filename) } else { log.Info(filebase+".proto was newer than", filename) // need to rerun err := doClean(filebase) allerr = errors.Join(allerr, err) if allerr != nil { log.Info("autogenpb doMtime() had errors:", allerr) } return false } } if ENV.Verbose() { log.Info(filebase + ".proto was older than all pb.go files. No need to re-run autogenpb.") } if allerr == nil { return true } log.Info("autogenpb doMtime() had errors:", allerr) return false }