9 ms·
You can figure out what the dependencies of a file using go list, I used something like ${GOCMD} list -f "{{ .ImportPath }} {{join .Deps \" \" }}" ./cmd/$com
by LaGrange 9y ago
You can figure out what the dependencies of a file using go list, I used something like
${GOCMD} list -f "{{ .ImportPath }} {{join .Deps \" \" }}" ./cmd/$command | \
xargs ${GOCMD} list -f "{{ if not .Standard }}build/mac/${command}: {{ range .GoFiles }}{{ \$.Dir }}/{{ . }} {{ end }}{{ end }}" ./cmd/${command} | \
sed "s: /go/src/com.test/your/package/: :g"
...and then including the output of that in the Makefile. There are ways to make sure it gets rebuilt if anything changes, but you'll pay a performance price. It's rather similar to what happens with C, as far as I remember.
It was quite evil, somewhat redundant, and I eventually found make to complicate things for my application more than it was helpful, but sure, you can map modified go files to whatever tasks you might want to do.
EDIT: note that, unlike in C, go (usually) has a single static output file, so without the .o stage, the dependencies are quite dynamic - a change to a go file not included directly might be cause for a recompile. You can build intermediates, (I think either Buck or Bazel do that?) and link by hand, but that's very non-standard.