golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.27k stars 17.7k forks source link

cmd/go: add `go generate -exec` flag like `go run -exec` and `go test -exec` #69487

Open mvdan opened 2 months ago

mvdan commented 2 months ago

I sometimes use go run -exec to quickly check how long a program takes to run excluding the build time, for example:

$ /bin/time go run testdata/gen.go 
7.53user 1.17system 0:01.51elapsed 573%CPU (0avgtext+0avgdata 601640maxresident)k
0inputs+384outputs (10major+131651minor)pagefaults 0swaps
$ go run -exec=/bin/time testdata/gen.go 
6.96user 1.08system 0:01.21elapsed 661%CPU (0avgtext+0avgdata 492024maxresident)k
0inputs+224outputs (1major+134476minor)pagefaults 0swaps

Similarly, I have found go test -exec very useful on occasion, for example to test for a different OS like GOOS=windows go test -exec=wine, or to test under a different environment like with https://github.com/mvdan/dockexec.

I wish I could do something similar with go generate. For example, in one of my projects, go generate ./... in CI takes twelve seconds, and I'd like to dig into which of the steps is taking longer than I would expect. For this reason I'd love to be able to do go generate -exec=time ./... or something similar with a short script.

gabyhelp commented 2 months ago

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

matloob commented 2 months ago

I don't see any immediate problems with this idea