Skip to content

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

@mvdan

Description

@mvdan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions