I would like to build test binary whenever it is need (only if the package or it's dependencies changed) - something like go install
vs go build
.
The only option option to speed up building test binaries is -i
(go test -c -i
).
Any idea if this is supported by the go
tool? Is there any other go
like tool to do it (I would like to use a tool with native support on go packages instead of a file based system like make
).
For go < 1.10, the go build
doesn't store the package compiled object files. The go install
does. One solution is to call go install
in the right package. It will go through all package dependencies, compile them if the timestamp of the file in the dependency package changed, store the object file and then link them all. Example:
GOBIN="my project build directory" go install ./cmd/mycmd
Another solution is to use -i
flag, which is supported by build
and test
commands.
go 1.10 adds new flag to go build
which does the "smart" caching.
The go build command now detects out-of-date packages purely based on the content of source files, specified build flags, and metadata stored in the compiled packages. Modification times are no longer consulted or relevant. The old advice to add -a to force a rebuild in cases where the modification times were misleading for one reason or another (for example, changes in build flags) is no longer necessary: builds now always detect when packages must be rebuilt. (If you observe otherwise, please file a bug.)
Read release notes for more information.