Use CompileDaemon with go generate?
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?
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"
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.