Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: cmd/go: add a -watch option to go generate #36414

Closed
azr opened this issue Jan 6, 2020 · 4 comments
Closed

proposal: cmd/go: add a -watch option to go generate #36414

azr opened this issue Jan 6, 2020 · 4 comments
Labels
Milestone

Comments

@azr
Copy link

@azr azr commented Jan 6, 2020

TLDR: add go generate -watch to watch for changes in a folder to run go generate when a file is changed.

I think go generate is really awesome. In the packer repo that I help maintain, a lot of code and docs are "go generated" and I think it would be nice to not have to think about running go generate every-time I change a file: making my programming a bit less disrupted; moreover this would make performances of go generate less of a problem. Right now a go generate is taking 8 minutes for us.

My gut feeling tells me that making/maintaining this would be way too complicated for the gain but may be I'm wrong !

In the meantime I'll be using https://github.com/fsnotify/fsnotify

@gopherbot gopherbot added this to the Proposal milestone Jan 6, 2020
@gopherbot gopherbot added the Proposal label Jan 6, 2020
@ianlancetaylor ianlancetaylor changed the title proposal: go generate: add a `-watch` option proposal: cmd/go: add a -watch option to go generate Jan 6, 2020
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jan 6, 2020

Thanks for the suggestion. However, the go generate command doesn't have any way to notice which inputs files matter to go generate, so it would have to watch for all changes. I think most people would rather watch just for changes to the file to matter, which would require a custom solution. And for that matter it would be a fairly simple custom solution to wait for any change in a directory and invoke go generate, which is what go generate -watch would do. So I tend to think 1) this would not do what most people want; 2) for the people who do want this, it can be done fairly easily. So to me this doesn't seem worth doing in the go tool.

@mvdan

This comment has been minimized.

Copy link
Member

@mvdan mvdan commented Jan 7, 2020

I think another reason not to do this is that we'd probably have to do it consistently for go build, go test, and so on. The complexity grows rapidly, in my mind. For example, besides watching for changes in all Go source including dependencies, go test -watch would need to somehow watch all testdata files and directories too.

@myitcv

This comment has been minimized.

Copy link
Member

@myitcv myitcv commented Jan 7, 2020

Just to add one final comment that it's already possible to use a file watcher (e.g. inotifywait, fswatch etc) to run commands (e.g. go generate) when files change.

Building on @ianlancetaylor's point:

However, the go generate command doesn't have any way to notice which inputs files matter to go generate, so it would have to watch for all changes

This was part of the motivation behind my work on the experimental gogenerate. That way you amortise the cost of repeatedly running gogenerate, because if you have a cache hit no work will be done.

I'd be happy to continue discussion/questions in that repo

@azr

This comment has been minimized.

Copy link
Author

@azr azr commented Jan 7, 2020

I understand and agree; closing this one for ya ! Thanks for taking the time to answer ! 🙂

@azr azr closed this Jan 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.