githubnemo / CompileDaemon

Very simple compile daemon for Go
BSD 2-Clause "Simplified" License
1.61k stars 153 forks source link

Use CompileDaemon with go generate? #67

Open jameshochadel opened 2 years ago

jameshochadel commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 7 months ago

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

jameshochadel commented 7 months ago

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.