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

Use CompileDaemon with go generate? #67

Open
jameshochadel opened this issue Sep 17, 2021 · 4 comments
Open

Use CompileDaemon with go generate? #67

jameshochadel opened this issue Sep 17, 2021 · 4 comments

Comments

@jameshochadel
Copy link

I'm trying to use CompileDaemon with go generate, but have not been successful. I am running two instances of CompileDaemon to try accomplishing this. One instances watches the source files, which are .sql, and runs go generate when they change. The other watches all .go source files and runs go build. I believe my flags are set up so that the two are watching mutually exclusive files:

#!/bin/sh

CompileDaemon -build="go generate ./..."
  -exclude="*.go"
  -include="*.sql"
  -pattern=".+\.sql$" &
CompileDaemon -build="go build -o /opt/bin/service"
  -exclude="*.sql"
  -include="*.go"
  -pattern=".+\.go$" &

However, when I run this script, CompileDaemon gets stuck in an infinite loop. Is CompileDaemon incompatible with go generate?

@githubnemo
Copy link
Owner

githubnemo commented Sep 18, 2021

What do you mean with "an infinite loop"? It builds continuously?

I think in general it would be best to have the generate and build step in one pass as a script, no?
Something like this:

#!/bin/sh
go geenrate ./...
go build -o /opt/bin/service

and have CompileDaemon run:

CompileDaemon -build="sh build.sh" \
  -include="*.sql" \
  -include="*.go"

@jameshochadel
Copy link
Author

Hey @githubnemo, thank you for taking the time to respond, and sorry about the ambiguity. I am seeing CompileDaemon start another build as soon as it completes the first, and another after that, and so on. This issue occurs even if I run a single CompileDaemon process that runs a script as you describe.

My hypothesis is that because go generate alters .go files, the file watcher immediately queues another build while the first is running, and this continues forever. I might expect a single additional build to be queued when go generate changes watched files, but I'm not sure why it repeats after that. That said, I'm not familiar with the underlying implementation, so this could be totally off base.

@Tiim
Copy link

Tiim commented Feb 10, 2024

Hi @jameshochadel, have you found a workaround for this in the meantime?

@jameshochadel
Copy link
Author

Hi @Tiim: Not to my knowledge, though it's been a few years. I've been using gow instead recently, although not with go generate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants