diff options
| author | Jeff Carr <[email protected]> | 2025-10-15 00:22:37 -0500 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-15 00:29:51 -0500 | 
| commit | 05653e8195865d70f6255ff7aeae6eb276197092 (patch) | |
| tree | 55c22c00339533254f6709eb137c122fa600dc69 | |
| parent | b7c2f78414f1b7113d4f760b81b51d7b6758ea35 (diff) | |
add mtime checks like 'make' for smarter automation
| -rw-r--r-- | argv.go | 4 | ||||
| -rw-r--r-- | doMtime.go (renamed from doClean.go) | 15 | ||||
| -rw-r--r-- | main.go | 9 | 
3 files changed, 15 insertions, 13 deletions
@@ -30,8 +30,8 @@ type args struct {  	Comments  bool   `arg:"--format-comments"          help:"enforce parseable comments in a .proto file"`  	NoFormat  bool   `arg:"--no-format"                help:"do not auto-reformat the .proto file"`  	Renumber  bool   `arg:"--renumber"                 help:"renumber everything. obviously breaks backwards compatiblity"` -	Clean     bool   `arg:"--clean"                    help:"clean out any *pb.go files; bypassing ctime sanity checks"` -	Ctime     bool   `arg:"--ctime"                    help:"do os.Stat() createtime sanity checks"` +	Clean     bool   `arg:"--clean"                    help:"clean out any *pb.go files; bypassing mtime sanity checks"` +	Mtime     bool   `arg:"--mtime"                    help:"do os.Stat() modtime sanity checks"`  	GoSrc     string `arg:"--go-src"                   help:"default is ~/go/src. could be set to your go.work path"`  	GoPath    string `arg:"--gopath"                   help:"the gopath of this repo"`  	Identify  string `arg:"--identify"                 help:"identify file"` @@ -17,11 +17,12 @@ import (  	"os"  	"path/filepath" +	"go.wit.com/lib/config"  	"go.wit.com/log"  )  func doClean(filebase string) error { -	globPattern := filebase + ".*.pb.go" +	globPattern := filebase + "*.pb.go"  	files, err := filepath.Glob(globPattern)  	if err != nil {  		log.Info("glob error", err, files) @@ -35,12 +36,12 @@ func doClean(filebase string) error {  }  // is true if no errors and nothing is new -func doCtime(filebase string) bool { +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" +	globPattern := filebase + "*.pb.go"  	files, err := filepath.Glob(globPattern)  	if err != nil {  		log.Info("glob error", err, files) @@ -63,15 +64,17 @@ func doCtime(filebase string) bool {  			err := doClean(filebase)  			allerr = errors.Join(allerr, err)  			if allerr != nil { -				log.Info("autogenpb doCtime() had errors:", allerr) +				log.Info("autogenpb doMtime() had errors:", allerr)  			}  			return false  		}  	} -	log.Info(filebase + ".proto was older than all pb.go files. No need to re-run autogenpb.") +	if config.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 doCtime() had errors:", allerr) +	log.Info("autogenpb doMtime() had errors:", allerr)  	return false  } @@ -77,8 +77,8 @@ func doProto(argvProto string) error {  		me.sh.GoodExit("doClean() ran")  	} -	if argv.Ctime { -		doCtime(pf.Filebase) +	if argv.Mtime { +		doMtime(pf.Filebase)  		me.sh.GoodExit("doClean() ran")  	} @@ -100,9 +100,8 @@ func doProto(argvProto string) error {  		os.Setenv("PROTOBUF_REGRET", "true")  	} -	if doCtime(pf.Filebase) { -		log.Info("nothing changed. exit here") -		me.sh.GoodExit("doCtime() ran") +	if doMtime(pf.Filebase) { +		me.sh.GoodExit(pf.Filename + " did not change")  	} else {  		log.Info("ctime check: need to re-run autogenpb")  	}  | 
